Hi, This is to support Perl's "/x" modifier.
2006-03-19 Ito Kazumitsu <[EMAIL PROTECTED]> * gnu/regexp/RE.java(REG_X_COMMENTS): New copilation flag, (initialize): Ignore whiltespaces and comments if REG_X_COMMENTS is set. * java/util/regex/Pattern.java(constructor): Set RE.REG_X_COMMENTS if COMMENTS is set.
Index: classpath/gnu/regexp/RE.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/regexp/RE.java,v retrieving revision 1.19 diff -u -r1.19 RE.java --- classpath/gnu/regexp/RE.java 11 Mar 2006 01:39:49 -0000 1.19 +++ classpath/gnu/regexp/RE.java 19 Mar 2006 00:00:34 -0000 @@ -236,6 +236,13 @@ */ public static final int REG_REPLACE_USE_BACKSLASHESCAPE = 0x0200; + /** + * Compilation flag. Allow whitespace and comments in pattern. + * This is equivalent to the "/x" operator in Perl. + */ + + public static final int REG_X_COMMENTS = 0x0400; + /** Returns a string representing the version of the gnu.regexp package. */ public static final String version() { return VERSION; @@ -373,6 +380,31 @@ if (quot) unit.bk = false; + if (((cflags & REG_X_COMMENTS) > 0) && (!unit.bk) && (!quot)) { + if (Character.isWhitespace(unit.ch)) { + continue; + } + if (unit.ch == '#') { + for (int i = index; i < pLength; i++) { + if (pattern[i] == '\n') { + index = i + 1; + continue; + } + else if (pattern[i] == '\r') { + if (i + 1 < pLength && pattern[i + 1] == '\n') { + index = i + 2; + } + else { + index = i + 1; + } + continue; + } + } + index = pLength; + continue; + } + } + // ALTERNATION OPERATOR // \| or | (if RE_NO_BK_VBAR) or newline (if RE_NEWLINE_ALT) // not available if RE_LIMITED_OPS is set @@ -497,7 +529,7 @@ case 'm': case 's': // case 'u': not supported - // case 'x': not supported + case 'x': case '-': if (!syntax.get(RESyntax.RE_EMBEDDED_FLAGS)) break; // Set or reset syntax flags. @@ -537,7 +569,13 @@ flagIndex++; break; // case 'u': not supported - // case 'x': not supported + case 'x': + if (negate) + newCflags &= ~REG_X_COMMENTS; + else + newCflags |= REG_X_COMMENTS; + flagIndex++; + break; case '-': negate = true; flagIndex++; Index: classpath/java/util/regex/Pattern.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/util/regex/Pattern.java,v retrieving revision 1.14 diff -u -r1.14 Pattern.java --- classpath/java/util/regex/Pattern.java 13 Jan 2006 09:49:52 -0000 1.14 +++ classpath/java/util/regex/Pattern.java 19 Mar 2006 00:00:34 -0000 @@ -94,7 +94,7 @@ if ((flags & COMMENTS) != 0) { - // Use a syntax with support for comments? + gnuFlags |= RE.REG_X_COMMENTS; } try