This patch fixes PR34270 by adding support for \p{javaX} generally. We were completely missing this from our regex implementation.
ChangeLog: 2008-02-21 Andrew John Hughes <[EMAIL PROTECTED]> * gnu/java/util/regex/REException.java: (REException(String,Throwable,int,int)): Added constructor which also includes the cause. * gnu/java/util/regex/RETokenNamedProperty.java: (getHandler(String)): Add support for \p{javaX}. (JavaCategoryHandler): New class. -- Andrew :-) Support Free Java! Contribute to GNU Classpath and the OpenJDK http://www.gnu.org/software/classpath http://openjdk.java.net
Index: gnu/java/util/regex/REException.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/util/regex/REException.java,v retrieving revision 1.1 diff -u -r1.1 REException.java --- gnu/java/util/regex/REException.java 7 Jun 2006 19:30:06 -0000 1.1 +++ gnu/java/util/regex/REException.java 21 Feb 2008 12:52:21 -0000 @@ -147,6 +147,12 @@ this.pos = position; } + REException(String msg, Throwable cause, int type, int position) { + super(msg, cause); + this.type = type; + this.pos = position; + } + /** * Returns the type of the exception, one of the constants listed above. */ Index: gnu/java/util/regex/RETokenNamedProperty.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/util/regex/RETokenNamedProperty.java,v retrieving revision 1.2 diff -u -r1.2 RETokenNamedProperty.java --- gnu/java/util/regex/RETokenNamedProperty.java 18 Nov 2006 17:22:46 -0000 1.2 +++ gnu/java/util/regex/RETokenNamedProperty.java 21 Feb 2008 12:52:21 -0000 @@ -38,6 +38,9 @@ package gnu.java.util.regex; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + final class RETokenNamedProperty extends REToken { String name; boolean insens; @@ -268,6 +271,20 @@ return true; } }; + if (name.startsWith("java")) + { + try + { + Method m = Character.class.getMethod("is" + name.substring(4), + Character.TYPE); + return new JavaCategoryHandler(m); + } + catch (NoSuchMethodException e) + { + throw new REException("Unsupported Java handler: " + name, e, + REException.REG_ESCAPE, 0); + } + } throw new REException("unsupported name " + name, REException.REG_ESCAPE, 0); } @@ -320,4 +337,37 @@ } } + /** + * Handle the Java-specific extensions \p{javaX} where X + * is a method from Character of the form isX + * + * @author Andrew John Hughes ([EMAIL PROTECTED]) + */ + private static class JavaCategoryHandler + extends Handler + { + private Method method; + + public JavaCategoryHandler(Method m) + { + this.method = m; + } + + public boolean includes(char c) + { + try + { + return (Boolean) method.invoke(null, c); + } + catch (IllegalAccessException e) + { + throw new InternalError("Unable to access method " + method); + } + catch (InvocationTargetException e) + { + throw new InternalError("Error invoking " + method); + } + } + } + }