classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] RFC: gnu.regexp fix to allow "([(])"


From: Ito Kazumitsu
Subject: [cp-patches] RFC: gnu.regexp fix to allow "([(])"
Date: Wed, 11 Jan 2006 01:08:27 +0900 (JST)

This fixes the bug #22802.

ChangeLog:
2006-01-10  Ito Kazumitsu  <address@hidden>

        Fixes bug #22802
        * gnu/regexp/RE.java(initialize): Fixed the parsing of
        character classes within a subexpression.

Index: classpath/gnu/regexp/RE.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/RE.java,v
retrieving revision 1.8
diff -u -r1.8 RE.java
--- classpath/gnu/regexp/RE.java        6 Jan 2006 17:13:20 -0000       1.8
+++ classpath/gnu/regexp/RE.java        10 Jan 2006 15:58:40 -0000
@@ -551,13 +551,48 @@
        int nested = 0;
 
        while ( ((nextIndex = getCharUnit(pattern,endIndex,unit,false)) > 0)
-               && !(nested == 0 && (unit.ch == ')') && 
(syntax.get(RESyntax.RE_NO_BK_PARENS) ^ (unit.bk || quot))) )
+               && !(nested == 0 && (unit.ch == ')') && 
(syntax.get(RESyntax.RE_NO_BK_PARENS) ^ (unit.bk || quot))) ) {
          if ((endIndex = nextIndex) >= pLength)
            throw new 
REException(getLocalizedMessage("subexpr.no.end"),REException.REG_ESUBREG,nextIndex);
+         else if ((unit.ch == '[') && !(unit.bk || quot)) {
+           // I hate to do something similar to the LIST OPERATOR matters
+           // above, but ...
+           int listIndex = nextIndex;
+           if (listIndex < pLength && pattern[listIndex] == '^') listIndex++;
+           if (listIndex < pLength && pattern[listIndex] == ']') listIndex++;
+           int listEndIndex = -1;
+           int listNest = 0;
+           while (listIndex < pLength && listEndIndex < 0) {
+             switch(pattern[listIndex++]) {
+               case '\\':
+                 listIndex++;
+                 break;
+               case '[':
+                 // Sun's API document says that regexp like "[a-d[m-p]]"
+                 // is legal.
+                 listNest++;
+                 break;
+               case ']':
+                 if (listNest == 0)
+                   listEndIndex = listIndex;
+                 listNest--;
+                 break;
+             }
+           }
+           if (listEndIndex >= 0) {
+             nextIndex = listEndIndex;
+             if ((endIndex = nextIndex) >= pLength)
+               throw new 
REException(getLocalizedMessage("subexpr.no.end"),REException.REG_ESUBREG,nextIndex);
+             else
+               continue;
+           }
+           throw new 
REException(getLocalizedMessage("subexpr.no.end"),REException.REG_ESUBREG,nextIndex);
+         }
          else if (unit.ch == '(' && (syntax.get(RESyntax.RE_NO_BK_PARENS) ^ 
(unit.bk || quot)))
            nested++;
          else if (unit.ch == ')' && (syntax.get(RESyntax.RE_NO_BK_PARENS) ^ 
(unit.bk || quot)))
            nested--;
+       }
 
        // endIndex is now position at a ')','\)' 
        // nextIndex is end of string or position after ')' or '\)'

reply via email to

[Prev in Thread] Current Thread [Next in Thread]