public override int Matches(int stringIndex, String 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_0;
                if (stringIndex + leaf.CharCount() > matchResult.GetRightBound() ||
                    (shift_0 = leaf.Accepts(stringIndex, testString)) < 1)
                {
                    break;
                }
                stringIndex += shift_0;
            }

            for (; i >= min; i--)
            {
                int shift_1 = next.Matches(stringIndex, testString, matchResult);
                if (shift_1 >= 0)
                {
                    return(shift_1);
                }
                stringIndex -= leaf.CharCount();
            }
            return(-1);
        }
Exemple #2
0
        public override int Matches(int stringIndex, String 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);
            }
        }