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. 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);
        }
Esempio n. 3
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);
 }
Esempio n. 4
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. 5
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);
            }
        }
        /// <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));
        }
        public override int FindBack(int strIndex, int lastIndex, String testString,
                                     MatchResultImpl matchResult)
        {
            if (testString  is  String)
            {
                int    startStr = matchResult.GetLeftBound();
                String testStr  = (String)testString;

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

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

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

                    lastIndex--;
                }

                return(-1);
            }

            return(base.FindBack(strIndex, lastIndex, testString, matchResult));
        }
Esempio n. 8
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. 10
0
		public override int Find(int strIndex, String testString,
				MatchResultImpl matchResult) {
			String group = GetString(matchResult);
			int strLength = matchResult.GetLeftBound();
	
			if (group == null || (strIndex + group.Length) > strLength)
				return -1;
	
			String testStr = testString.ToString();
	
			while (strIndex <= strLength) {
				strIndex = ILOG.J2CsMapping.Util.StringUtil.IndexOf(testStr,group,strIndex);
	
				if (strIndex < 0)
					return -1;
				if (next.Matches(strIndex + group.Length, testString, matchResult) >= 0) {
					return strIndex;
				}
	
				strIndex++;
			}
	
			return -1;
		}
Esempio n. 11
0
        public override int FindBack(int stringIndex, int startSearch,
                                     String testString, MatchResultImpl matchResult)
        {
            int strLength = matchResult.GetRightBound();
            int startStr  = matchResult.GetLeftBound();

            while (startSearch >= stringIndex)
            {
                //check for supplementary codepoints
                if (startSearch < strLength)
                {
                    char low = testString[startSearch];

                    if (System.Char.IsLowSurrogate(low))
                    {
                        if (startSearch > startStr)
                        {
                            char high = testString[startSearch - 1];
                            if (System.Char.IsHighSurrogate(high))
                            {
                                startSearch--;
                                continue;
                            }
                        }
                    }
                }

                if (next.Matches(startSearch, testString, matchResult) >= 0)
                {
                    return(startSearch);
                }
                startSearch--;
            }

            return(-1);
        }
Esempio n. 12
0
 /// @com.intel.drl.spec_ref
 public int RegionStart()
 {
     return(matchResult.GetLeftBound());
 }