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;
            }
            return(next.Matches(stringIndex, testString, matchResult));
        }
Esempio n. 2
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int strLength = matchResult.GetRightBound();
            int offset    = -1;

            if (stringIndex < strLength)
            {
                char high = testString[stringIndex++];

                if (Contains(high) &&
                    (offset = next.Matches(stringIndex, testString,
                                           matchResult)) > 0)
                {
                    return(offset);
                }

                if (stringIndex < strLength)
                {
                    char low = testString[stringIndex++];

                    if (System.Char.IsSurrogatePair(high, low) &&
                        Contains(Character.ToCodePoint(high, low)))
                    {
                        return(next.Matches(stringIndex, testString, matchResult));
                    }
                }
            }

            return(-1);
        }
Esempio n. 3
0
        public override int Find(int stringIndex, String testString,
                                 MatchResultImpl matchResult)
        {
            int res         = 0;
            int lastIndex   = matchResult.GetRightBound();
            int startSearch = stringIndex;

            for (; startSearch <= lastIndex; startSearch++)
            {
                int saveStart = matchResult.GetStart(groupIndex);

                matchResult.SetStart(groupIndex, startSearch);
                res = kid.Matches(startSearch, testString, matchResult);
                if (res >= 0)
                {
                    res = startSearch;
                    break;
                }
                else
                {
                    matchResult.SetStart(groupIndex, saveStart);
                }
            }

            return(res);
        }
Esempio n. 4
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);
        }
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            if (stringIndex + 1 > matchResult.GetRightBound())
            {
                matchResult.hitEnd = true;
                return(-1);
            }

            char low_0 = testString[stringIndex];

            if (stringIndex > matchResult.GetLeftBound())
            {
                char high = testString[stringIndex - 1];

                /*
                 * we consider high surrogate followed by
                 * low surrogate as a codepoint
                 */
                if (System.Char.IsHighSurrogate(high))
                {
                    return(-1);
                }
            }

            if (this.low == low_0)
            {
                return(next.Matches(stringIndex + 1, testString, matchResult));
            }

            return(-1);
        }
Esempio n. 6
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int strLength = matchResult.GetRightBound();

            if (stringIndex + 1 > strLength)
            {
                matchResult.hitEnd = true;
                return(-1);
            }
            char high = testString[stringIndex];

            if (System.Char.IsHighSurrogate(high) && (stringIndex + 2 <= strLength))
            {
                char low = testString[stringIndex + 1];

                if (System.Char.IsSurrogatePair(high, low))
                {
                    return((lt.IsLineTerminator(Character.ToCodePoint(high, low))) ? -1
                                                        : next.Matches(stringIndex + 2, testString, matchResult));
                }
            }

            return((lt.IsLineTerminator(high)) ? -1 : next.Matches(stringIndex + 1,
                                                                   testString, matchResult));
        }
Esempio n. 7
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int strLength = matchResult.GetRightBound();

            if (stringIndex + 1 > strLength)
            {
                matchResult.hitEnd = true;
                return(-1);
            }

            char high_0 = testString[stringIndex];

            if (stringIndex + 1 < strLength)
            {
                char low = testString[stringIndex + 1];

                /*
                 * we consider high surrogate followed by
                 * low surrogate as a codepoint
                 */
                if (System.Char.IsLowSurrogate(low))
                {
                    return(-1);
                }
            }

            if (this.high == high_0)
            {
                return(next.Matches(stringIndex + 1, testString, matchResult));
            }

            return(-1);
        }
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int i     = 0;
            int shift = 0;

            while (stringIndex + leaf.CharCount() <= matchResult.GetRightBound() &&
                   (shift = leaf.Accepts(stringIndex, testString)) > 0)
            {
                stringIndex += shift;
                i++;
            }

            for (; i >= 0; i--)
            {
                shift = next.Matches(stringIndex, testString, matchResult);
                if (shift >= 0)
                {
                    return(shift);
                }

                stringIndex -= leaf.CharCount();
            }
            return(-1);
        }
Esempio n. 9
0
        public override int Find(int strIndex, String testString,
                                 MatchResultImpl matchResult)
        {
            if (testString  is  String)
            {
                String testStr   = (String)testString;
                int    strLength = matchResult.GetRightBound();

                while (strIndex < strLength)
                {
                    strIndex = testStr.IndexOf(high, strIndex);
                    if (strIndex < 0)
                    {
                        return(-1);
                    }

                    strIndex++;
                    if (strIndex < strLength)
                    {
                        char ch_0 = testStr[strIndex];

                        if ((low == ch_0) &&
                            (next.Matches(strIndex + 1, testString,
                                          matchResult) >= 0))
                        {
                            return(--strIndex);
                        }
                        strIndex++;
                    }
                }
                return(-1);
            }

            return(base.Find(strIndex, testString, matchResult));
        }
