Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2008-04-28 12:45:34 -0400
committerpelder2008-04-28 12:45:34 -0400
commit87bbab292632f29733733c13d9707361e6a1e198 (patch)
tree0de625df367cfe73e22a32a079c9402c2f4cafe1
parentd4601da0702934b347091e82388635ee6e028fc3 (diff)
downloadorg.eclipse.jet-87bbab292632f29733733c13d9707361e6a1e198.tar.gz
org.eclipse.jet-87bbab292632f29733733c13d9707361e6a1e198.tar.xz
org.eclipse.jet-87bbab292632f29733733c13d9707361e6a1e198.zip
[229098] normalize-space function incorrectly leaves non-blank whitespace characters in its result
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/NormalizeSpaceFunction.java43
1 files changed, 17 insertions, 26 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/NormalizeSpaceFunction.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/NormalizeSpaceFunction.java
index 304fccf..926e845 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/NormalizeSpaceFunction.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/NormalizeSpaceFunction.java
@@ -52,43 +52,34 @@ public class NormalizeSpaceFunction implements XPathFunction, XPathFunctionWithC
return normalizeSpace(arg);
}
+
/**
* Normalize a string, accoring to the XPath normalize-space function.
* @param arg the original string.
* @return the normalized string
*/
- public static String normalizeSpace(String arg)
- {
- boolean stripNextSpace = true;
- StringBuffer result = new StringBuffer(arg);
- for(int i = 0; i < result.length(); i++)
- {
- if(Character.isWhitespace(result.charAt(i)))
- {
- if(stripNextSpace)
- {
- result.deleteCharAt(i);
- i--;
+ public static String normalizeSpace(String input) {
+ final int inputLength = input.length();
+ final StringBuffer result = new StringBuffer(inputLength);
+ int wsRunStart = -1; // -1 indicates not run in effect
+ for(int i = 0; i < inputLength; i++) {
+ final char c = input.charAt(i);
+ if(Character.isWhitespace(c)) {
+ if(wsRunStart == -1) {
+ wsRunStart = i;
}
- else
- {
- stripNextSpace = true;
+ } else {
+ if(wsRunStart > 0) { // intentionally misses runs starting at 0
+ result.append(' ');
}
- }
- else
- {
- stripNextSpace = false;
+ wsRunStart = -1;
+ result.append(c);
}
}
-
- final int lastCharIndex = result.length() - 1;
- if(lastCharIndex >= 0 && Character.isWhitespace(result.charAt(lastCharIndex)))
- {
- result.deleteCharAt(lastCharIndex);
- }
+ // loop intentionally suppresses trailing
return result.toString();
}
-
+
public void setContext(Context context)
{
this.context = context;

Back to the top