This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi-xmlbeans.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 4aec5c4e define \w as [^\p{P}\p{Z}\p{C}] in the xsd regex parser (#145)
4aec5c4e is described below

commit 4aec5c4e20a6babef654d9e7fcbcb58c71c390de
Author: aizu-m <[email protected]>
AuthorDate: Mon Nov 16 01:22:19 2026 +0530

    define \w as [^\p{P}\p{Z}\p{C}] in the xsd regex parser (#145)
    
    * define \w as [^\p{P}\p{Z}\p{C}] in the xsd regex parser
    
    * keep the old \w tables by default, spec \w behind xmlbean.regex.strictword
    
    * configure the legacy \w tables with XmlOptions instead of a system 
property
    
    \w and \W in pattern facets now follow the XML Schema definition
    ([#x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}]) by default. The pre-5.5.0 XML 1.0
    Letter and Digit tables are available per type system with
    XmlOptions.setCompileLegacyRegexWordClass(), replacing the
    xmlbean.regex.strictword system property.
    
    The choice is a new "L" regex option, so it is per expression rather than
    global. Compiled .xsb files record it with a FLAG_SCHEMA_REGEX_WORD type
    flag; types written by older versions lack the flag and load with the
    legacy tables, so existing precompiled schema jars keep their behaviour.
    Older runtimes ignore the flag, so no xsb version bump is needed.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    
    * the legacy \w option ships in 6.0.0, not 5.5.0
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    
    ---------
    
    Co-authored-by: PJ Fanning <[email protected]>
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 src/main/java/org/apache/xmlbeans/XmlOptions.java  | 35 +++++++++
 .../xmlbeans/impl/regex/ParserForXMLSchema.java    | 25 +++++-
 .../org/apache/xmlbeans/impl/regex/REUtil.java     |  5 ++
 .../xmlbeans/impl/regex/RegularExpression.java     | 17 ++++
 .../xmlbeans/impl/schema/SchemaTypeSystemImpl.java |  3 +
 .../impl/schema/StscSimpleTypeResolver.java        |  3 +-
 .../org/apache/xmlbeans/impl/schema/StscState.java | 10 +++
 .../org/apache/xmlbeans/impl/schema/XsbReader.java |  7 +-
 .../misc/checkin/RegexWordClassCompileTest.java    | 91 ++++++++++++++++++++++
 .../java/misc/checkin/RegularExpressionTest.java   | 70 ++++++++++++++++-
 10 files changed, 258 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/xmlbeans/XmlOptions.java 
b/src/main/java/org/apache/xmlbeans/XmlOptions.java
index 4a7075b9..be3bddfa 100644
--- a/src/main/java/org/apache/xmlbeans/XmlOptions.java
+++ b/src/main/java/org/apache/xmlbeans/XmlOptions.java
@@ -131,6 +131,7 @@ public class XmlOptions implements java.io.Serializable {
         COMPILE_NO_VALIDATION,
         COMPILE_NO_UPA_RULE,
         COMPILE_NO_PVR_RULE,
+        COMPILE_LEGACY_REGEX_WORD_CLASS,
         COMPILE_NO_ANNOTATIONS,
         COMPILE_DOWNLOAD_URLS,
         COMPILE_MDEF_NAMESPACES,
@@ -1078,6 +1079,40 @@ public class XmlOptions implements java.io.Serializable {
         return hasOption(XmlOptionsKeys.COMPILE_NO_PVR_RULE);
     }
 
+    /**
+     * If this option is set, {@code \w} and {@code \W} in pattern facets use 
the
+     * XML 1.0 Letter and Digit tables, as XMLBeans did before 6.0.0, instead 
of the
+     * XML Schema definition of {@code \w}, which is every character except
+     * punctuation, separators and "other" characters
+     * ({@code [#x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}]}). See
+     * <a target="_blank" 
href="https://www.w3.org/TR/xmlschema-2/#cces-mce";>Appendix F of the XML Schema 
Part 2 specification</a>.
+     * <p>
+     * The setting is stored with the compiled {@code SchemaTypeSystem}. Type 
systems
+     * compiled by XMLBeans versions before 6.0.0 keep the old tables when 
loaded.
+     *
+     * @see XmlBeans#compileXsd
+     * @since 6.0.0
+     */
+    public XmlOptions setCompileLegacyRegexWordClass() {
+        return setCompileLegacyRegexWordClass(true);
+    }
+
+    /**
+     * @see #setCompileLegacyRegexWordClass()
+     * @since 6.0.0
+     */
+    public XmlOptions setCompileLegacyRegexWordClass(boolean b) {
+        return set(XmlOptionsKeys.COMPILE_LEGACY_REGEX_WORD_CLASS, b);
+    }
+
+    /**
+     * @see #setCompileLegacyRegexWordClass()
+     * @since 6.0.0
+     */
+    public boolean isCompileLegacyRegexWordClass() {
+        return hasOption(XmlOptionsKeys.COMPILE_LEGACY_REGEX_WORD_CLASS);
+    }
+
     /**
      * if this option is set, the schema compiler will skip annotations when
      * processing Schema components.
diff --git 
a/src/main/java/org/apache/xmlbeans/impl/regex/ParserForXMLSchema.java 
b/src/main/java/org/apache/xmlbeans/impl/regex/ParserForXMLSchema.java
index 3e689f10..6c33bfbf 100644
--- a/src/main/java/org/apache/xmlbeans/impl/regex/ParserForXMLSchema.java
+++ b/src/main/java/org/apache/xmlbeans/impl/regex/ParserForXMLSchema.java
@@ -287,6 +287,11 @@ class ParserForXMLSchema extends RegexParser {
         throw this.ex("parser.process.1", this.offset);
     }
 
+    private String wordRangeName() {
+        return (this.options & RegularExpression.XMLSCHEMA_LEGACY_WORD) != 0
+            ? "xml:isWordLegacy" : "xml:isWord";
+    }
+
     Token getTokenForShorthand(int ch) {
         switch (ch) {
           case 'd':
@@ -294,9 +299,9 @@ class ParserForXMLSchema extends RegexParser {
           case 'D':
             return ParserForXMLSchema.getRange("xml:isDigit", false);
           case 'w':
-            return ParserForXMLSchema.getRange("xml:isWord", true);
+            return ParserForXMLSchema.getRange(wordRangeName(), true);
           case 'W':
-            return ParserForXMLSchema.getRange("xml:isWord", false);
+            return ParserForXMLSchema.getRange(wordRangeName(), false);
           case 's':
             return ParserForXMLSchema.getRange("xml:isSpace", true);
           case 'S':
@@ -366,8 +371,20 @@ class ParserForXMLSchema extends RegexParser {
             tok = Token.createRange();
             setupRange(tok, LETTERS);
             tok.mergeRanges(ranges.get("xml:isDigit"));
-            ranges.put("xml:isWord", tok);
-            ranges2.put("xml:isWord", Token.complementRanges(tok));
+            // the XML 1.0 Letter and Digit tables, used for \w with the "L" 
option
+            ranges.put("xml:isWordLegacy", tok);
+            ranges2.put("xml:isWordLegacy", Token.complementRanges(tok));
+
+            /*
+             * \w is defined by the XML Schema specification to be:
+             * [#x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}] (all characters except the 
set of "punctuation", "separator" and "other" characters)
+             */
+            tok = Token.createRange();
+            tok.mergeRanges(Token.getRange("P", true));
+            tok.mergeRanges(Token.getRange("Z", true));
+            tok.mergeRanges(Token.getRange("C", true));
+            ranges2.put("xml:isWord", tok);
+            ranges.put("xml:isWord", Token.complementRanges(tok));
 
             tok = Token.createRange();
             setupRange(tok, NAMECHARS);
diff --git a/src/main/java/org/apache/xmlbeans/impl/regex/REUtil.java 
b/src/main/java/org/apache/xmlbeans/impl/regex/REUtil.java
index 0c868932..1a68ea24 100644
--- a/src/main/java/org/apache/xmlbeans/impl/regex/REUtil.java
+++ b/src/main/java/org/apache/xmlbeans/impl/regex/REUtil.java
@@ -83,6 +83,9 @@ public final class REUtil {
           case ',':
             ret = RegularExpression.SPECIAL_COMMA;
             break;
+          case 'L':
+            ret = RegularExpression.XMLSCHEMA_LEGACY_WORD;
+            break;
           default:
         }
         return ret;
@@ -122,6 +125,8 @@ public final class REUtil {
             sb.append((char)'x');
         if ((options & RegularExpression.SPECIAL_COMMA) != 0)
             sb.append((char)',');
+        if ((options & RegularExpression.XMLSCHEMA_LEGACY_WORD) != 0)
+            sb.append((char)'L');
         return sb.toString().intern();
     }
 
diff --git 
a/src/main/java/org/apache/xmlbeans/impl/regex/RegularExpression.java 
b/src/main/java/org/apache/xmlbeans/impl/regex/RegularExpression.java
index 317d9043..dc8df60c 100644
--- a/src/main/java/org/apache/xmlbeans/impl/regex/RegularExpression.java
+++ b/src/main/java/org/apache/xmlbeans/impl/regex/RegularExpression.java
@@ -2245,6 +2245,12 @@ public class RegularExpression implements 
java.io.Serializable {
      * ",".
      */
     static final int SPECIAL_COMMA = 1<<10;
+    /**
+     * "L". Only meaningful with "X": \w and \W use the XML 1.0 Letter and 
Digit
+     * tables that XMLBeans used before 6.0.0, instead of the XML Schema 
definition
+     * of \w ({@code [#x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}]}).
+     */
+    static final int XMLSCHEMA_LEGACY_WORD = 1<<11;
 
 
     private static boolean isSet(int options, int flag) {
@@ -2351,6 +2357,17 @@ public class RegularExpression implements 
java.io.Serializable {
         return REUtil.createOptionString(this.options);
     }
 
+    /**
+     * Returns true if this expression was compiled with the "L" option, so 
that
+     * \w and \W use the XML 1.0 Letter and Digit tables instead of the
+     * XML Schema definition of \w.
+     *
+     * @since 6.0.0
+     */
+    public boolean isLegacyWordClass() {
+        return isSet(this.options, XMLSCHEMA_LEGACY_WORD);
+    }
+
     /**
      *  Return true if patterns are the same and the options are equivalent.
      */
diff --git 
a/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java 
b/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
index 0c7585e5..44d635d8 100644
--- a/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
+++ b/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
@@ -92,6 +92,9 @@ public class SchemaTypeSystemImpl extends 
SchemaTypeLoaderBase implements Schema
     static final int FLAG_FINAL_LIST = 0x20000;
     static final int FLAG_ABSTRACT = 0x40000;
     static final int FLAG_ATTRIBUTE_TYPE = 0x80000;
+    // pattern facets use the XML Schema definition of \w; types written before
+    // this flag existed use the XML 1.0 Letter and Digit tables
+    static final int FLAG_SCHEMA_REGEX_WORD = 0x100000;
 
     /**
      * regex to identify the type system holder package namespace
diff --git 
a/src/main/java/org/apache/xmlbeans/impl/schema/StscSimpleTypeResolver.java 
b/src/main/java/org/apache/xmlbeans/impl/schema/StscSimpleTypeResolver.java
index adfe67fd..b19166eb 100644
--- a/src/main/java/org/apache/xmlbeans/impl/schema/StscSimpleTypeResolver.java
+++ b/src/main/java/org/apache/xmlbeans/impl/schema/StscSimpleTypeResolver.java
@@ -836,7 +836,8 @@ public class StscSimpleTypeResolver {
                         case SchemaType.FACET_PATTERN:
                             RegularExpression p;
                             try {
-                                p = new 
RegularExpression(facet.getValue().getStringValue(), "X");
+                                p = new 
RegularExpression(facet.getValue().getStringValue(),
+                                    state.legacyRegexWordClass() ? "XL" : "X");
                             } catch (ParseException e) {
                                 state.error(XmlErrorCodes.PATTERN_REGEX, new 
Object[]{facet.getValue().getStringValue(), e.getMessage()}, facet);
                                 continue;
diff --git a/src/main/java/org/apache/xmlbeans/impl/schema/StscState.java 
b/src/main/java/org/apache/xmlbeans/impl/schema/StscState.java
index 1d334641..17781d47 100644
--- a/src/main/java/org/apache/xmlbeans/impl/schema/StscState.java
+++ b/src/main/java/org/apache/xmlbeans/impl/schema/StscState.java
@@ -103,6 +103,7 @@ public class StscState {
     private final List<SchemaAnnotation> _annotations = new ArrayList<>();
     private boolean _noUpa;
     private boolean _noPvr;
+    private boolean _legacyRegexWordClass;
     private boolean _noAnn;
     private boolean _mdefAll;
     private String _sourceCodeEncoding ;
@@ -475,6 +476,7 @@ public class StscState {
                  
!"true".equals(SystemProperties.getProperty("xmlbean.schemaannotations", 
"true"));
         _doingDownloads = options.isCompileDownloadUrls() ||
                           
"true".equals(SystemProperties.getProperty("xmlbean.downloadurls", "false"));
+        _legacyRegexWordClass = options.isCompileLegacyRegexWordClass();
         _maxNumberOfCharsForNumbers = options.getMaxNumberOfCharsForNumbers();
         _sourceCodeEncoding = options.getCharacterEncoding();
         if (_sourceCodeEncoding == null || _sourceCodeEncoding.isEmpty()) {
@@ -529,6 +531,14 @@ public class StscState {
         return _noPvr;
     }
 
+    /**
+     * True if pattern facets use the pre-6.0.0 XML 1.0 Letter and Digit 
tables for \w,
+     * see {@link XmlOptions#setCompileLegacyRegexWordClass()}.
+     */
+    public boolean legacyRegexWordClass() {
+        return _legacyRegexWordClass;
+    }
+
     /**
      * True if annotations should be skipped
      */
diff --git a/src/main/java/org/apache/xmlbeans/impl/schema/XsbReader.java 
b/src/main/java/org/apache/xmlbeans/impl/schema/XsbReader.java
index bc2b29e7..117fc699 100644
--- a/src/main/java/org/apache/xmlbeans/impl/schema/XsbReader.java
+++ b/src/main/java/org/apache/xmlbeans/impl/schema/XsbReader.java
@@ -1032,8 +1032,9 @@ class XsbReader {
 
                 int patternCount = readShort();
                 org.apache.xmlbeans.impl.regex.RegularExpression[] patterns = 
new org.apache.xmlbeans.impl.regex.RegularExpression[patternCount];
+                String patternOptions = (flags & FLAG_SCHEMA_REGEX_WORD) != 0 
? "X" : "XL";
                 for (int i = 0; i < patternCount; i++) {
-                    patterns[i] = new 
org.apache.xmlbeans.impl.regex.RegularExpression(readString(), "X");
+                    patterns[i] = new 
org.apache.xmlbeans.impl.regex.RegularExpression(readString(), patternOptions);
                 }
                 impl.setPatterns(patterns);
 
@@ -1165,6 +1166,10 @@ class XsbReader {
         if (type.hasPatternFacet()) {
             flags |= FLAG_HAS_PATTERN;
         }
+        org.apache.xmlbeans.impl.regex.RegularExpression[] typePatterns = 
((SchemaTypeImpl) type).getPatternExpressions();
+        if (typePatterns.length > 0 && !typePatterns[0].isLegacyWordClass()) {
+            flags |= FLAG_SCHEMA_REGEX_WORD;
+        }
         if (type.isOrderSensitive()) {
             flags |= FLAG_ORDER_SENSITIVE;
         }
diff --git a/src/test/java/misc/checkin/RegexWordClassCompileTest.java 
b/src/test/java/misc/checkin/RegexWordClassCompileTest.java
new file mode 100644
index 00000000..27217552
--- /dev/null
+++ b/src/test/java/misc/checkin/RegexWordClassCompileTest.java
@@ -0,0 +1,91 @@
+/*   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package misc.checkin;
+
+import org.apache.xmlbeans.SchemaTypeLoader;
+import org.apache.xmlbeans.SchemaTypeSystem;
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * XmlOptions.setCompileLegacyRegexWordClass switches pattern facets back to 
the
+ * XML 1.0 Letter and Digit tables for \w, and the choice survives saving the
+ * type system to .xsb files and loading it again.
+ */
+public class RegexWordClassCompileTest {
+
+    private static final String XSD =
+        "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' " +
+        "xmlns:t='urn:t' targetNamespace='urn:t'>" +
+        "  <xs:element name='e'><xs:simpleType>" +
+        "    <xs:restriction base='xs:string'><xs:pattern 
value='[^\\w]+'/></xs:restriction>" +
+        "  </xs:simpleType></xs:element>" +
+        "</xs:schema>";
+
+    // '+' is a symbol: inside the XML Schema \w, outside the XML 1.0 Letter 
and Digit tables
+    private static final String PLUS = "<t:e xmlns:t='urn:t'>+</t:e>";
+    // '.' is punctuation: outside \w in both
+    private static final String DOT = "<t:e xmlns:t='urn:t'>.</t:e>";
+
+    private static SchemaTypeSystem compile(XmlOptions options) throws 
Exception {
+        return XmlBeans.compileXsd(new 
XmlObject[]{SchemaDocument.Factory.parse(XSD)},
+            XmlBeans.getBuiltinTypeSystem(), options);
+    }
+
+    private static boolean valid(SchemaTypeLoader loader, String xml) throws 
Exception {
+        return loader.parse(xml, null, null).validate();
+    }
+
+    private static SchemaTypeLoader saveAndReload(SchemaTypeSystem sts, File 
dir) throws Exception {
+        sts.saveToDirectory(dir);
+        // load the .xsb files back from disk rather than using the compiled 
instance
+        SchemaTypeLoader loaded = 
XmlBeans.typeLoaderForResource(XmlBeans.resourceLoaderForPath(new File[]{dir}));
+        return XmlBeans.typeLoaderUnion(loaded, 
XmlBeans.getBuiltinTypeSystem());
+    }
+
+    @Test
+    void schemaWordClassByDefault(@TempDir File dir) throws Exception {
+        SchemaTypeSystem sts = compile(null);
+        SchemaTypeLoader loader = XmlBeans.typeLoaderUnion(sts, 
XmlBeans.getBuiltinTypeSystem());
+        assertFalse(valid(loader, PLUS));
+        assertTrue(valid(loader, DOT));
+
+        SchemaTypeLoader reloaded = saveAndReload(sts, dir);
+        assertFalse(valid(reloaded, PLUS));
+        assertTrue(valid(reloaded, DOT));
+    }
+
+    @Test
+    void legacyWordClassOption(@TempDir File dir) throws Exception {
+        SchemaTypeSystem sts = compile(new 
XmlOptions().setCompileLegacyRegexWordClass());
+        SchemaTypeLoader loader = XmlBeans.typeLoaderUnion(sts, 
XmlBeans.getBuiltinTypeSystem());
+        assertTrue(valid(loader, PLUS));
+        assertTrue(valid(loader, DOT));
+
+        SchemaTypeLoader reloaded = saveAndReload(sts, dir);
+        assertTrue(valid(reloaded, PLUS));
+        assertTrue(valid(reloaded, DOT));
+    }
+}
diff --git a/src/test/java/misc/checkin/RegularExpressionTest.java 
b/src/test/java/misc/checkin/RegularExpressionTest.java
index 4aad8cd2..bbefdb90 100644
--- a/src/test/java/misc/checkin/RegularExpressionTest.java
+++ b/src/test/java/misc/checkin/RegularExpressionTest.java
@@ -19,12 +19,12 @@ import org.apache.xmlbeans.impl.regex.ParseException;
 import org.apache.xmlbeans.impl.regex.RegularExpression;
 import org.junit.jupiter.api.Test;
 
-import java.time.Duration;
+import java.time.Duration;
 import java.util.Random;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -110,6 +110,72 @@ public class RegularExpressionTest {
         }
     }
 
+    @Test
+    void testLegacyWordOption() {
+        // with the "L" option, \w keeps the XML 1.0 Letter and Digit tables
+        RegularExpression word = new RegularExpression("\\w+", "XL");
+        RegularExpression notWord = new RegularExpression("\\W+", "XL");
+        assertTrue(word.isLegacyWordClass());
+        assertTrue(word.getOptions().contains("L"));
+        assertFalse(word.matches("+"));
+        assertTrue(notWord.matches("+"));
+        assertFalse(word.matches("\u017F"));
+        assertTrue(word.matches("a1"));
+    }
+
+    @Test
+    void testWordEscapeFollowsSchemaDefinition() {
+        // XML Schema defines \w as [#x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}]: 
everything that
+        // is not punctuation, a separator or "other". The legacy ("L") tables 
are the
+        // XML 1.0 Letter and Digit tables, so symbols, marks,
+        // letter-like numbers and letters added after Unicode 2.0 are outside 
\w while
+        // \W and [^\w] match them (the same bug as XERCESJ-1651 in the Xerces 
port)
+        RegularExpression word = new RegularExpression("\\w+", "X");
+        RegularExpression notWord = new RegularExpression("\\W+", "X");
+        RegularExpression negated = new RegularExpression("[^\\w]+", "X");
+        for (int cp = 0; cp < 0x10000; cp++) {
+            int type = Character.getType(cp);
+            if (type == Character.SURROGATE) {
+                continue;
+            }
+            String s = String.valueOf((char) cp);
+            boolean in;
+            switch (type) {
+                case Character.CONNECTOR_PUNCTUATION:
+                case Character.DASH_PUNCTUATION:
+                case Character.START_PUNCTUATION:
+                case Character.END_PUNCTUATION:
+                case Character.INITIAL_QUOTE_PUNCTUATION:
+                case Character.FINAL_QUOTE_PUNCTUATION:
+                case Character.OTHER_PUNCTUATION:
+                case Character.SPACE_SEPARATOR:
+                case Character.LINE_SEPARATOR:
+                case Character.PARAGRAPH_SEPARATOR:
+                case Character.CONTROL:
+                case Character.FORMAT:
+                case Character.PRIVATE_USE:
+                case Character.UNASSIGNED:
+                    in = false;
+                    break;
+                default:
+                    in = true;
+            }
+            String hex = Integer.toHexString(cp);
+            assertEquals(in, word.matches(s), () -> "\\w, code point " + hex);
+            assertEquals(!in, notWord.matches(s), () -> "\\W, code point " + 
hex);
+            assertEquals(!in, negated.matches(s), () -> "[^\\w], code point " 
+ hex);
+        }
+        // a few of the characters the old tables got wrong, spelled out
+        for (String s : new String[]{"^", "+", "|", "$", "\u0301", "\u2167", 
"\u01C5", "\u017F", "\uFB00"}) {
+            assertTrue(word.matches(s), s);
+            assertFalse(notWord.matches(s), s);
+        }
+        for (String s : new String[]{".", "-", "(", "\u00AB", " ", "\u00A0", 
"\t", "\u200B"}) {
+            assertFalse(word.matches(s), s);
+            assertTrue(notWord.matches(s), s);
+        }
+    }
+
     private static final String AB ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     private static final Random rnd = new Random();
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to