Esempio n. 10
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int min   = quantifier.Min();
            int max   = quantifier.Max();
            int i     = 0;
            int shift = 0;

            for (; i < min; i++)
            {
                if (stringIndex + leaf.CharCount() > matchResult.GetRightBound())
                {
                    matchResult.hitEnd = true;
                    return(-1);
                }

                shift = leaf.Accepts(stringIndex, testString);
                if (shift < 1)
                {
                    return(-1);
                }
                stringIndex += shift;
            }

            do
            {
                shift = next.Matches(stringIndex, testString, matchResult);
                if (shift >= 0)
                {
                    return(shift);
                }

                if (stringIndex + leaf.CharCount() <= matchResult.GetRightBound())
                {
                    shift        = leaf.Accepts(stringIndex, testString);
                    stringIndex += shift;
                    i++;
                }
            } while (shift >= 1 && i <= max);

            return(-1);
        }
Esempio n. 11
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int strLength = matchResult.GetRightBound();

            if (strLength <= stringIndex)
            {
                return(next.Matches(stringIndex, testString, matchResult));
            }
            return(next.FindBack(stringIndex, strLength, testString, matchResult));
        }
Esempio n. 12
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            while (stringIndex + leaf.CharCount() <= matchResult.GetRightBound() &&
                   leaf.Accepts(stringIndex, testString) > 0)
            {
                stringIndex += leaf.CharCount();
            }

            return(next.Matches(stringIndex, testString, matchResult));
        }
Esempio n. 13
0
 public override int Matches(int stringIndex, String testString,
                             MatchResultImpl matchResult)
 {
     if (matchResult.Mode() == Matcher.MODE_FIND ||
         stringIndex == matchResult.GetRightBound())
     {
         matchResult.SetValid();
         matchResult.SetEnd(0, stringIndex);
         return(stringIndex);
     }
     return(-1);
 }
Esempio n. 14
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int shift = 0;

            if (stringIndex + leaf.CharCount() <= matchResult.GetRightBound() &&
                (shift = leaf.Accepts(stringIndex, testString)) >= 1)
            {
                stringIndex += shift;
            }

            return(next.Matches(stringIndex, testString, matchResult));
        }
Esempio n. 15
0
		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);
		}
Esempio n. 16
0
        public override int Matches(int strIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            if (strIndex != matchResult.GetRightBound() &&
                ((strIndex == 0 || (matchResult.HasAnchoringBounds() && strIndex == matchResult
                                    .GetLeftBound())) || lt.IsAfterLineTerminator(
                     testString[strIndex - 1],
                     testString[strIndex])))
            {
                return(next.Matches(strIndex, testString, matchResult));
            }

            return(-1);
        }
Esempio n. 17
0
        public override int Find(int stringIndex, String testString,
                                 MatchResultImpl matchResult)
        {
            int strLength = matchResult.GetRightBound();

            if (next.FindBack(stringIndex, strLength, testString, matchResult) >= 0)
            {
                return(stringIndex);
            }
            else
            {
                return(-1);
            }
        }
        /// <summary>
        /// Returns stringIndex+shift, the next position to match
        /// </summary>
        ///
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int startStr  = matchResult.GetLeftBound();
            int strLength = matchResult.GetRightBound();

            if (stringIndex + 1 > strLength)
            {
                matchResult.hitEnd = true;
                return(-1);
            }

            char ch = testString[stringIndex];

            if (!surrChars.Contains(ch))
            {
                return(-1);
            }

            if (System.Char.IsHighSurrogate(ch))
            {
                if (stringIndex + 1 < strLength)
                {
                    char low = testString[stringIndex + 1];

                    if (System.Char.IsLowSurrogate(low))
                    {
                        return(-1);
                    }
                }
            }
            else if (System.Char.IsLowSurrogate(ch))
            {
                if (stringIndex > startStr)
                {
                    char high = testString[stringIndex - 1];

                    if (System.Char.IsHighSurrogate(high))
                    {
                        return(-1);
                    }
                }
            }

            return(next.Matches(stringIndex + 1, testString, matchResult));
        }
Esempio n. 19
0
        public override int Find(int stringIndex, String 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 occurrence of the searched pattern
            // //
            int res = next.Find(stringIndex, testString, matchResult);

            // 3. Check if we have other occurrences 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);
        }
Esempio n. 20
0
        /// <summary>
        /// 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.
        /// </summary>
        ///
        /// <param name="stringIndex">starting index</param>
        /// <param name="testString">string to search in</param>
        /// <param name="matchResult">result of the match</param>
        /// <returns>last searched index</returns>
        public virtual int Find(int stringIndex, String testString,
                                MatchResultImpl matchResult)
        {
            int length = matchResult.GetRightBound();

            while (stringIndex <= length)
            {
                if (Matches(stringIndex, testString, matchResult) >= 0)
                {
                    return(stringIndex);
                }
                else
                {
                    stringIndex++;
                }
            }
            return(-1);
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
        /// <summary>
        /// Checks if we can enter this state and pass the control to the next one.
        /// Return positive value if match succeeds, negative otherwise.
        /// </summary>
        ///
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            if (stringIndex + CharCount() > matchResult.GetRightBound())
            {
                matchResult.hitEnd = true;
                return(-1);
            }

            int shift = Accepts(stringIndex, testString);

            if (shift < 0)
            {
                return(-1);
            }

            return(next.Matches(stringIndex + shift, testString, matchResult));
        }
