コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
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);
        }
コード例 #5
0
        protected internal String GetString(MatchResultImpl matchResult)
        {
            String res = matchResult.GetGroupNoCheck(referencedGroup);

            return(res);
            // return (res != null) ? res : "";
        }
コード例 #6
0
        public override int FindBack(int strIndex, int lastIndex, String testString,
                                     MatchResultImpl matchResult)
        {
            if (testString  is  String)
            {
                String testStr = (String)testString;

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

                    if ((high == testStr[lastIndex]) &&
                        next.Matches(lastIndex + 2, testString, matchResult) >= 0)
                    {
                        return(lastIndex);
                    }

                    lastIndex--;
                }
                return(-1);
            }

            return(base.FindBack(strIndex, lastIndex, testString, matchResult));
        }
コード例 #7
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));
        }
コード例 #8
0
ファイル: EOLSet.cs プロジェクト: bdqnghi/j2cstranslator
        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);
        }
コード例 #9
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);
        }
コード例 #10
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);
        }
コード例 #11
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)
                {
                    // 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);
        }
コード例 #12
0
ファイル: DotSet.cs プロジェクト: bdqnghi/j2cstranslator
        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));
        }
コード例 #13
0
        public override int FindBack(int stringIndex, int lastIndex,
                                     String testString, MatchResultImpl matchResult)
        {
            int res         = 0;
            int startSearch = lastIndex;

            for (; startSearch >= stringIndex; 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);
        }
コード例 #14
0
        public override bool HasConsumed(MatchResultImpl matchResult)
        {
            int  cons;
            bool res = ((cons = matchResult.GetConsumed(consCounter)) < 0 || cons > 0);

            matchResult.SetConsumed(consCounter, -1);
            return(res);
        }
コード例 #15
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int gr         = GetGroupIndex();
            int rightBound = matchResult.GetConsumed(gr);

            return((rightBound == stringIndex) ? stringIndex : -1);
        }
コード例 #16
0
 /// <seealso cref="M:ILOG.J2CsMapping.RegEx.AbstractSet.Matches(System.Int32, System.String, ILOG.J2CsMapping.RegEx.MatchResultImpl)"/>
 public override int Matches(int stringIndex, String testString,
                             MatchResultImpl matchResult)
 {
     if (stringIndex == matchResult.GetPreviousMatchEnd())
     {
         return(next.Matches(stringIndex, testString, matchResult));
     }
     return(-1);
 }
コード例 #17
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));
        }
コード例 #18
0
        /// <summary>
        /// Runs match starting from <c>set</c> specified against input
        /// sequence starting at <c>index</c> specified; Result of the match
        /// will be stored into matchResult instance;
        /// </summary>
        ///
        private bool RunMatch(AbstractSet set, int index,
                              MatchResultImpl matchResult_0)
        {
            if (set.Matches(index, str0, matchResult_0) >= 0)
            {
                matchResult_0.FinalizeMatch();
                return(true);
            }

            return(false);
        }
コード例 #19
0
        public override int FindBack(int stringIndex, int lastIndex,
                                     String testString, MatchResultImpl matchResult)
        {
            int res = kid.FindBack(stringIndex, lastIndex, testString, matchResult);

            if (res >= 0)
            {
                matchResult.SetStart(groupIndex, res);
            }
            return(res);
        }
コード例 #20
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));
        }
コード例 #21
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));
        }
コード例 #22
0
 public override int Matches(int strIndex, String testString,
                             MatchResultImpl matchResult)
 {
     if (strIndex == 0 ||
         (matchResult.HasAnchoringBounds() && strIndex == matchResult
          .GetLeftBound()))
     {
         return(next.Matches(strIndex, testString, matchResult));
     }
     return(-1);
 }
コード例 #23
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int nextIndex = innerSet.Matches(stringIndex, testString, matchResult);

            if (nextIndex > 0)
            {
                stringIndex = nextIndex;
            }

            return(next.Matches(stringIndex, testString, matchResult));
        }
コード例 #24
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);
 }
コード例 #25
0
        internal MatchResult CloneImpl()
        {
            MatchResultImpl res = new MatchResultImpl(this.str0, this.leftBound,
                                                      this.rightBound, this.groupCount - 1, 0, 0);

            res.valid = valid;
            if (valid)
            {
                System.Array.Copy((Array)(groupBounds), 0, (Array)(res.groupBounds), 0, this.groupBounds.Length);
            }
            return(res);
        }
コード例 #26
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));
        }
コード例 #27
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);
		}
コード例 #28
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);
        }
コード例 #29
0
        public override int Matches(int stringIndex, String testString,
                                    MatchResultImpl matchResult)
        {
            int shift;

            if ((shift = next.Matches(stringIndex, testString, matchResult)) >= 0)
            {
                return(shift);
            }
            else
            {
                return(innerSet.Matches(stringIndex, testString, matchResult));
            }
        }
コード例 #30
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);
            }
        }