by Asura » Tue Jun 07, 2016 6:59 pm
- Code: Select all
private static StringBuilder replace(String wmlTemplateString, int offset, StringBuilder strB, Map<String, ?> mappings) {
int startKey = wmlTemplateString.indexOf("${", offset);
if(startKey == -1) {
return strB.append(wmlTemplateString.substring(offset));
} else {
strB.append(wmlTemplateString.substring(offset, startKey));
int keyEnd = wmlTemplateString.indexOf(125, startKey);
String key = wmlTemplateString.substring(startKey + 2, keyEnd);
String val = mappings.get(key).toString(); // realy?!
if(val == null) { // =_=
log.warn("Invalid key \'" + key + "\' or key not mapped to a value");
strB.append(key);
} else {
strB.append(val);
}
return replace(wmlTemplateString, keyEnd + 1, strB, mappings);
}
}