Пример #1
0
        // AND operation
        public void Intersection(AbstractCharClass clazz_0)
        {
            if (!mayContainSupplCodepoints && clazz_0.mayContainSupplCodepoints)
            {
                mayContainSupplCodepoints = true;
            }

            if (clazz_0.HasUCI())
            {
                this.hasUCI = true;
            }

            if (altSurrogates ^ clazz_0.altSurrogates)
            {
                //!A & B = ((A ^ B) & B)
                if (altSurrogates)
                {
                    lowHighSurrogates.Xor(clazz_0.GetLowHighSurrogates());
                    lowHighSurrogates.And(clazz_0.GetLowHighSurrogates());
                    altSurrogates = false;

                    //A & !B
                }
                else
                {
                    lowHighSurrogates.AndNot(clazz_0.GetLowHighSurrogates());
                }
            }
            else
            {
                //!A & !B = !(A | B)
                if (altSurrogates)
                {
                    lowHighSurrogates.Or(clazz_0.GetLowHighSurrogates());

                    //A & B
                }
                else
                {
                    lowHighSurrogates.And(clazz_0.GetLowHighSurrogates());
                }
            }

            if (!hideBits && clazz_0.GetBits() != null)
            {
                if (alt ^ clazz_0.IsNegative())
                {
                    //!A & B = ((A ^ B) & B)
                    if (alt)
                    {
                        bits.Xor(clazz_0.GetBits());
                        bits.And(clazz_0.GetBits());
                        alt = false;

                        //A & !B
                    }
                    else
                    {
                        bits.AndNot(clazz_0.GetBits());
                    }
                }
                else
                {
                    //!A & !B = !(A | B)
                    if (alt)
                    {
                        bits.Or(clazz_0.GetBits());

                        //A & B
                    }
                    else
                    {
                        bits.And(clazz_0.GetBits());
                    }
                }
            }
            else
            {
                bool curAlt_1 = alt;

                if (nonBitSet == null)
                {
                    if (!inverted && bits.IsEmpty())
                    {
                        if (curAlt_1)
                        {
                            nonBitSet = new CharClass.Anonymous_C6(clazz_0);
                            //alt = true
                        }
                        else
                        {
                            nonBitSet = new CharClass.Anonymous_C5(clazz_0);
                            //alt = false
                        }
                    }
                    else
                    {
                        if (curAlt_1)
                        {
                            nonBitSet = new CharClass.Anonymous_C4(this, curAlt_1, clazz_0);
                            //alt = true
                        }
                        else
                        {
                            nonBitSet = new CharClass.Anonymous_C3(this, clazz_0, curAlt_1);
                            //alt = false
                        }
                    }
                    hideBits = true;
                }
                else
                {
                    AbstractCharClass nb_2 = nonBitSet;

                    if (curAlt_1)
                    {
                        nonBitSet = new CharClass.Anonymous_C2(curAlt_1, nb_2, clazz_0);
                        //alt = true
                    }
                    else
                    {
                        nonBitSet = new CharClass.Anonymous_C1(curAlt_1, nb_2, clazz_0);
                        //alt = false
                    }
                }
            }
        }
Пример #2
0
        /*
         * The difference between add(AbstractCharClass) and union(AbstractCharClass)
         * is that add() is used for constructions like "[^abc\\d]"
         * (this pattern doesn't match "1")
         * while union is used for constructions like "[^abc[\\d]]"
         * (this pattern matches "1").
         */
        public CharClass Add(AbstractCharClass cc_0)
        {
            if (!mayContainSupplCodepoints && cc_0.mayContainSupplCodepoints)
            {
                mayContainSupplCodepoints = true;
            }

            if (!invertedSurrogates)
            {
                //A | !B = ! ((A ^ B) & B)
                if (cc_0.altSurrogates)
                {
                    lowHighSurrogates.Xor(cc_0.GetLowHighSurrogates());
                    lowHighSurrogates.And(cc_0.GetLowHighSurrogates());
                    altSurrogates      = !altSurrogates;
                    invertedSurrogates = true;

                    //A | B
                }
                else
                {
                    lowHighSurrogates.Or(cc_0.GetLowHighSurrogates());
                }
            }
            else
            {
                //!A | !B = !(A & B)
                if (cc_0.altSurrogates)
                {
                    lowHighSurrogates.And(cc_0.GetLowHighSurrogates());

                    //!A | B = !(A & !B)
                }
                else
                {
                    lowHighSurrogates.AndNot(cc_0.GetLowHighSurrogates());
                }
            }

            if (!hideBits && cc_0.GetBits() != null)
            {
                if (!inverted)
                {
                    //A | !B = ! ((A ^ B) & B)
                    if (cc_0.IsNegative())
                    {
                        bits.Xor(cc_0.GetBits());
                        bits.And(cc_0.GetBits());
                        alt      = !alt;
                        inverted = true;

                        //A | B
                    }
                    else
                    {
                        bits.Or(cc_0.GetBits());
                    }
                }
                else
                {
                    //!A | !B = !(A & B)
                    if (cc_0.IsNegative())
                    {
                        bits.And(cc_0.GetBits());

                        //!A | B = !(A & !B)
                    }
                    else
                    {
                        bits.AndNot(cc_0.GetBits());
                    }
                }
            }
            else
            {
                bool curAlt_1 = alt;

                if (nonBitSet == null)
                {
                    if (curAlt_1 && !inverted && bits.IsEmpty())
                    {
                        nonBitSet = new CharClass.Anonymous_C17(cc_0);
                        //alt = true;
                    }
                    else
                    {
                        /*
                         * We keep the value of alt unchanged for
                         * constructions like [^[abc]fgb] by using
                         * the formula a ^ b == !a ^ !b.
                         */
                        if (curAlt_1)
                        {
                            nonBitSet = new CharClass.Anonymous_C16(this, curAlt_1, cc_0);
                            //alt = true
                        }
                        else
                        {
                            nonBitSet = new CharClass.Anonymous_C15(this, curAlt_1, cc_0);
                            //alt = false
                        }
                    }

                    hideBits = true;
                }
                else
                {
                    AbstractCharClass nb_2 = nonBitSet;

                    if (curAlt_1)
                    {
                        nonBitSet = new CharClass.Anonymous_C14(curAlt_1, cc_0, nb_2);
                        //alt = true
                    }
                    else
                    {
                        nonBitSet = new CharClass.Anonymous_C13(curAlt_1, cc_0, nb_2);
                        //alt = false
                    }
                }
            }

            return(this);
        }