IsMatched() private méthode

private IsMatched ( int cap ) : bool
cap int
Résultat bool
Exemple #1
0
 /*
  * Call out to runmatch to get around visibility issues
  */
 protected bool IsMatched(int cap)
 {
     return(_runmatch.IsMatched(cap));
 }
        internal static string[] Split(Regex regex, string input, int count, int startat)
        {
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", SR.GetString("CountTooSmall"));
            }
            if ((startat < 0) || (startat > input.Length))
            {
                throw new ArgumentOutOfRangeException("startat", SR.GetString("BeginIndexNotNegative"));
            }
            if (count == 1)
            {
                return(new string[] { input });
            }
            count--;
            Match match = regex.Match(input, startat);

            if (!match.Success)
            {
                return(new string[] { input });
            }
            List <string> list = new List <string>();

            if (regex.RightToLeft)
            {
                int length = input.Length;
Label_011A:
                list.Add(input.Substring(match.Index + match.Length, (length - match.Index) - match.Length));
                length = match.Index;
                for (int j = 1; j < match.Groups.Count; j++)
                {
                    if (match.IsMatched(j))
                    {
                        list.Add(match.Groups[j].ToString());
                    }
                }
                if (--count != 0)
                {
                    match = match.NextMatch();
                    if (match.Success)
                    {
                        goto Label_011A;
                    }
                }
                list.Add(input.Substring(0, length));
                list.Reverse(0, list.Count);
                goto Label_01BD;
            }
            int startIndex = 0;

Label_0082:
            list.Add(input.Substring(startIndex, match.Index - startIndex));
            startIndex = match.Index + match.Length;
            for (int i = 1; i < match.Groups.Count; i++)
            {
                if (match.IsMatched(i))
                {
                    list.Add(match.Groups[i].ToString());
                }
            }
            if (--count != 0)
            {
                match = match.NextMatch();
                if (match.Success)
                {
                    goto Label_0082;
                }
            }
            list.Add(input.Substring(startIndex, input.Length - startIndex));
Label_01BD:
            return(list.ToArray());
        }
Exemple #3
0
        /// <summary>
        /// Does a split. In the right-to-left case we reorder the
        /// array to be forwards.
        /// </summary>
        internal static String[] Split(Regex regex, String input, int count, int startat)
        {
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", SR.CountTooSmall);
            }
            if (startat < 0 || startat > input.Length)
            {
                throw new ArgumentOutOfRangeException("startat", SR.BeginIndexNotNegative);
            }

            String[] result;

            if (count == 1)
            {
                result    = new String[1];
                result[0] = input;
                return(result);
            }

            count -= 1;

            Match match = regex.Match(input, startat);

            if (!match.Success)
            {
                result    = new String[1];
                result[0] = input;
                return(result);
            }
            else
            {
                List <String> al = new List <String>();

                if (!regex.RightToLeft)
                {
                    int prevat = 0;

                    for (; ;)
                    {
                        al.Add(input.Substring(prevat, match.Index - prevat));

                        prevat = match.Index + match.Length;

                        // add all matched capture groups to the list.
                        for (int i = 1; i < match.Groups.Count; i++)
                        {
                            if (match.IsMatched(i))
                            {
                                al.Add(match.Groups[i].ToString());
                            }
                        }

                        if (--count == 0)
                        {
                            break;
                        }

                        match = match.NextMatch();

                        if (!match.Success)
                        {
                            break;
                        }
                    }

                    al.Add(input.Substring(prevat, input.Length - prevat));
                }
                else
                {
                    int prevat = input.Length;

                    for (; ;)
                    {
                        al.Add(input.Substring(match.Index + match.Length, prevat - match.Index - match.Length));

                        prevat = match.Index;

                        // add all matched capture groups to the list.
                        for (int i = 1; i < match.Groups.Count; i++)
                        {
                            if (match.IsMatched(i))
                            {
                                al.Add(match.Groups[i].ToString());
                            }
                        }

                        if (--count == 0)
                        {
                            break;
                        }

                        match = match.NextMatch();

                        if (!match.Success)
                        {
                            break;
                        }
                    }

                    al.Add(input.Substring(0, prevat));

                    al.Reverse(0, al.Count);
                }

                return(al.ToArray());
            }
        }
Exemple #4
0
        internal static string[] Split(Regex regex, string input, int count, int startat)
        {
            string[] strArray2;
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            if ((startat < 0) || (startat > input.Length))
            {
                throw new ArgumentOutOfRangeException();
            }
            if (count == 1)
            {
                return(new string[] { input });
            }
            count--;
            Match match = regex.Match(input, startat);

            if (!match.Success)
            {
                return(new string[] { input });
            }
            ArrayList list = new ArrayList();

            if (regex.RightToLeft)
            {
                int length = input.Length;
                do
                {
                    list.Add(input.Substring(match.Index + match.Length, (length - match.Index) - match.Length));
                    length = match.Index;
                    if (--count == 0)
                    {
                        break;
                    }
                    match = match.NextMatch();
                }while (match.Success);
                list.Add(input.Substring(0, length));
                list.Reverse(0, list.Count);
                goto Label_0153;
            }
            int startIndex = 0;

Label_0064:
            list.Add(input.Substring(startIndex, match.Index - startIndex));
            startIndex = match.Index + match.Length;
            for (int i = 1; match.IsMatched(i); i++)
            {
                list.Add(match.Groups[i].ToString());
            }
            if (--count != 0)
            {
                match = match.NextMatch();
                if (match.Success)
                {
                    goto Label_0064;
                }
            }
            list.Add(input.Substring(startIndex, input.Length - startIndex));
Label_0153:
            strArray2 = new string[list.Count];
            list.CopyTo(0, strArray2, 0, list.Count);
            return(strArray2);
        }