harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r387239 [9/21] - in /incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math: ./ Harmony/ doc/ doc/images/ make/ src/ src/common/ src/common/javasrc/ src/common/javasrc/java/ src/common/javasrc/java/applet/ src/common/javasrc/jav...
Date Mon, 20 Mar 2006 16:31:33 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractCharClass.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractCharClass.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractCharClass.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractCharClass.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,528 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+package java.util.regex;
+
+import java.util.BitSet;
+import java.util.ListResourceBundle;
+
+/**
+ * This class represents character classes, i.e. 
+ * sets of character either predefined or user defined.
+ * 
+ * Note, this class represent token, not node, so being 
+ * constructed by lexer.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+abstract class AbstractCharClass extends SpecialToken {
+    protected boolean alt;
+
+    static PredefinedCharacterClasses charClasses = new PredefinedCharacterClasses();
+
+    /**
+     * Returns true if this char class contains character specified;
+     * 
+     * @param ch
+     *            character to check;
+     */
+    abstract public boolean contains(int ch);
+
+    /**
+     * Returns BitSet representing this character class or <code>null</code>
+     * if this character class does not have character representation;
+     * 
+     * @return bitset
+     */
+    protected BitSet getBits() {
+        return null;
+    }
+
+    public int getType() {
+        return SpecialToken.TOK_CHARCLASS;
+    }
+
+    public AbstractCharClass getInstance() {
+        return this;
+    }
+
+    public boolean hasUCI() {
+        return false;
+    }
+
+    /**
+     * Sets this CharClass to negative form, i.e. if they will add some
+     * characters and after that set this class to negative it will accept all
+     * the characters except previously set ones.
+     * 
+     * Although this method will not alternate all the already set characters,
+     * just overall meaning of the class.
+     * 
+     * @see #contains(int)
+     * @see #intersect(CharClass)
+     * @see #union(CharClass)
+     */
+    public AbstractCharClass setNegative(boolean value) {
+        if (alt ^ value)
+            alt = !alt;
+        return this;
+    }
+
+    public boolean isNegative() {
+        return alt;
+    }
+
+    // -----------------------------------------------------------------
+    // Static methods and predefined classes
+    // -----------------------------------------------------------------
+    
+    public static boolean intersects(char ch1, char ch2) {
+        return ch1 == ch2;
+    }
+
+    public static boolean intersects(AbstractCharClass cc, char ch) {
+        return cc.contains(ch);
+    }
+
+    public static boolean intersects(AbstractCharClass cc1,
+            AbstractCharClass cc2) {
+        if (cc1.getBits() == null || cc2.getBits() == null)
+            return true;
+        return cc1.getBits().intersects(cc2.getBits());
+    }
+
+    public static AbstractCharClass getPredefinedClass(String name,
+            boolean negative) {
+        return ((LazyCharClass) charClasses.getObject(name)).getValue(negative);
+    }
+
+    abstract static class LazyCharClass {
+        AbstractCharClass posValue = null;
+
+        AbstractCharClass negValue = null;
+
+        public AbstractCharClass getValue(boolean negative) {
+            if (!negative && posValue == null) {
+                posValue = computeValue();
+            } else if (negative && negValue == null) {
+                negValue = computeValue().setNegative(true);
+            }
+            if (!negative)
+                return posValue;
+            return negValue;
+        }
+
+        protected abstract AbstractCharClass computeValue();
+    }
+
+    static class LazyDigit extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new CharClass().add('0', '9');
+        }
+    }
+
+    static class LazyNonDigit extends LazyDigit {
+        protected AbstractCharClass computeValue() {
+            return super.computeValue().setNegative(true);
+        }
+    }
+
+    static class LazySpace extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            /* 9-13 - \t\n\x0B\f\r; 32 - ' ' */
+            return new CharClass().add(9, 13).add(32);
+        }
+    }
+
+    static class LazyNonSpace extends LazySpace {
+        protected AbstractCharClass computeValue() {
+            return super.computeValue().setNegative(true);
+        }
+    }
+
+    static class LazyWord extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new CharClass().add('a', 'z').add('A', 'Z').add('0', '9')
+                    .add('_');
+        }
+    }
+
+    static class LazyNonWord extends LazyWord {
+        protected AbstractCharClass computeValue() {
+            return super.computeValue().setNegative(true);
+        }
+    }
+
+    static class LazyLower extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new CharClass().add('a', 'z');
+        }
+    }
+
+    static class LazyUpper extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new CharClass().add('A', 'Z');
+        }
+    }
+
+    static class LazyASCII extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new CharClass().add(0x00, 0x7F);
+        }
+    }
+
+    static class LazyAlpha extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new CharClass().add('a', 'z').add('A', 'Z');
+        }
+    }
+
+    static class LazyAlnum extends LazyAlpha {
+        protected AbstractCharClass computeValue() {
+            return ((CharClass) super.computeValue()).add('0', '9');
+        }
+    }
+
+    static class LazyPunct extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            /* Punctuation !"#$%&'()*+,-./:;<=>?@ [\]^_` {|}~ */
+            return new CharClass().add(0x21, 0x40).add(0x5B, 0x60).add(0x7B,
+                    0x7E);
+        }
+    }
+
+    static class LazyGraph extends LazyAlnum {
+        protected AbstractCharClass computeValue() {
+            /* plus punctiation */
+            return ((CharClass) super.computeValue()).add(0x21, 0x40).add(0x5B,
+                    0x60).add(0x7B, 0x7E);
+        }
+    }
+
+    static class LazyPrint extends LazyGraph {
+        protected AbstractCharClass computeValue() {
+            return ((CharClass) super.computeValue()).add(0x20);
+        }
+    }
+
+    static class LazyBlank extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new CharClass().add(' ').add('\t');
+        }
+    }
+
+    static class LazyCntrl extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new CharClass().add(0x00, 0x1F).add(0x7F);
+        }
+    }
+
+    static class LazyXDigit extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new CharClass().add('0', '9').add('a', 'f').add('A', 'F');
+        }
+    }
+
+    static class LazyRange extends LazyCharClass {
+        int start, end;
+
+        public LazyRange(int start, int end) {
+            this.start = start;
+            this.end = end;
+        }
+
+        public AbstractCharClass computeValue() {
+            return new CharClass().add(start, end);
+        }
+    }
+
+    static class LazySpecialsBlock extends LazyCharClass {
+        public AbstractCharClass computeValue() {
+            return new CharClass().add(0xFEFF, 0xFEFF).add(0xFFF0, 0xFFFD);
+        }
+    }
+
+    static class LazyCategoryScope extends LazyCharClass {
+        int category;
+
+        public LazyCategoryScope(int cat) {
+            this.category = cat;
+        }
+
+        protected AbstractCharClass computeValue() {
+            return new UnicodeCategoryScope(category);
+        }
+    }
+
+    static class LazyCategory extends LazyCharClass {
+        int category;
+
+        public LazyCategory(int cat) {
+            this.category = cat;
+        }
+
+        protected AbstractCharClass computeValue() {
+            return new UnicodeCategory(category);
+        }
+    }
+
+    static class LazyJavaLowerCase extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new AbstractCharClass() {
+                public boolean contains(int ch) {
+                    return Character.isLowerCase((char) ch);
+                }
+            };
+        }
+    }
+
+    static class LazyJavaUpperCase extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new AbstractCharClass() {
+                public boolean contains(int ch) {
+                    return Character.isUpperCase((char) ch);
+                }
+            };
+        }
+    }
+
+    static class LazyJavaWhitespace extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new AbstractCharClass() {
+                public boolean contains(int ch) {
+                    return Character.isWhitespace((char) ch);
+                }
+            };
+        }
+    }
+
+    static class LazyJavaMirrored extends LazyCharClass {
+        protected AbstractCharClass computeValue() {
+            return new AbstractCharClass() {
+                public boolean contains(int ch) {
+                    return Character.isMirrored((char) ch);
+                }
+            };
+        }
+    }
+
+    /**
+     * character classes generated from 
+     * http://www.unicode.org/reports/tr18/
+     * http://www.unicode.org/Public/4.1.0/ucd/Blocks.txt
+     */
+    static final class PredefinedCharacterClasses extends ListResourceBundle {
+        static LazyCharClass space = new LazySpace();
+
+        static LazyCharClass digit = new LazyDigit();
+
+        static final Object[][] contents = {
+                { "Lower", new LazyLower() },
+                { "Upper", new LazyUpper() },
+                { "ASCII", new LazyASCII() },
+                { "Alpha", new LazyAlpha() },
+                { "Digit", digit },
+                { "Alnum", new LazyAlnum() },
+                { "Punct", new LazyPunct() },
+                { "Graph", new LazyGraph() },
+                { "Print", new LazyPrint() },
+                { "Blank", new LazyBlank() },
+                { "Cntrl", new LazyCntrl() },
+                { "XDigit", new LazyXDigit() },
+                { "Space", space },
+                { "w", new LazyWord() },
+                { "W", new LazyNonWord() },
+                { "s", space },
+                { "S", new LazyNonSpace() },
+                { "d", digit },
+                { "D", new LazyNonDigit() },
+                { "BasicLatin", new LazyRange(0x0000, 0x007F) },
+                { "Latin-1Supplement", new LazyRange(0x0080, 0x00FF) },
+                { "LatinExtended-A", new LazyRange(0x0100, 0x017F) },
+                { "LatinExtended-B", new LazyRange(0x0180, 0x024F) },
+                { "IPAExtensions", new LazyRange(0x0250, 0x02AF) },
+                { "SpacingModifierLetters", new LazyRange(0x02B0, 0x02FF) },
+                { "CombiningDiacriticalMarks", new LazyRange(0x0300, 0x036F) },
+                { "Greek", new LazyRange(0x0370, 0x03FF) },
+                { "Cyrillic", new LazyRange(0x0400, 0x04FF) },
+                { "CyrillicSupplement", new LazyRange(0x0500, 0x052F) },
+                { "Armenian", new LazyRange(0x0530, 0x058F) },
+                { "Hebrew", new LazyRange(0x0590, 0x05FF) },
+                { "Arabic", new LazyRange(0x0600, 0x06FF) },
+                { "Syriac", new LazyRange(0x0700, 0x074F) },
+                { "ArabicSupplement", new LazyRange(0x0750, 0x077F) },
+                { "Thaana", new LazyRange(0x0780, 0x07BF) },
+                { "Devanagari", new LazyRange(0x0900, 0x097F) },
+                { "Bengali", new LazyRange(0x0980, 0x09FF) },
+                { "Gurmukhi", new LazyRange(0x0A00, 0x0A7F) },
+                { "Gujarati", new LazyRange(0x0A80, 0x0AFF) },
+                { "Oriya", new LazyRange(0x0B00, 0x0B7F) },
+                { "Tamil", new LazyRange(0x0B80, 0x0BFF) },
+                { "Telugu", new LazyRange(0x0C00, 0x0C7F) },
+                { "Kannada", new LazyRange(0x0C80, 0x0CFF) },
+                { "Malayalam", new LazyRange(0x0D00, 0x0D7F) },
+                { "Sinhala", new LazyRange(0x0D80, 0x0DFF) },
+                { "Thai", new LazyRange(0x0E00, 0x0E7F) },
+                { "Lao", new LazyRange(0x0E80, 0x0EFF) },
+                { "Tibetan", new LazyRange(0x0F00, 0x0FFF) },
+                { "Myanmar", new LazyRange(0x1000, 0x109F) },
+                { "Georgian", new LazyRange(0x10A0, 0x10FF) },
+                { "HangulJamo", new LazyRange(0x1100, 0x11FF) },
+                { "Ethiopic", new LazyRange(0x1200, 0x137F) },
+                { "EthiopicSupplement", new LazyRange(0x1380, 0x139F) },
+                { "Cherokee", new LazyRange(0x13A0, 0x13FF) },
+                { "UnifiedCanadianAboriginalSyllabics",
+                        new LazyRange(0x1400, 0x167F) },
+                { "Ogham", new LazyRange(0x1680, 0x169F) },
+                { "Runic", new LazyRange(0x16A0, 0x16FF) },
+                { "Tagalog", new LazyRange(0x1700, 0x171F) },
+                { "Hanunoo", new LazyRange(0x1720, 0x173F) },
+                { "Buhid", new LazyRange(0x1740, 0x175F) },
+                { "Tagbanwa", new LazyRange(0x1760, 0x177F) },
+                { "Khmer", new LazyRange(0x1780, 0x17FF) },
+                { "Mongolian", new LazyRange(0x1800, 0x18AF) },
+                { "Limbu", new LazyRange(0x1900, 0x194F) },
+                { "TaiLe", new LazyRange(0x1950, 0x197F) },
+                { "NewTaiLue", new LazyRange(0x1980, 0x19DF) },
+                { "KhmerSymbols", new LazyRange(0x19E0, 0x19FF) },
+                { "Buginese", new LazyRange(0x1A00, 0x1A1F) },
+                { "PhoneticExtensions", new LazyRange(0x1D00, 0x1D7F) },
+                { "PhoneticExtensionsSupplement", new LazyRange(0x1D80, 0x1DBF) },
+                { "CombiningDiacriticalMarksSupplement",
+                        new LazyRange(0x1DC0, 0x1DFF) },
+                { "LatinExtendedAdditional", new LazyRange(0x1E00, 0x1EFF) },
+                { "GreekExtended", new LazyRange(0x1F00, 0x1FFF) },
+                { "GeneralPunctuation", new LazyRange(0x2000, 0x206F) },
+                { "SuperscriptsandSubscripts", new LazyRange(0x2070, 0x209F) },
+                { "CurrencySymbols", new LazyRange(0x20A0, 0x20CF) },
+                { "CombiningMarksforSymbols", new LazyRange(0x20D0, 0x20FF) },
+                { "LetterlikeSymbols", new LazyRange(0x2100, 0x214F) },
+                { "NumberForms", new LazyRange(0x2150, 0x218F) },
+                { "Arrows", new LazyRange(0x2190, 0x21FF) },
+                { "MathematicalOperators", new LazyRange(0x2200, 0x22FF) },
+                { "MiscellaneousTechnical", new LazyRange(0x2300, 0x23FF) },
+                { "ControlPictures", new LazyRange(0x2400, 0x243F) },
+                { "OpticalCharacterRecognition", new LazyRange(0x2440, 0x245F) },
+                { "EnclosedAlphanumerics", new LazyRange(0x2460, 0x24FF) },
+                { "BoxDrawing", new LazyRange(0x2500, 0x257F) },
+                { "BlockElements", new LazyRange(0x2580, 0x259F) },
+                { "GeometricShapes", new LazyRange(0x25A0, 0x25FF) },
+                { "MiscellaneousSymbols", new LazyRange(0x2600, 0x26FF) },
+                { "Dingbats", new LazyRange(0x2700, 0x27BF) },
+                { "MiscellaneousMathematicalSymbols-A",
+                        new LazyRange(0x27C0, 0x27EF) },
+                { "SupplementalArrows-A", new LazyRange(0x27F0, 0x27FF) },
+                { "BraillePatterns", new LazyRange(0x2800, 0x28FF) },
+                { "SupplementalArrows-B", new LazyRange(0x2900, 0x297F) },
+                { "MiscellaneousMathematicalSymbols-B",
+                        new LazyRange(0x2980, 0x29FF) },
+                { "SupplementalMathematicalOperators",
+                        new LazyRange(0x2A00, 0x2AFF) },
+                { "MiscellaneousSymbolsandArrows",
+                        new LazyRange(0x2B00, 0x2BFF) },
+                { "Glagolitic", new LazyRange(0x2C00, 0x2C5F) },
+                { "Coptic", new LazyRange(0x2C80, 0x2CFF) },
+                { "GeorgianSupplement", new LazyRange(0x2D00, 0x2D2F) },
+                { "Tifinagh", new LazyRange(0x2D30, 0x2D7F) },
+                { "EthiopicExtended", new LazyRange(0x2D80, 0x2DDF) },
+                { "SupplementalPunctuation", new LazyRange(0x2E00, 0x2E7F) },
+                { "CJKRadicalsSupplement", new LazyRange(0x2E80, 0x2EFF) },
+                { "KangxiRadicals", new LazyRange(0x2F00, 0x2FDF) },
+                { "IdeographicDescriptionCharacters",
+                        new LazyRange(0x2FF0, 0x2FFF) },
+                { "CJKSymbolsandPunctuation", new LazyRange(0x3000, 0x303F) },
+                { "Hiragana", new LazyRange(0x3040, 0x309F) },
+                { "Katakana", new LazyRange(0x30A0, 0x30FF) },
+                { "Bopomofo", new LazyRange(0x3100, 0x312F) },
+                { "HangulCompatibilityJamo", new LazyRange(0x3130, 0x318F) },
+                { "Kanbun", new LazyRange(0x3190, 0x319F) },
+                { "BopomofoExtended", new LazyRange(0x31A0, 0x31BF) },
+                { "CJKStrokes", new LazyRange(0x31C0, 0x31EF) },
+                { "KatakanaPhoneticExtensions", new LazyRange(0x31F0, 0x31FF) },
+                { "EnclosedCJKLettersandMonths", new LazyRange(0x3200, 0x32FF) },
+                { "CJKCompatibility", new LazyRange(0x3300, 0x33FF) },
+                { "CJKUnifiedIdeographsExtensionA",
+                        new LazyRange(0x3400, 0x4DB5) },
+                { "YijingHexagramSymbols", new LazyRange(0x4DC0, 0x4DFF) },
+                { "CJKUnifiedIdeographs", new LazyRange(0x4E00, 0x9FFF) },
+                { "YiSyllables", new LazyRange(0xA000, 0xA48F) },
+                { "YiRadicals", new LazyRange(0xA490, 0xA4CF) },
+                { "ModifierToneLetters", new LazyRange(0xA700, 0xA71F) },
+                { "SylotiNagri", new LazyRange(0xA800, 0xA82F) },
+                { "HangulSyllables", new LazyRange(0xAC00, 0xD7A3) },
+                { "HighSurrogates", new LazyRange(0xD800, 0xDB7F) },
+                { "HighPrivateUseSurrogates", new LazyRange(0xDB80, 0xDBFF) },
+                { "LowSurrogates", new LazyRange(0xDC00, 0xDFFF) },
+                { "PrivateUseArea", new LazyRange(0xE000, 0xF8FF) },
+                { "CJKCompatibilityIdeographs", new LazyRange(0xF900, 0xFAFF) },
+                { "AlphabeticPresentationForms", new LazyRange(0xFB00, 0xFB4F) },
+                { "ArabicPresentationForms-A", new LazyRange(0xFB50, 0xFDFF) },
+                { "VariationSelectors", new LazyRange(0xFE00, 0xFE0F) },
+                { "VerticalForms", new LazyRange(0xFE10, 0xFE1F) },
+                { "CombiningHalfMarks", new LazyRange(0xFE20, 0xFE2F) },
+                { "CJKCompatibilityForms", new LazyRange(0xFE30, 0xFE4F) },
+                { "SmallFormVariants", new LazyRange(0xFE50, 0xFE6F) },
+                { "ArabicPresentationForms-B", new LazyRange(0xFE70, 0xFEFF) },
+                { "HalfwidthandFullwidthForms", new LazyRange(0xFF00, 0xFFEF) },
+                { "Specials", new LazySpecialsBlock() },
+                { "Cn", new LazyCategory(Character.UNASSIGNED) },
+                { "IsL", new LazyCategoryScope(0x3E) },
+                { "Lu", new LazyCategory(Character.UPPERCASE_LETTER) },
+                { "Ll", new LazyCategory(Character.LOWERCASE_LETTER) },
+                { "Lt", new LazyCategory(Character.TITLECASE_LETTER) },
+                { "Lm", new LazyCategory(Character.MODIFIER_LETTER) },
+                { "Lo", new LazyCategory(Character.OTHER_LETTER) },
+                { "IsM", new LazyCategoryScope(0x1C0) },
+                { "Mn", new LazyCategory(Character.NON_SPACING_MARK) },
+                { "Me", new LazyCategory(Character.ENCLOSING_MARK) },
+                { "Mc", new LazyCategory(Character.COMBINING_SPACING_MARK) },
+                { "N", new LazyCategoryScope(0xE00) },
+                { "Nd", new LazyCategory(Character.DECIMAL_DIGIT_NUMBER) },
+                { "Nl", new LazyCategory(Character.LETTER_NUMBER) },
+                { "No", new LazyCategory(Character.OTHER_NUMBER) },
+                { "IsZ", new LazyCategoryScope(0x7000) },
+                { "Zs", new LazyCategory(Character.SPACE_SEPARATOR) },
+                { "Zl", new LazyCategory(Character.LINE_SEPARATOR) },
+                { "Zp", new LazyCategory(Character.PARAGRAPH_SEPARATOR) },
+                { "IsC", new LazyCategoryScope(0xF0000) },
+                { "Cc", new LazyCategory(Character.CONTROL) },
+                { "Cf", new LazyCategory(Character.FORMAT) },
+                { "Co", new LazyCategory(Character.PRIVATE_USE) },
+                { "Cs", new LazyCategory(Character.SURROGATE) },
+                { "IsP", new LazyCategoryScope(0xF8000) },
+                { "Pd", new LazyCategory(Character.DASH_PUNCTUATION) },
+                { "Ps", new LazyCategory(Character.START_PUNCTUATION) },
+                { "Pe", new LazyCategory(Character.END_PUNCTUATION) },
+                { "Pc", new LazyCategory(Character.CONNECTOR_PUNCTUATION) },
+                { "Po", new LazyCategory(Character.OTHER_PUNCTUATION) },
+                { "IsS", new LazyCategoryScope(0x7E000000) },
+                { "Sm", new LazyCategory(Character.MATH_SYMBOL) },
+                { "Sc", new LazyCategory(Character.CURRENCY_SYMBOL) },
+                { "Sk", new LazyCategory(Character.MODIFIER_SYMBOL) },
+                { "So", new LazyCategory(Character.OTHER_SYMBOL) },
+                { "Pi", new LazyCategory(Character.INITIAL_QUOTE_PUNCTUATION) },
+                { "Pf", new LazyCategory(Character.FINAL_QUOTE_PUNCTUATION) } };
+
+        public Object[][] getContents() {
+            return contents;
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractLineTerminator.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractLineTerminator.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractLineTerminator.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractLineTerminator.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,68 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Line terminator factory
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+abstract class AbstractLineTerminator {
+    static AbstractLineTerminator unixLT = null;
+
+    static AbstractLineTerminator unicodeLT = null;
+
+    public abstract boolean isLineTerminator(int ch);
+
+    public abstract boolean isAfterLineTerminator(int ch1, int ch2);
+
+    public static AbstractLineTerminator getInstance(int flag) {
+        if ((flag & Pattern.UNIX_LINES) != 0) {
+            if (unixLT != null)
+                return unixLT;
+            unixLT = new AbstractLineTerminator() {
+                public boolean isLineTerminator(int ch) {
+                    return ch == '\n';
+                }
+
+                public boolean isAfterLineTerminator(int ch, int ch2) {
+                    return ch == '\n';
+                }
+            };
+            return unixLT;
+        } else {
+            if (unicodeLT != null)
+                return unicodeLT;
+            unicodeLT = new AbstractLineTerminator() {
+                public boolean isLineTerminator(int ch) {
+                    return (ch == '\n' || ch == '\r' || ch == '\u0085' || (ch | 1) == '\u2029');
+                }
+
+                public boolean isAfterLineTerminator(int ch, int ch2) {
+                    return (ch == '\n' || ch == '\u0085' || (ch | 1) == '\u2029')
+                            || (ch == '\r' && ch2 != '\n');
+                }
+            };
+            return unicodeLT;
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AbstractSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,196 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.12.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Basic class for nodes, representing given regular expression.
+ * Note: All the classes representing nodes has set prefix;
+ *    
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.12.2.2 $
+ */
+abstract class AbstractSet {
+    
+    public static final int TYPE_LEAF = 1 << 0;
+
+    public static final int TYPE_FSET = 1 << 1;
+
+    public static final int TYPE_QUANT = 1 << 3;
+
+    public static final int TYPE_DOTSET = 0x80000000 | '.';
+
+    /**
+     * Next node to visit
+     */
+    protected AbstractSet next;
+
+    /**
+     * Counter for debugging purposes, represent unique node index;
+     */
+    static int counter = 1;
+
+    protected String index = new Integer(AbstractSet.counter++).toString();
+
+    private int type = 0;
+
+    public AbstractSet() {
+    }
+
+    public AbstractSet(AbstractSet n) {
+        next = n;
+    }
+
+    /**
+     * Checks if this node matches in given position and requrcively call
+     * next node matches on positive self match. Returns positive integer if 
+     * entire match succeed, negative otherwise
+     * @param stringIndex - string index to start from;
+     * @param testString  - input string
+     * @param matchResult - MatchResult to sore result into
+     * @return -1 if match fails or n > 0;
+     */
+    public abstract int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult);
+
+    /**
+     * Attempts to apply pattern starting from this set/stringIndex; returns
+     * index this search was started from, if value is negative, this means that
+     * this search didn't succeed, additional information could be obtained via
+     * matchResult;
+     * 
+     * Note: this is default implementation for find method, it's based on 
+     * matches, subclasses do not have to override find method unless 
+     * more effective find method exists for a particular node type 
+     * (sequence, i.e. substring, for example). Same applies for find back 
+     * method.
+     * 
+     * @param stringIndex
+     *            starting index
+     * @param testString
+     *            string to search in
+     * @param matchResult
+     *            result of the match
+     * @return last searched index
+     */
+    public int find(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        int length = matchResult.getRightBound();
+        while (stringIndex <= length) {
+            if (matches(stringIndex, testString, matchResult) >= 0) {
+                return stringIndex;
+            } else {
+                stringIndex++;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * @param stringIndex -
+     *            an index, to finish search back (left limit)
+     * @param startSearch -
+     *            an index to start search from (right limit)
+     * @param testString -
+     *            test string;
+     * @param matchResult
+     *            match result
+     * @return an index to start back search next time if this search fails(new
+     *         left bound); if this search fails the value is negative;
+     */
+    public int findBack(int stringIndex, int startSearch,
+            CharSequence testString, MatchResultImpl matchResult) {
+        int shift;
+        while (startSearch >= stringIndex) {
+            if (matches(startSearch, testString, matchResult) >= 0) {
+                return startSearch;
+            } else {
+                startSearch--;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * Returns true, if this node has consumed any characters during 
+     * positive match attempt, for example node representing character always 
+     * consumes one character if it matches. If particular node matches 
+     * empty sting this method will return false;
+     * 
+     * @param matchResult
+     * @return
+     */
+    public abstract boolean hasConsumed(MatchResultImpl matchResult);
+
+    /**
+     * Returns name for the particular node type.
+     * Used for debugging purposes.
+     */
+    protected abstract String getName();
+
+    protected void setType(int type) {
+        this.type = type;
+    }
+
+    public int getType() {
+        return this.type;
+    }
+
+    protected String getQualifiedName() {
+        return "<" + index + ":" + getName() + ">";
+    }
+
+    public String toString() {
+        return getQualifiedName();
+    }
+
+    /**
+     * Returns the next.
+     */
+    public AbstractSet getNext() {
+        return next;
+    }
+
+    /**
+     * Sets next abstract set
+     * @param next
+     *            The next to set.
+     */
+    public void setNext(AbstractSet next) {
+        this.next = next;
+    }
+    
+    /**
+     * Returns true if the given node intersects with this one,
+     * false otherwise.
+     * This method is bieng used for quantifiers construction, 
+     * lets consider the following regular expression (a|b)*ccc.
+     * 
+     * (a|b) does not intersects with "ccc" and thus can be quantified 
+     * greedly (w/o kickbacks), like *+ instead of *.
+     * 
+     * @param set - usually previous node
+     * 
+     * @return true if the given node intersects with this one
+     */
+    public boolean first(AbstractSet set) {
+        return true;
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AheadFSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AheadFSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AheadFSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AheadFSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,43 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * LookAhead FSet, always returns true;
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+class AheadFSet extends FSet {
+  
+    public AheadFSet() {
+        super(-1);
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        return stringIndex;
+    }
+
+    protected String getName() {
+        return "AheadFSet";
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AltGroupQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AltGroupQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AltGroupQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AltGroupQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,55 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.9.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Represents "?" quantifier over composite sets.
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.9.2.2 $
+ */
+class AltGroupQuantifierSet extends GroupQuantifierSet {
+
+    public AltGroupQuantifierSet(AbstractSet innerSet, AbstractSet next,
+            int type) {
+        super(innerSet, next, type);
+
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+
+        if (!innerSet.hasConsumed(matchResult))
+            return next.matches(stringIndex, testString, matchResult);
+
+        int nextIndex = innerSet.matches(stringIndex, testString, matchResult);
+
+        if (nextIndex < 0) {
+            return next.matches(stringIndex, testString, matchResult);
+        } else {
+            return nextIndex;
+        }
+    }
+
+    public void setNext(AbstractSet next) {
+        super.setNext(next);
+        innerSet.setNext(next);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AltQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AltQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AltQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AltQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,51 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Represents "?" quantifier over leaf sets.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+class AltQuantifierSet extends LeafQuantifierSet {
+
+    public AltQuantifierSet(LeafSet innerSet, AbstractSet next, int type) {
+        super(innerSet, next, type);
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        int i = 0;
+        int shift = 0;
+
+        if ((shift = innerSet.matches(stringIndex, testString, matchResult)) >= 0) {
+            return shift;
+        } else {
+            return next.matches(stringIndex, testString, matchResult);
+        }
+    }
+
+    public void setNext(AbstractSet next) {
+        super.setNext(next);
+        innerSet.setNext(next);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AtomicFSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AtomicFSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AtomicFSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AtomicFSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,56 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+class AtomicFSet extends FSet {
+    
+    int index;
+
+    public AtomicFSet(int groupIndex) {
+        super(groupIndex);
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+
+        int gr = getGroupIndex();
+        matchResult.setConsumed(gr, stringIndex - matchResult.getConsumed(gr));
+        index = stringIndex;
+
+        return stringIndex;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    protected String getName() {
+        return "AtomicFSet";
+    }
+
+    public boolean hasConsumed(MatchResultImpl mr) {
+        return false;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AtomicJointSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AtomicJointSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AtomicJointSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/AtomicJointSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,73 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.4.2.2 $
+ */
+package java.util.regex;
+
+import java.util.ArrayList;
+
+/**
+ * This class represent atomic group (?>X), once X matches,
+ * this match become unchangable till the end of the match.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.4.2.2 $
+ */
+class AtomicJointSet extends NonCapJointSet {
+    
+    public AtomicJointSet(ArrayList children, FSet fSet) {
+        super(children, fSet);
+    }
+
+    /**
+     * Returns stringIndex+shift, the next position to match
+     */
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        int start = matchResult.getConsumed(groupIndex);
+        matchResult.setConsumed(groupIndex, stringIndex);
+
+        int size = children.size();
+        for (int i = 0; i < size; i++) {
+            AbstractSet e = (AbstractSet) children.get(i);
+            int shift = e.matches(stringIndex, testString, matchResult);
+            if (shift >= 0) {
+                // AtomicFset always returns true, but saves the index to run
+                // this next.match() from;
+                return next.matches(((AtomicFSet) fSet).getIndex(), testString,
+                        matchResult);
+            }
+        }
+
+        matchResult.setConsumed(groupIndex, start);
+        return -1;
+    }
+
+    public void setNext(AbstractSet next) {
+        this.next = next;
+    }
+
+    public AbstractSet getNext() {
+        return next;
+    }
+
+    protected String getName() {
+        return "NonCapJointSet";
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/BackReferenceSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/BackReferenceSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/BackReferenceSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/BackReferenceSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,109 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.11.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Back reference node, i.e. \1-9;
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.11.2.2 $
+ */
+class BackReferenceSet extends CIBackReferenceSet {
+
+    public BackReferenceSet(int groupIndex, int consCounter) {
+        super(groupIndex, consCounter);
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        String group = getString(matchResult);
+        if (group == null
+                || (stringIndex + group.length()) > matchResult.getRightBound())
+            return -1;
+        int shift = testString.toString().startsWith(group, stringIndex) ? group
+                .length()
+                : -1;
+
+        if (shift < 0) {
+            return -1;
+        }
+        matchResult.setConsumed(consCounter, shift);
+        return next.matches(stringIndex + shift, testString, matchResult);
+    }
+
+    public int find(int strIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        String group = getString(matchResult);
+        int strLength = matchResult.getLeftBound();
+
+        if (group == null || (strIndex + group.length()) > strLength)
+            return -1;
+
+        String testStr = testString.toString();
+
+        while (strIndex <= strLength) {
+            strIndex = testStr.indexOf(group, strIndex);
+
+            if (strIndex < 0)
+                return -1;
+            if (next
+                    .matches(strIndex + group.length(), testString, matchResult) >= 0) {
+                return strIndex;
+            }
+
+            strIndex++;
+        }
+
+        return -1;
+    }
+
+    public int findBack(int strIndex, int lastIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        String group = getString(matchResult);
+
+        if (group == null)
+            return -1;
+
+        String testStr = testString.toString();
+
+        while (lastIndex >= strIndex) {
+            lastIndex = testStr.lastIndexOf(group, lastIndex);
+
+            if (lastIndex < 0 || lastIndex < strIndex)
+                return -1;
+            if (next.matches(lastIndex + group.length(), testString,
+                    matchResult) >= 0) {
+                return lastIndex;
+            }
+
+            lastIndex--;
+        }
+        return -1;
+    }
+
+    public boolean first(AbstractSet set) {
+        return true;
+    }
+
+    public String getName() {
+        return "back reference: " + this.groupIndex;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/BehindFSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/BehindFSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/BehindFSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/BehindFSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,49 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.2.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * FSet for lookbehind constructs. Checks if string index saved by corresponding
+ * jointSet in "consumers" equals to current index and return current string
+ * index, return -1 otherwise.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.2.2.2 $
+ */
+class BehindFSet extends FSet {
+
+    public BehindFSet(int groupIndex) {
+        super(groupIndex);
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+
+        int gr = getGroupIndex();
+        int rightBound = matchResult.getConsumed(gr);
+        matchResult.setConsumed(gr, -1);
+        return (rightBound == stringIndex) ? stringIndex : -1;
+    }
+
+    protected String getName() {
+        return "BehindFSet";
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CIBackReferenceSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CIBackReferenceSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CIBackReferenceSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CIBackReferenceSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,94 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+package java.util.regex;
+
+
+/**
+ * Case Insensitive back reference node;
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+class CIBackReferenceSet extends JointSet {
+
+    protected int referencedGroup;
+
+    protected int consCounter;
+
+    /**
+     * @param substring
+     */
+    public CIBackReferenceSet(int groupIndex, int consCounter) {
+        this.referencedGroup = groupIndex;
+        this.consCounter = consCounter;
+    }
+
+    public int accepts(int strIndex, CharSequence testString) {
+        throw new PatternSyntaxException(I18n.getMessage("Internal error"), "",
+                0);
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        String group = getString(matchResult);
+
+        if (group == null
+                || (stringIndex + group.length()) > matchResult.getRightBound())
+            return -1;
+
+        for (int i = 0; i < group.length(); i++) {
+            if (group.charAt(i) != testString.charAt(stringIndex + i)
+                    && Pattern.getSupplement(group.charAt(i)) != testString
+                            .charAt(stringIndex + i)) {
+                return -1;
+            }
+        }
+        matchResult.setConsumed(consCounter, group.length());
+        return next.matches(stringIndex + group.length(), testString,
+                matchResult);
+    }
+
+    public AbstractSet getNext() {
+        return this.next;
+    }
+
+    public void setNext(AbstractSet next) {
+        this.next = next;
+    }
+
+    protected String getString(MatchResultImpl matchResult) {
+        String res = matchResult.getGroupNoCheck(referencedGroup);
+        return res;
+        // return (res != null) ? res : "";
+    }
+
+    public String getName() {
+        return "CI back reference: " + this.groupIndex;
+    }
+
+    public boolean hasConsumed(MatchResultImpl matchResult) {
+        int cons;
+        boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0);
+        matchResult.setConsumed(consCounter, -1);
+        return res;
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CICharSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CICharSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CICharSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CICharSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,53 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Represents node accepting single character in 
+ * case insensitive manner.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+class CICharSet extends LeafSet {
+    
+    private char ch;
+
+    private char supplement;
+
+    public CICharSet(char ch) {
+        this.ch = ch;
+        this.supplement = Pattern.getSupplement(ch);
+    }
+
+    public int accepts(int strIndex, CharSequence testString) {
+        return (this.ch == testString.charAt(strIndex) 
+        		|| this.supplement == testString.charAt(strIndex)) ? 1 : -1;
+    }
+
+    protected String getName() {
+        return "CI " + ch;
+    }
+
+    protected char getChar() {
+        return ch;
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CISequenceSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CISequenceSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CISequenceSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CISequenceSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,57 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.6.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * This class represents ASCII case insensitive character sequences.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.6.2.2 $
+ */
+class CISequenceSet extends LeafSet {
+	
+    private String string = null;
+
+	/**
+	 * Constructs this sequence set 
+	 */
+	CISequenceSet(StringBuffer substring) {
+		this.string = substring.toString();
+		this.charCount = substring.length();
+	}
+
+	public int accepts(int strIndex, CharSequence testString) {
+		for (int i = 0; i < string.length(); i++) {
+			if (string.charAt(i) != testString.charAt(strIndex + i)
+					&& Pattern.getSupplement(string.charAt(i)) != testString
+							.charAt(strIndex + i)) {
+				return -1;
+			}
+		}
+
+		return string.length();
+
+	}
+
+	public String getName() {
+		return "CI sequence: " + string;
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CharClass.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CharClass.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CharClass.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CharClass.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,291 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.11.2.2 $
+ */
+package java.util.regex;
+
+import java.util.BitSet;
+
+/**
+ * User defined character classes ([abef]). See AbstractCharClass
+ * documentation for more details.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.11.2.2 $
+ */
+class CharClass extends AbstractCharClass {
+
+    // Flag indicates if we add supplement upper/lower case
+    boolean ci = false;
+
+    boolean uci = false;
+
+    // Flag indicates if there are unicode supplements
+    boolean hasUCI = false;
+
+    boolean inverted = false;
+
+    boolean hideBits = false;
+
+    BitSet bits = new BitSet();
+
+    AbstractCharClass nonBitSet = null;
+
+    public CharClass() {
+    }
+
+    public CharClass(boolean ci, boolean uci) {
+        this.ci = ci;
+        this.uci = uci;
+    }
+
+    public CharClass(boolean negative, boolean ci, boolean uci) {
+        this(ci, uci);
+        setNegative(negative);
+    }
+
+    public CharClass add(int ch) {
+        if (ci) {
+            if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
+                if (!inverted) {
+                    bits.set(Pattern.getSupplement((char) ch));
+                } else {
+                    bits.clear(Pattern.getSupplement((char) ch));
+                }
+            } else if (uci && ch > 128) {
+                hasUCI = true;
+                ch = Character.toLowerCase(Character.toUpperCase((char) ch));
+                // return this;
+            }
+        }
+        if (!inverted) {
+            bits.set(ch);
+        } else
+            bits.clear();
+
+        return this;
+    }
+
+    public CharClass add(final AbstractCharClass cc) {
+        if (cc.getBits() != null) {
+            if (!inverted) {
+                if (cc.isNegative()) {
+                    bits.xor(cc.getBits());
+                    bits.and(cc.getBits());
+                    alt = !alt;
+                    inverted = true;
+                } else {
+                    bits.or(cc.getBits());
+                }
+            } else {
+                if (cc.isNegative()) {
+                    bits.and(cc.getBits());
+                } else {
+                    bits.andNot(cc.getBits());
+                }
+            }
+        } else {
+            if (nonBitSet == null) {
+                // hide bits true at the moment
+                nonBitSet = new AbstractCharClass() {
+                    public boolean contains(int ch) {
+                        return cc.contains(ch) || bits.get(ch);
+                    }
+                };
+                hideBits = true;
+            } else {
+                final AbstractCharClass nb = nonBitSet;
+                nonBitSet = new AbstractCharClass() {
+                    public boolean contains(int ch) {
+                        return nb.contains(ch) || cc.contains(ch);
+                    }
+                };
+            }
+        }
+
+        return this;
+    }
+
+    public CharClass add(int st, int end) {
+        if (st > end)
+            throw new IllegalArgumentException();
+        if (!ci) {
+            if (!inverted) {
+                bits.set(st, end + 1);
+            } else {
+                bits.clear(st, end + 1);
+            }
+        } else {
+            for (int i = st; i < end + 1; i++) {
+                add(i);
+            }
+        }
+        return this;
+    }
+
+    // OR operation
+    public void union(final AbstractCharClass clazz) {
+        if (clazz.hasUCI())
+            this.hasUCI = true;
+        if (!hideBits && clazz.getBits() != null) {
+            if (alt ^ clazz.isNegative()) {
+                if (alt) {
+                    bits.andNot(clazz.getBits());
+                } else {
+                    bits.xor(clazz.getBits());
+                    bits.and(clazz.getBits());
+                }
+                alt = true;
+            } else {
+                if (alt) {
+                    bits.and(clazz.getBits());
+                } else {
+                    bits.or(clazz.getBits());
+                }
+            }
+        } else {
+            if (nonBitSet == null) {
+                nonBitSet = new AbstractCharClass() {
+                    public boolean contains(int ch) {
+                        return clazz.contains(ch) || bits.get(ch);
+                    }
+                };
+                hideBits = true;
+            } else {
+                final AbstractCharClass nb = nonBitSet;
+                nonBitSet = new AbstractCharClass() {
+                    public boolean contains(int ch) {
+                        return nb.contains(ch) || clazz.contains(ch);
+                    }
+                };
+            }
+        }
+    }
+
+    // AND operation
+    public void intersection(final AbstractCharClass clazz) {
+        if (clazz.hasUCI())
+            this.hasUCI = true;
+        if (!hideBits && clazz.getBits() != null) {
+            if (alt ^ clazz.isNegative()) {
+                if (alt) {
+                    bits.xor(clazz.getBits());
+                    bits.and(clazz.getBits());
+                    setNegative(false);
+                } else {
+                    bits.andNot(clazz.getBits());
+                }
+            } else {
+                if (alt) {
+                    bits.or(clazz.getBits());
+                } else {
+                    bits.and(clazz.getBits());
+                }
+            }
+        } else {
+            if (nonBitSet == null) {
+                nonBitSet = new AbstractCharClass() {
+                    public boolean contains(int ch) {
+                        return bits.get(ch) && clazz.contains(ch);
+                    }
+                };
+                hideBits = true;
+            } else {
+                final AbstractCharClass nb = nonBitSet;
+                nonBitSet = new AbstractCharClass() {
+                    public boolean contains(int ch) {
+                        return nb.contains(ch) && clazz.contains(ch);
+                    }
+                };
+            }
+        }
+    }
+
+    /**
+     * Returns <code>true</code> if character class contains symbol specified,
+     * <code>false</code> otherwise. Note: #setNegative() method changes the
+     * meaning of contains method;
+     * 
+     * @param ch
+     * @return <code>true</code> if character class contains symbol specified;
+     * 
+     * TODO: currently <code>character class</code> implementation based on
+     * BitSet, but this implementation possibly will be turned to combined
+     * BitSet(for first 256 symbols) and Black/Red tree for the rest of UTF.
+     */
+    public boolean contains(int ch) {
+        if (nonBitSet == null) {
+            return this.alt ^ bits.get(ch);
+        } else {
+            return alt ^ nonBitSet.contains(ch);
+        }
+    }
+
+    protected BitSet getBits() {
+        if (hideBits)
+            return null;
+        return bits;
+    }
+
+    public AbstractCharClass getInstance() {
+        if (nonBitSet == null) {
+            final BitSet bs = getBits();
+            AbstractCharClass res = new AbstractCharClass() {
+                public boolean contains(int ch) {
+                    return this.alt ^ bs.get(ch);
+                }
+
+                public String toString() {
+                    StringBuffer temp = new StringBuffer();
+                    for (int i = bs.nextSetBit(0); i >= 0; i = bs
+                            .nextSetBit(i + 1)) {
+                        temp.append((char) i);
+                        temp.append('|');
+                    }
+
+                    if (temp.length() > 0)
+                        temp.deleteCharAt(temp.length() - 1);
+
+                    return temp.toString();
+                }
+
+            };
+            return res.setNegative(isNegative());
+        } else {
+            return this;
+        }
+    }
+
+    public String toString() {
+        StringBuffer temp = new StringBuffer();
+        for (int i = bits.nextSetBit(0); i >= 0; i = bits.nextSetBit(i + 1)) {
+            temp.append((char) i);
+            temp.append('|');
+        }
+
+        if (temp.length() > 0)
+            temp.deleteCharAt(temp.length() - 1);
+
+        return temp.toString();
+    }
+
+    public boolean hasUCI() {
+        return hasUCI;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CharSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CharSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CharSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CharSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,101 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.12.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Represents node accepting single character.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.12.2.2 $
+ */
+class CharSet extends LeafSet {
+
+    private char ch = 0;
+
+    public CharSet(char ch) {
+        this.ch = ch;
+    }
+
+    public int charCount() {
+        return 1;
+    }
+
+    public int accepts(int strIndex, CharSequence testString) {
+        return (this.ch == testString.charAt(strIndex)) ? 1 : -1;
+    }
+
+    public int find(int strIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        boolean res = false;
+        String testStr = testString.toString();
+        int strLength = matchResult.getRightBound();
+
+        while (strIndex < strLength) {
+            strIndex = testStr.indexOf(ch, strIndex);
+            if (strIndex < 0)
+                return -1;
+            if (next.matches(strIndex + 1, testString, matchResult) >= 0) {
+                return strIndex;
+            }
+            strIndex++;
+        }
+
+        return -1;
+    }
+
+    public int findBack(int strIndex, int lastIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        String testStr = testString.toString();
+
+        while (lastIndex >= strIndex) {
+            lastIndex = testStr.lastIndexOf(ch, lastIndex);
+            if (lastIndex < 0 || lastIndex < strIndex) {
+                return -1;
+            }
+
+            if (next.matches(lastIndex + 1, testString, matchResult) >= 0) {
+                return lastIndex;
+            }
+
+            lastIndex--;
+        }
+
+        return -1;
+    }
+
+    protected String getName() {
+        return "" + ch;
+    }
+
+    protected char getChar() {
+        return ch;
+    }
+
+    public boolean first(AbstractSet set) {
+        if (set instanceof CharSet) {
+            return ((CharSet) set).getChar() == ch;
+        } else if (set instanceof RangeSet) {
+            return ((RangeSet) set).accepts(0, Character.toString(ch)) > 0;
+        }
+
+        return true;
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CompositeGroupQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CompositeGroupQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CompositeGroupQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CompositeGroupQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,89 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.10.2.3 $
+ */
+package java.util.regex;
+
+/**
+ * Composite (i.e. {n,m}) quantifier node for groups ("(X){n,m}")
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.10.2.3 $
+ */
+class CompositeGroupQuantifierSet extends GroupQuantifierSet {
+    
+    protected Quantifier quantifier = null;
+
+    int setCounter;
+
+    /**
+     * Constructs CompositeGroupQuantifierSet
+     * @param quant    - given composite quantifier
+     * @param innerSet - given group
+     * @param next     - next set after the quantifier
+     */
+    public CompositeGroupQuantifierSet(Quantifier quant, AbstractSet innerSet,
+            AbstractSet next, int type, int setCounter) {
+        super(innerSet, next, type);
+        this.quantifier = quant;
+        this.setCounter = setCounter;
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        int enterCounter = matchResult.getEnterCounter(setCounter);
+
+        if (!innerSet.hasConsumed(matchResult))
+            return next.matches(stringIndex, testString, matchResult);
+
+        // can't go inner set;
+        if (enterCounter >= quantifier.max()) {
+            return next.matches(stringIndex, testString, matchResult);
+        }
+
+        // go inner set;
+        matchResult.setEnterCounter(setCounter, ++enterCounter);
+        int nextIndex = innerSet.matches(stringIndex, testString, matchResult);
+
+        if (nextIndex < 0) {
+            matchResult.setEnterCounter(setCounter, --enterCounter);
+            if (enterCounter >= quantifier.min()) {
+                return next.matches(stringIndex, testString, matchResult);
+            } else {
+                matchResult.setEnterCounter(setCounter, 0);
+                return -1;
+            }
+        } else {
+            matchResult.setEnterCounter(setCounter, 0);
+            return nextIndex;
+        }
+    }
+
+    public void reset() {
+        quantifier.resetCounter();
+    }
+
+    protected String getName() {
+        return quantifier.toString();
+    }
+
+    void setQuantifier(Quantifier quant) {
+        this.quantifier = quant;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CompositeQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CompositeQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CompositeQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/CompositeQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,90 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Composite (i.e. {n,m}) quantifier node over the leaf nodes ("a{n,m}")
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+class CompositeQuantifierSet extends LeafQuantifierSet {
+    
+    protected Quantifier quantifier = null;
+
+    public CompositeQuantifierSet(Quantifier quant, LeafSet innerSet,
+            AbstractSet next, int type) {
+        super(innerSet, next, type);
+        this.quantifier = quant;
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        int min = quantifier.min();
+        int max = quantifier.max();
+        int i = 0;
+
+        for (; i < min; i++) {
+
+            if (stringIndex + leaf.charCount() > matchResult.getRightBound()) {
+                matchResult.hitEnd = true;
+                return -1;
+            }
+
+            int shift = leaf.accepts(stringIndex, testString);
+            if (shift < 1) {
+                return -1;
+            }
+            stringIndex += shift;
+        }
+
+        for (; i < max; i++) {
+            int shift;
+            if (stringIndex + leaf.charCount() > matchResult.getRightBound()
+                    || (shift = leaf.accepts(stringIndex, testString)) < 1) {
+                break;
+            }
+            stringIndex += shift;
+        }
+
+        for (; i >= min; i--) {
+            int shift = next.matches(stringIndex, testString, matchResult);
+            if (shift >= 0) {
+                return shift;
+            }
+            stringIndex--;
+        }
+        return -1;
+
+    }
+
+    public void reset() {
+        quantifier.resetCounter();
+    }
+
+    protected String getName() {
+        return quantifier.toString();
+    }
+
+    void setQuantifier(Quantifier quant) {
+        this.quantifier = quant;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotAllQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotAllQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotAllQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotAllQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,56 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Special node for ".*" construction for any character 
+ * including line terminators.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+class DotAllQuantifierSet extends LeafQuantifierSet {
+
+    public DotAllQuantifierSet(LeafSet innerSet, AbstractSet next, int type) {
+        super(innerSet, next, type);
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+
+        int strLength = testString.length();
+
+        if (strLength <= stringIndex) {
+            return next.matches(stringIndex, testString, matchResult);
+        }
+        return next.findBack(stringIndex, strLength, testString, matchResult);
+    }
+
+    public int find(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        int strLength = testString.length();
+        if (next.findBack(stringIndex, strLength, testString, matchResult) >= 0) {
+            return stringIndex;
+        } else {
+            return -1;
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotAllSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotAllSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotAllSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotAllSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,42 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.6.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Node accepting any character including line terminators.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.6.2.2 $
+ */
+class DotAllSet extends LeafSet {
+
+    public int accepts(int strIndex, CharSequence testString) {
+        return (strIndex < testString.length()) ? 1 : -1;
+    }
+
+    protected String getName() {
+        return "DotAll";
+    }
+
+    public int getType() {
+        return AbstractSet.TYPE_DOTSET;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/DotQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,117 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.11.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Special node for ".*" construction.
+ * The main idea here is to find line terminator and try to find the rest of
+ * the construction from this point.
+ * 
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.11.2.2 $
+ */
+class DotQuantifierSet extends LeafQuantifierSet {
+    
+    AbstractLineTerminator lt;
+
+    public DotQuantifierSet(LeafSet innerSet, AbstractSet next, int type,
+            AbstractLineTerminator lt) {
+        super(innerSet, next, type);
+        this.lt = lt;
+    }
+
+    public int matches(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+
+        int strLength = matchResult.getRightBound();
+
+        int startSearch = /* testString.toString().indexOf('\n', stringIndex); */
+        findLineTerminator(stringIndex, strLength, testString);
+
+        if (startSearch < 0) {
+            startSearch = testString.length();
+        }
+
+        if (startSearch <= stringIndex) {
+            return next.matches(stringIndex, testString, matchResult);
+        }
+        return next.findBack(stringIndex, startSearch, testString, matchResult);
+    }
+
+    public int find(int stringIndex, CharSequence testString,
+            MatchResultImpl matchResult) {
+        // String testStr = testString.toString();
+        int strLength = matchResult.getRightBound();
+        // 1. skip line terminators ???
+        // //
+        // we don't skip line terminators here, but return zero match instead
+        // //
+
+        // 2. find first occurance of the searched pattern
+        // //
+        int res = next.find(stringIndex, testString, matchResult);
+
+        // 3. Check if we have other occurances till the end of line
+        // (because .* is greedy and we need last one)
+        // //
+        if (res >= 0) {
+            int nextSearch = findLineTerminator(res, strLength, testString);
+            // testStr.indexOf('\n', res);
+            if (nextSearch < 0) {
+                nextSearch = strLength;
+            }
+            nextSearch = next
+                    .findBack(res, nextSearch, testString, matchResult);
+            res = (res < nextSearch) ? nextSearch : res;
+        } else {
+            return -1;
+        }
+
+        // 4. find left boundary of this search
+        // //
+        int leftBound = (res > 0) ? findBackLineTerminator(stringIndex,
+                res - 1, testString)/* testStr.lastIndexOf('\n', res - 1) */
+                : (res == 0) ? 0 : -1;
+        res = (leftBound >= stringIndex) ? ((leftBound < res) ? leftBound + 1
+                : leftBound) : stringIndex;
+
+        return res;
+    }
+
+    private int findLineTerminator(int from, int to, CharSequence testString) {
+        for (int i = from; i < to; i++) {
+            if (lt.isLineTerminator(testString.charAt(i))) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    private int findBackLineTerminator(int from, int to, CharSequence testString) {
+        for (int i = to; i >= from; i--) {
+            if (lt.isLineTerminator(testString.charAt(i))) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+}



Mime
View raw message