diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java
index 506072ec2..2dc8122cb 100644
--- a/src/main/org/apache/tools/ant/ProjectHelper.java
+++ b/src/main/org/apache/tools/ant/ProjectHelper.java
@@ -438,25 +438,36 @@ public class ProjectHelper {
* ${
without a closing
* }
*/
- public static void parsePropertyString(String value, Vector fragments, Vector propertyRefs)
+ public static void parsePropertyString(String value, Vector fragments, Vector propertyRefs)
throws BuildException {
int prev = 0;
int pos;
+ //search for the next instance of $ from the 'prev' position
while ((pos = value.indexOf("$", prev)) >= 0) {
+
+ //if there was any text before this, add it as a fragment
+ //TODO, this check could me modified to go if pos>prev;
+ //seems like this current version could stick empty strings
+ //into the list
if (pos > 0) {
fragments.addElement(value.substring(prev, pos));
}
-
- if (pos == (value.length() - 1)) {
+ //if we are at the end of the string, we tack on a $
+ //then move past it
+ if( pos == (value.length() - 1)) {
fragments.addElement("$");
prev = pos + 1;
- } else if (value.charAt(pos + 1) != '{' ) {
+ }
+ //peek ahead to see if the next char is a property or not
+ else if (value.charAt(pos + 1) != '{' ) {
+ //not a property: insert the char as a literal
fragments.addElement(value.substring(pos + 1, pos + 2));
prev = pos + 2;
} else {
+ //property found, extract its name or bail on a typo
int endName = value.indexOf('}', pos);
if (endName < 0) {
- throw new BuildException("Syntax error in property: "
+ throw new BuildException("Syntax error in property: "
+ value );
}
String propertyName = value.substring(pos + 2, endName);
@@ -465,9 +476,11 @@ public class ProjectHelper {
prev = endName + 1;
}
}
-
+ //no more $ signs found
+ //if there is any tail to the file, append it
if (prev < value.length()) {
fragments.addElement(value.substring(prev));
}
}
+//end class
}