Author: knoaman
Date: Thu Jul 30 21:35:19 2009
New Revision: 799450

URL: http://svn.apache.org/viewvc?rev=799450&view=rev
Log:
Allow back references with multiple digits

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

Modified: 
xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/RegexParser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/RegexParser.java?rev=799450&r1=799449&r2=799450&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/RegexParser.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xpath/regex/RegexParser.java 
Thu Jul 30 21:35:19 2009
@@ -76,6 +76,7 @@
     static protected final int S_INBRACKETS = 1;
     static protected final int S_INXBRACKETS = 2;
     int context = S_NORMAL;
+    int parenOpened = 1;
     int parennumber = 1;
     boolean hasBackReferences;
     Vector references = null;
@@ -115,6 +116,7 @@
         this.offset = 0;
         this.setContext(S_NORMAL);
         this.parennumber = 1;
+        this.parenOpened = 1;
         this.hasBackReferences = false;
         this.regex = regex;
         if (this.isSet(RegularExpression.EXTENDED_COMMENT))
@@ -438,9 +440,10 @@
     }
     Token processParen() throws ParseException {
         this.next();
-        int p = this.parennumber++;
+        int p = this.parenOpened++;
         Token tok = Token.createParen(this.parseRegex(), p);
         if (this.read() != T_RPAREN)  throw ex("parser.factor.1", 
this.offset-1);
+        this.parennumber++;
         this.next();                            // Skips ')'
         return tok;
     }
@@ -460,9 +463,31 @@
         int ch = this.regex.charAt(this.offset);
         if ('1' <= ch && ch <= '9') {
             refno = ch-'0';
+            int finalRefno = refno;
+            
+            if (this.parennumber <= refno)
+                throw ex("parser.parse.2", this.offset);
+
+            while (this.offset + 1 < this.regexlen) {
+                ch = this.regex.charAt(this.offset + 1);
+                if ('1' <= ch && ch <= '9') {
+                    refno = (refno * 10) + (ch - '0');
+                    if (refno < this.parennumber) {
+                        finalRefno= refno;
+                        ++this.offset;
+                    }
+                    else {
+                        break;
+                    }
+                }
+                else {
+                    break;
+                }
+            }
+
             this.hasBackReferences = true;
             if (this.references == null)  this.references = new Vector();
-            this.references.addElement(new ReferencePosition(refno, 
this.offset));
+            this.references.addElement(new ReferencePosition(finalRefno, 
this.offset));
             this.offset ++;
             if (this.regex.charAt(this.offset) != ')')  throw 
ex("parser.factor.1", this.offset);
             this.offset ++;
@@ -571,10 +596,33 @@
     }
     Token processBackreference() throws ParseException {
         int refnum = this.chardata-'0';
-        Token tok = Token.createBackReference(refnum);
+        int finalRefnum = refnum;
+
+        if (this.parennumber <= refnum)
+            throw ex("parser.parse.2", this.offset-2);
+
+        while  (this.offset < this.regexlen) {
+            final int ch = this.regex.charAt(this.offset);
+            if ('1' <= ch && ch <= '9') {
+                refnum = (refnum * 10) + (ch - '0');
+                if (refnum < this.parennumber) {
+                    ++this.offset;
+                    finalRefnum = refnum;
+                    this.chardata = ch;
+                }
+                else {
+                    break;
+                }
+            }
+            else {
+                break;
+            }
+        }
+
+        Token tok = Token.createBackReference(finalRefnum);
         this.hasBackReferences = true;
         if (this.references == null)  this.references = new Vector();
-        this.references.addElement(new ReferencePosition(refnum, 
this.offset-2));
+        this.references.addElement(new ReferencePosition(finalRefnum, 
this.offset-2));
         this.next();
         return tok;
     }



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

Reply via email to