Beispiel #1
0
        public override int Matches(int strIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int rightBound = (matchResult.HasAnchoringBounds()) ? matchResult
                             .GetRightBound() : testString.Length;

            if (strIndex >= rightBound)
            {
                matchResult.SetConsumed(consCounter, 0);
                return(next.Matches(strIndex, testString, matchResult));
            }

            // check final line terminator;
            if ((rightBound - strIndex) == 2 && testString[strIndex] == '\r' &&
                testString[strIndex + 1] == '\n')
            {
                matchResult.SetConsumed(consCounter, 0);
                return(next.Matches(strIndex, testString, matchResult));
            }
            char ch;

            if ((rightBound - strIndex) == 1 &&
                (((ch = testString[strIndex]) == '\n' || ch == '\r' ||
                  ch == '\u0085' || (ch | 1) == '\u2029')))
            {
                matchResult.SetConsumed(consCounter, 0);
                return(next.Matches(strIndex, testString, matchResult));
            }

            return(-1);
        }
Beispiel #2
0
        /// <summary>
        /// Returns stringIndex+shift, the next position to match
        /// </summary>
        ///
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int size      = children.Count;
            int leftBound = (matchResult.HasTransparentBounds()) ? 0 : matchResult
                            .GetLeftBound();

            int shift = next.Matches(stringIndex, testString, matchResult);

            if (shift >= 0)
            {
                //fSet will take this index to check if we at the right bound
                // and return true if the current index equal to this one
                matchResult.SetConsumed(groupIndex, stringIndex);
                for (int i = 0; i < size; i++)
                {
                    AbstractSet e = (AbstractSet)children[i];
                    // find limits could be calculated though e.getCharCount()
                    // fSet will return true only if string index at fSet equal
                    // to stringIndex
                    if (e.FindBack(leftBound, stringIndex, testString, matchResult) >= 0)
                    {
                        matchResult.SetConsumed(groupIndex, -1);
                        return(shift);
                    }
                }
            }

            return(-1);
        }
        /// <summary>
        /// Returns stringIndex+shift, the next position to match
        /// </summary>
        ///
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int start = matchResult.GetConsumed(groupIndex);

            matchResult.SetConsumed(groupIndex, stringIndex);

            int size = children.Count;

            for (int i = 0; i < size; i++)
            {
                AbstractSet e     = (AbstractSet)children[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);
        }
Beispiel #4
0
        public override int Matches(int strIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int strDif = (matchResult.HasAnchoringBounds()) ? matchResult
                         .GetLeftBound() - strIndex : testString.Length - strIndex;
            char ch1;
            char ch2;

            if (strDif == 0)
            {
                matchResult.SetConsumed(consCounter, 0);
                return(next.Matches(strIndex, testString, matchResult));
            }
            else if (strDif >= 2)
            {
                ch1 = testString[strIndex];
                ch2 = testString[strIndex + 1];
            }
            else
            {
                ch1 = testString[strIndex];
                ch2 = 'a';
            }

            switch ((int)ch1)
            {
            case '\r': {
                if (ch2 == '\n')
                {
                    matchResult.SetConsumed(consCounter, 0);
                    return(next.Matches(strIndex, testString, matchResult));
                }
                matchResult.SetConsumed(consCounter, 0);
                return(next.Matches(strIndex, testString, matchResult));
            }

            case '\n':
            case '\u0085':
            case '\u2028':
            case '\u2029': {
                matchResult.SetConsumed(consCounter, 0);
                return(next.Matches(strIndex, testString, matchResult));
            }

            default:
                return(-1);
            }
        }
        public override bool HasConsumed(MatchResultImpl matchResult)
        {
            int  cons;
            bool res = ((cons = matchResult.GetConsumed(consCounter)) < 0 || cons > 0);

            matchResult.SetConsumed(consCounter, -1);
            return(res);
        }
        public override int Matches(int strIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int strDif = (matchResult.HasAnchoringBounds()) ? matchResult
                         .GetRightBound() - strIndex : testString.Length - strIndex;

            if (strDif <= 0)
            {
                matchResult.SetConsumed(consCounter, 0);
                return(next.Matches(strIndex, testString, matchResult));
            }
            else if (testString[strIndex] == '\n')
            {
                matchResult.SetConsumed(consCounter, 1);
                return(next.Matches(strIndex + 1, testString, matchResult));
            }
            return(-1);
        }
Beispiel #7
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int gr = GetGroupIndex();

            matchResult.SetConsumed(gr, stringIndex - matchResult.GetConsumed(gr));

            return(next.Matches(stringIndex, testString, matchResult));
        }
Beispiel #8
0
        /// <summary>
        /// Returns stringIndex+shift, the next position to match
        /// </summary>
        ///
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int start = matchResult.GetConsumed(groupIndex);

            matchResult.SetConsumed(groupIndex, stringIndex);

            int size = children.Count;

            for (int i = 0; i < size; i++)
            {
                AbstractSet e     = (AbstractSet)children[i];
                int         shift = e.Matches(stringIndex, testString, matchResult);
                if (shift >= 0)
                {
                    return(shift);
                }
            }
            matchResult.SetConsumed(groupIndex, start);
            return(-1);
        }
		public override int Matches(int stringIndex, String testString,
				MatchResultImpl matchResult) {
			String group = GetString(matchResult);
			if (group == null
					|| (stringIndex + group.Length) > matchResult.GetRightBound())
				return -1;
			int shift = (ILOG.J2CsMapping.Util.StringUtil.StartsWith(testString.ToString(),group,stringIndex)) ? group.Length : -1;
	
			if (shift < 0) {
				return -1;
			}
			matchResult.SetConsumed(consCounter, shift);
			return next.Matches(stringIndex + shift, testString, matchResult);
		}
        public override int Matches(int stringIndex, String 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 (Char.ToLower(Char.ToUpper(group[i])) != Char.ToLower(Char.ToUpper(testString[stringIndex + i])))
                {
                    return(-1);
                }
            }
            matchResult.SetConsumed(consCounter, group.Length);
            return(next.Matches(stringIndex + group.Length, testString,
                                matchResult));
        }
        public override int Matches(int stringIndex, String 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[i] != testString[stringIndex + i] &&
                    Pattern.GetSupplement(group[i]) != testString[stringIndex + i])
                {
                    return(-1);
                }
            }
            matchResult.SetConsumed(consCounter, group.Length);
            return(next.Matches(stringIndex + group.Length, testString,
                                matchResult));
        }