Improved interpolateString.

This commit is contained in:
Anthony Whitford
2015-10-27 23:25:28 -07:00
parent 92e7d9cf80
commit 7f130ff036

View File

@@ -308,10 +308,7 @@ public class Model {
*/ */
public static String interpolateString(String text, Properties properties) { public static String interpolateString(String text, Properties properties) {
final Properties props = properties; final Properties props = properties;
if (text == null) { if (text == null || props == null) {
return text;
}
if (props == null) {
return text; return text;
} }
@@ -319,7 +316,7 @@ public class Model {
if (pos < 0) { if (pos < 0) {
return text; return text;
} }
final int end = text.indexOf("}"); final int end = text.indexOf('}', pos + 2);
if (end < pos) { if (end < pos) {
return text; return text;
} }
@@ -330,10 +327,9 @@ public class Model {
propValue = ""; propValue = "";
} }
final StringBuilder sb = new StringBuilder(propValue.length() + text.length()); final StringBuilder sb = new StringBuilder(propValue.length() + text.length());
sb.append(text.subSequence(0, pos)); sb.append(text.subSequence(0, pos))
sb.append(propValue); .append(propValue)
sb.append(text.substring(end + 1)); .append(text.substring(end + 1));
return interpolateString(sb.toString(), props); //yes yes, this should be a loop... return interpolateString(sb.toString(), props); //yes yes, this should be a loop...
} }
} }