diff options
author | Ziga Mahkovec <ziga.mahkovec@klika.si> | 2005-06-02 00:11:00 +0200 |
---|---|---|
committer | Ziga Mahkovec <ziga@gcc.gnu.org> | 2005-06-01 22:11:00 +0000 |
commit | 7e1603c0f0dea72c62f5b78cbfbcbeaf4ac05207 (patch) | |
tree | c21882d9affe68b641900cf6ea85eb1ec0847f80 /libjava/gnu/regexp/RE.java | |
parent | cce7074710fc4712506c58a183034e53b87262fa (diff) | |
download | gcc-7e1603c0f0dea72c62f5b78cbfbcbeaf4ac05207.zip gcc-7e1603c0f0dea72c62f5b78cbfbcbeaf4ac05207.tar.gz gcc-7e1603c0f0dea72c62f5b78cbfbcbeaf4ac05207.tar.bz2 |
re PR libgcj/20435 (regex pattern compiling bug)
2005-06-01 Ziga Mahkovec <ziga.mahkovec@klika.si>
PR libgcj/20435:
* gnu/regexp/RESyntax.java (RE_POSSESSIVE_OPS): New field.
(static): Add possessive matching to JAVA_1_4 syntax.
* gnu/regexp/RETokenRepeated.java (possessive): New field.
(makePossessive, isPossessive): New methods.
(match): Don't back off during possessive matching.
* gnu/regexp/RE.java (initalize): Accept possessive quantifier.
* java/util/regex/Pattern.java (constructor): Switch syntax from PERL5
to JAVA_1_4.
From-SVN: r100466
Diffstat (limited to 'libjava/gnu/regexp/RE.java')
-rw-r--r-- | libjava/gnu/regexp/RE.java | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/libjava/gnu/regexp/RE.java b/libjava/gnu/regexp/RE.java index c8c8a3e..541e8cb 100644 --- a/libjava/gnu/regexp/RE.java +++ b/libjava/gnu/regexp/RE.java @@ -629,20 +629,29 @@ public class RE extends REToken { currentToken = setRepeated(currentToken,0,Integer.MAX_VALUE,index); } - // ONE-OR-MORE REPEAT OPERATOR + // ONE-OR-MORE REPEAT OPERATOR / POSSESSIVE MATCHING OPERATOR // + | \+ depending on RE_BK_PLUS_QM // not available if RE_LIMITED_OPS is set else if ((unit.ch == '+') && !syntax.get(RESyntax.RE_LIMITED_OPS) && (!syntax.get(RESyntax.RE_BK_PLUS_QM) ^ (unit.bk || quot))) { if (currentToken == null) throw new REException(getLocalizedMessage("repeat.no.token"),REException.REG_BADRPT,index); - if (currentToken instanceof RETokenRepeated) - throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index); - if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary) + + // Check for possessive matching on RETokenRepeated + if (currentToken instanceof RETokenRepeated) { + RETokenRepeated tokenRep = (RETokenRepeated)currentToken; + if (syntax.get(RESyntax.RE_POSSESSIVE_OPS) && !tokenRep.isPossessive() && !tokenRep.isStingy()) + tokenRep.makePossessive(); + else + throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index); + + } + else if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary) throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index); - if (currentToken.getMinimumLength() == 0) + else if (currentToken.getMinimumLength() == 0) throw new REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,index); - currentToken = setRepeated(currentToken,1,Integer.MAX_VALUE,index); + else + currentToken = setRepeated(currentToken,1,Integer.MAX_VALUE,index); } // ZERO-OR-ONE REPEAT OPERATOR / STINGY MATCHING OPERATOR @@ -655,13 +664,14 @@ public class RE extends REToken { // Check for stingy matching on RETokenRepeated if (currentToken instanceof RETokenRepeated) { - if (syntax.get(RESyntax.RE_STINGY_OPS) && !((RETokenRepeated)currentToken).isStingy()) - ((RETokenRepeated)currentToken).makeStingy(); - else - throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index); - } - else if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary) - throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index); + RETokenRepeated tokenRep = (RETokenRepeated)currentToken; + if (syntax.get(RESyntax.RE_STINGY_OPS) && !tokenRep.isStingy() && !tokenRep.isPossessive()) + tokenRep.makeStingy(); + else + throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index); + } + else if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary) + throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index); else currentToken = setRepeated(currentToken,0,1,index); } |