Index: src/java/org/apache/regexp/RE.java =================================================================== RCS file: /home/cvspublic/jakarta-regexp/src/java/org/apache/regexp/RE.java,v retrieving revision 1.14 diff -u -r1.14 RE.java --- src/java/org/apache/regexp/RE.java 6 Sep 2003 01:45:51 -0000 1.14 +++ src/java/org/apache/regexp/RE.java 30 Dec 2003 02:25:13 -0000 @@ -295,12 +295,27 @@ * *
*
+ * Line terminators
+ *
+ * A line terminator is a one- or two-character sequence that marks
+ * the end of a line of the input character sequence. The following
+ * are recognized as line terminators:
+ *
* RE runs programs compiled by the RECompiler class. But the RE * matcher class does not include the actual regular expression compiler * for reasons of efficiency. In fact, if you want to pre-compile one * or more regular expressions, the 'recompile' class can be invoked * from the command line to produce compiled output like this: - * + * *
* * // Pre-compiled regular expression "a*b" @@ -462,9 +477,6 @@ static final int offsetNext = 2; // Next index offset (third char) static final int nodeSize = 3; // Node size (in chars) - /** Line Separator */ - static final String NEWLINE = System.getProperty("line.separator"); - // State of current program REProgram program; // Compiled regular expression 'program' transient CharacterIterator search; // The string being matched against @@ -1840,20 +1852,14 @@ /** @return true if at the i-th position in the 'search' a newline ends */ private boolean isNewline(int i) { + char nextChar = search.charAt(i); - if (i < NEWLINE.length() - 1) { - return false; - } - - if (search.charAt(i) == '\n') { + if (nextChar == '\n' || nextChar == '\r' || nextChar == '\u0085' + || nextChar == '\u2028' || nextChar == '\u2029') + { return true; } - for (int j = NEWLINE.length() - 1; j >= 0; j--, i--) { - if (NEWLINE.charAt(j) != search.charAt(i)) { - return false; - } - } - return true; + return false; } } Index: src/java/org/apache/regexp/RETest.java =================================================================== RCS file: /home/cvspublic/jakarta-regexp/src/java/org/apache/regexp/RETest.java,v retrieving revision 1.8 diff -u -r1.8 RETest.java --- src/java/org/apache/regexp/RETest.java 20 Dec 2003 17:21:44 -0000 1.8 +++ src/java/org/apache/regexp/RETest.java 30 Dec 2003 02:25:16 -0000 @@ -411,6 +411,28 @@ s = r.subst("variable=value", "$1_test_$212", RE.REPLACE_BACKREFERENCES); assertEquals("Wrong subst() result", "variable_test_value12", s); + + // Test MATCH_MULTILINE + // test for eol/bol symbols + r = new RE("^[ \t]*window.location.href=", RE.MATCH_MULTILINE); + if (!r.match("\nwindow.location.href=")) { + fail("\"\\nwindow.location.href=\" doesn't match"); + } + if (!r.match("\rwindow.location.href=")) { + fail("\"\\rwindow.location.href=\" doesn't match"); + } + if (!r.match("\r\nwindow.location.href=")) { + fail("\"\\r\\nwindow.location.href=\" doesn't match"); + } + if (!r.match("\u0085window.location.href=")) { + fail("\"\\u0085window.location.href=\" doesn't match"); + } + if (!r.match("\u2028window.location.href=")) { + fail("\"\\u2028window.location.href=\" doesn't match"); + } + if (!r.match("\u2029window.location.href=")) { + fail("\"\\u2029window.location.href=\" doesn't match"); + } } private void testPrecompiledRE()