Author: knoaman
Date: Wed Oct 21 13:56:13 2009
New Revision: 828015

URL: http://svn.apache.org/viewvc?rev=828015&view=rev
Log:
A free spacing mode has no effect inside a character class (i.e. whitespace are 
included)

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/REUtil.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/REUtil.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/REUtil.java?rev=828015&r1=828014&r2=828015&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/REUtil.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/REUtil.java Wed 
Oct 21 13:56:13 2009
@@ -138,11 +138,17 @@
         int len = regex.length();
         StringBuffer buffer = new StringBuffer(len);
         int offset = 0;
+        int charClass = 0;
         while (offset < len) {
             int ch = regex.charAt(offset++);
                                                 // Skips a white space.
-            if (ch == '\t' || ch == '\n' || ch == '\f' || ch == '\r' || ch == 
' ')
+            if (ch == '\t' || ch == '\n' || ch == '\f' || ch == '\r' || ch == 
' ') {
+                // if we are inside a character class, we keep the white space
+                if (charClass > 0) {
+                    buffer.append((char)ch);
+                }
                 continue;
+            }
 
             if (ch == '#') {                    // Skips chracters between '#' 
and a line end.
                 while (offset < len) {
@@ -165,8 +171,32 @@
                     buffer.append((char)next);
                     offset ++;
                 }
-            } else                              // As is.
+            }
+            else if (ch == '[') {
+                charClass++;
+                buffer.append((char)ch);
+                if (offset < len) {
+                    next = regex.charAt(offset);
+                    if (next == '[' || next ==']') {
+                        buffer.append((char)next);
+                        offset ++;
+                    }
+                    else if (next == '^' && offset + 1 < len) {
+                        next = regex.charAt(offset + 1);
+                        if (next == '[' || next ==']') {
+                            buffer.append((char)'^');
+                            buffer.append((char)next);
+                            offset += 2;
+                        }
+                    }
+                }
+            }
+            else {
+                if (charClass > 0 && ch == ']') {
+                    --charClass;
+                }
                 buffer.append((char)ch);
+            }
         }
         return buffer.toString();
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to