Esempio n. 23
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int strLength = matchResult.GetRightBound();

            int startSearch =             /* testString.toString().indexOf('\n', stringIndex); */
                              FindLineTerminator(stringIndex, strLength, testString);

            if (startSearch < 0)
            {
                startSearch = strLength;
            }

            if (startSearch <= stringIndex)
            {
                return(next.Matches(stringIndex, testString, matchResult));
            }
            return(next.FindBack(stringIndex, startSearch, testString, matchResult));
        }
Esempio n. 24
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            bool left;
            bool right;

            char ch1 = (stringIndex >= matchResult.GetRightBound()) ? ' '
                                        : testString[stringIndex];
            char ch2 = (stringIndex == 0) ? ' ' : testString[stringIndex - 1];

            int leftBound = (matchResult.HasTransparentBounds()) ? 0 : matchResult
                            .GetLeftBound();

            left  = (ch1 == ' ') || IsSpace(ch1, stringIndex, leftBound, testString);
            right = (ch2 == ' ') ||
                    IsSpace(ch2, stringIndex - 1, leftBound, testString);
            return(((left ^ right) ^ positive) ? -1 : next.Matches(stringIndex,
                                                                   testString, matchResult));
        }
        public override int Find(int strIndex, String testString,
                                 MatchResultImpl matchResult)
        {
            if (testString  is  String)
            {
                String testStr   = (String)testString;
                int    startStr  = matchResult.GetLeftBound();
                int    strLength = matchResult.GetRightBound();

                while (strIndex < strLength)
                {
                    strIndex = testStr.IndexOf(low, strIndex);
                    if (strIndex < 0)
                    {
                        return(-1);
                    }

                    if (strIndex > startStr)
                    {
                        /*
                         * we consider high surrogate followed by
                         * low surrogate as a codepoint
                         */
                        if (System.Char.IsHighSurrogate(testStr[strIndex - 1]))
                        {
                            strIndex++;
                            continue;
                        }
                    }

                    if (next.Matches(strIndex + 1, testString, matchResult) >= 0)
                    {
                        return(strIndex);
                    }
                    strIndex++;
                }

                return(-1);
            }

            return(base.Find(strIndex, testString, matchResult));
        }
Esempio n. 26
0
        public override int FindBack(int strIndex, int lastIndex, String testString,
                                     MatchResultImpl matchResult)
        {
            if (testString  is  String)
            {
                String testStr   = (String)testString;
                int    strLength = matchResult.GetRightBound();

                while (lastIndex >= strIndex)
                {
                    lastIndex = testStr.LastIndexOf(high, lastIndex);
                    if (lastIndex < 0 || lastIndex < strIndex)
                    {
                        return(-1);
                    }

                    if (lastIndex + 1 < strLength)
                    {
                        /*
                         * we consider high surrogate followed by
                         * low surrogate as a codepoint
                         */
                        if (System.Char.IsLowSurrogate(testStr[lastIndex + 1]))
                        {
                            lastIndex--;
                            continue;
                        }
                    }

                    if (next.Matches(lastIndex + 1, testString, matchResult) >= 0)
                    {
                        return(lastIndex);
                    }

                    lastIndex--;
                }

                return(-1);
            }

            return(base.FindBack(strIndex, lastIndex, testString, matchResult));
        }
Esempio n. 27
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int shift = 0;

            do
            {
                shift = next.Matches(stringIndex, testString, matchResult);
                if (shift >= 0)
                {
                    return(shift);
                }

                if (stringIndex + leaf.CharCount() <= matchResult.GetRightBound())
                {
                    shift        = leaf.Accepts(stringIndex, testString);
                    stringIndex += shift;
                }
            } while (shift >= 1);

            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);
            }

            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));
        }
Esempio n. 29
0
        public override int Find(int strIndex, String testString,
                                 MatchResultImpl matchResult)
        {
            int strLength = matchResult.GetRightBound();

            while (strIndex <= strLength)
            {
                strIndex = IndexOf(testString, strIndex, strLength);

                if (strIndex < 0)
                {
                    return(-1);
                }
                if (next.Matches(strIndex + charCount, testString, matchResult) >= 0)
                {
                    return(strIndex);
                }

                strIndex++;
            }

            return(-1);
        }
Esempio n. 30
0
        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));
        }