diff --git a/li.strolch.utils/src/main/java/li/strolch/utils/helper/StringHelper.java b/li.strolch.utils/src/main/java/li/strolch/utils/helper/StringHelper.java index 1bfc45738..2ffe264dd 100644 --- a/li.strolch.utils/src/main/java/li/strolch/utils/helper/StringHelper.java +++ b/li.strolch.utils/src/main/java/li/strolch/utils/helper/StringHelper.java @@ -415,7 +415,7 @@ public class StringHelper { */ public static String replacePropertiesIn(Properties properties, String value) { - return replacePropertiesIn(properties, '$', value); + return replacePropertiesIn(properties, "$", value); } /** @@ -432,9 +432,9 @@ public class StringHelper { * * @return a new string with all defined properties replaced or if an error occurred the original value is returned */ - public static String replacePropertiesIn(Properties properties, char prefix, String value) { + public static String replacePropertiesIn(Properties properties, String prefix, String value) { - String prefixS = String.valueOf(prefix); + String startTag = prefix + "{"; // get a copy of the value String tmpValue = value; @@ -443,13 +443,8 @@ public class StringHelper { int pos = -1; int stop = 0; - // loop on $ character positions - while ((pos = tmpValue.indexOf(prefix, pos + 1)) != -1) { - - // if pos+1 is not { character then continue - if (tmpValue.charAt(pos + 1) != '{') { - continue; - } + // loop on prefix positions + while ((pos = tmpValue.indexOf(startTag, pos + 1)) != -1) { // find end of sequence with } character stop = tmpValue.indexOf('}', pos + 1); @@ -462,12 +457,12 @@ public class StringHelper { } // get sequence enclosed by pos and stop - String sequence = tmpValue.substring(pos + 2, stop); + String sequence = tmpValue.substring(pos + 1, stop); // make sure sequence doesn't contain $ { } characters - if (sequence.contains(prefixS) || sequence.contains("{") || sequence.contains("}")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (sequence.contains(startTag) || sequence.contains("}")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String msg = "Enclosed sequence in offsets {0} - {1} contains one of the illegal chars: {2} { }: {3}"; - msg = MessageFormat.format(msg, pos, stop, prefixS, sequence); + msg = MessageFormat.format(msg, pos, stop, prefix, sequence); logger.error(msg); tmpValue = value; break; @@ -483,7 +478,7 @@ public class StringHelper { } // property exists, so replace in value - tmpValue = tmpValue.replace(prefixS + "{" + sequence + "}", property); //$NON-NLS-1$ //$NON-NLS-2$ + tmpValue = tmpValue.replace(prefix + "{" + sequence + "}", property); //$NON-NLS-1$ //$NON-NLS-2$ } return tmpValue; diff --git a/li.strolch.utils/src/main/java/li/strolch/utils/helper/TexHelper.java b/li.strolch.utils/src/main/java/li/strolch/utils/helper/TexHelper.java index e1418b002..8a390e9a3 100644 --- a/li.strolch.utils/src/main/java/li/strolch/utils/helper/TexHelper.java +++ b/li.strolch.utils/src/main/java/li/strolch/utils/helper/TexHelper.java @@ -55,7 +55,7 @@ public class TexHelper { } data = StringHelper.replacePropertiesIn(properties, data); - data = StringHelper.replacePropertiesIn(getI18nData(bundle), '%', data); + data = StringHelper.replacePropertiesIn(getI18nData(bundle), "%", data); File renderedPdf = renderPdf(fileName, templatePath, data); diff --git a/li.strolch.utils/src/test/java/li/strolch/utils/helper/ReplacePropertiesInTest.java b/li.strolch.utils/src/test/java/li/strolch/utils/helper/ReplacePropertiesInTest.java index 9d75b685f..d67f609ce 100644 --- a/li.strolch.utils/src/test/java/li/strolch/utils/helper/ReplacePropertiesInTest.java +++ b/li.strolch.utils/src/test/java/li/strolch/utils/helper/ReplacePropertiesInTest.java @@ -133,7 +133,7 @@ public class ReplacePropertiesInTest { properties.setProperty("foo", "bar"); properties.setProperty("food", "foofoo"); - String result = StringHelper.replacePropertiesIn(properties, '%', expr); + String result = StringHelper.replacePropertiesIn(properties, "%", expr); assertEquals(expected, result); }