diff options
Diffstat (limited to 'libjava/gnu')
-rw-r--r-- | libjava/gnu/java/nio/channels/natFileChannelPosix.cc | 11 | ||||
-rw-r--r-- | libjava/gnu/regexp/RE.java | 36 | ||||
-rw-r--r-- | libjava/gnu/regexp/RESyntax.java | 8 | ||||
-rw-r--r-- | libjava/gnu/regexp/RETokenRepeated.java | 13 |
4 files changed, 49 insertions, 19 deletions
diff --git a/libjava/gnu/java/nio/channels/natFileChannelPosix.cc b/libjava/gnu/java/nio/channels/natFileChannelPosix.cc index 742201bde94..24b6396c66c 100644 --- a/libjava/gnu/java/nio/channels/natFileChannelPosix.cc +++ b/libjava/gnu/java/nio/channels/natFileChannelPosix.cc @@ -37,6 +37,7 @@ details. */ #include <java/lang/NullPointerException.h> #include <java/lang/System.h> #include <java/lang/String.h> +#include <java/lang/StringBuffer.h> #include <java/lang/Thread.h> #include <java/nio/ByteBuffer.h> #include <java/nio/MappedByteBufferImpl.h> @@ -168,13 +169,13 @@ FileChannelImpl::open (jstring path, jint jflags) } if (fd == -1) { - char msg[MAXPATHLEN + 200]; // We choose the formatting here for JDK compatibility, believe // it or not. - sprintf (msg, "%.*s (%.*s)", - MAXPATHLEN + 150, buf, - 40, strerror (errno)); - throw new ::java::io::FileNotFoundException (JvNewStringLatin1 (msg)); + ::java::lang::StringBuffer *msg = new ::java::lang::StringBuffer (path); + msg->append (JvNewStringUTF (" (")); + msg->append (JvNewStringUTF (strerror (errno))); + msg->append (JvNewStringUTF (")")); + throw new ::java::io::FileNotFoundException (msg->toString ()); } _Jv_platform_close_on_exec (fd); diff --git a/libjava/gnu/regexp/RE.java b/libjava/gnu/regexp/RE.java index c8c8a3eb9ff..541e8cb950f 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); } diff --git a/libjava/gnu/regexp/RESyntax.java b/libjava/gnu/regexp/RESyntax.java index 649bd0df584..7cb3e1400b8 100644 --- a/libjava/gnu/regexp/RESyntax.java +++ b/libjava/gnu/regexp/RESyntax.java @@ -197,7 +197,12 @@ public final class RESyntax implements Serializable { */ public static final int RE_CHAR_CLASS_ESC_IN_LISTS = 24; - private static final int BIT_TOTAL = 25; + /** + * Syntax bit. Possessive matching is allowed (++, *+, ?+, {x,y}+). + */ + public static final int RE_POSSESSIVE_OPS = 25; + + private static final int BIT_TOTAL = 26; /** * Predefined syntax. @@ -425,6 +430,7 @@ public final class RESyntax implements Serializable { RE_SYNTAX_JAVA_1_4 = new RESyntax(RE_SYNTAX_PERL5) // XXX + .set(RE_POSSESSIVE_OPS) // *+,?+,++,{}+ .makeFinal(); } diff --git a/libjava/gnu/regexp/RETokenRepeated.java b/libjava/gnu/regexp/RETokenRepeated.java index 8c789271220..821e4c55c0f 100644 --- a/libjava/gnu/regexp/RETokenRepeated.java +++ b/libjava/gnu/regexp/RETokenRepeated.java @@ -44,6 +44,7 @@ final class RETokenRepeated extends REToken { private REToken token; private int min,max; private boolean stingy; + private boolean possessive; RETokenRepeated(int subIndex, REToken token, int min, int max) { super(subIndex); @@ -61,6 +62,16 @@ final class RETokenRepeated extends REToken { boolean isStingy() { return stingy; } + + /** Sets possessive matching mode to true. */ + void makePossessive() { + possessive = true; + } + + /** Queries if this token has possessive matching enabled. */ + boolean isPossessive() { + return possessive; + } /** * The minimum length of a repeated token is the minimum length @@ -172,6 +183,8 @@ final class RETokenRepeated extends REToken { } } // else did not match rest of the tokens, try again on smaller sample + // or break out when performing possessive matching + if (possessive) break; } if (allResults != null) { mymatch.assignFrom(allResults); // does this get all? |