Пример #1
0
        public override string Replace(Regex regex, string input, string replacement, int count, int startat)
        {
            if (regex.SameGroupNamesFlag)
            {
                return(base.Replace(regex, input, replacement, count, startat));
            }

            if (count < 0)
            {
                count = Int32.MaxValue;
            }

            string  replacementPattern = ReplacementData.Reformat(regex, replacement);
            Matcher m = JavaPattern.matcher((CharSequence)(object)input);

            StringBuffer sb = new StringBuffer();

            if (count > 0 && m.find(startat))
            {
                ReplacementData.ReplaceMatch(replacementPattern, m, sb, input, _patternData);
            }

            for (int matchesCounter = 1; matchesCounter < count; ++matchesCounter)
            {
                if (!m.find())
                {
                    break;
                }
                ReplacementData.ReplaceMatch(replacementPattern, m, sb, input, _patternData);
            }


            m.appendTail(sb);
            return(sb.ToString());
        }
Пример #2
0
        public override Match Scan(Regex regex, string text, int start, int end)
        {
            if (start > end)
            {
                return(Match.Empty);
            }

            Matcher m = JavaPattern.matcher(((CharSequence)(object)text).subSequence(0, end));

            if (!m.find(start))
            {
                return(System.Text.RegularExpressions.Match.Empty);
            }

            GroupCollection groups = new GroupCollection(regex.GroupCount + 1);
            Match           match  = new Match(regex, this, groups, text, text.Length,
                                               m.start(), m.end() - m.start());

            for (int javaGroupNumber = 1; javaGroupNumber <= m.groupCount(); ++javaGroupNumber)
            {
                AddGroup(m, groups, javaGroupNumber, text, match);
            }

            return(match);
        }
Пример #3
0
        private void FillGroups(RegexOptions options)
        {
            if (_patternGrouping.GroupCount >= 0)
            {
                return;
            }

            Matcher m = JavaPattern.matcher((CharSequence)(object)String.Empty);

            if ((options & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture)
            {
                _patternGrouping.SetGroups(0, m.groupCount());
            }
            else
            {
                _patternGrouping.SetGroups(m.groupCount(), m.groupCount());
            }
        }
Пример #4
0
        public override string [] Split(Regex regex, string input, int count, int startat)
        {
            string [] splitArray = JavaPattern.split((CharSequence)(object)input.Substring(startat), count);

            if (regex.GroupCount == 0 || splitArray.Length == 1)
            {
                return(splitArray);
            }

            if (count == 0)
            {
                count = Int32.MaxValue;
            }

            Matcher m = JavaPattern.matcher((CharSequence)(object)input.Substring(startat));

            int splitArrayIndex = 1;

            List <string> splits = new List <string> (splitArray.Length * (1 + regex.GroupCount));

            splits.Add(splitArray [0]);

            for (int number = 0; number < count; ++number)
            {
                if (!m.find())
                {
                    break;
                }

                for (int i = 1; i <= m.groupCount(); ++i)
                {
                    splits.Add(m.group(i));
                }

                splits.Add(splitArray [splitArrayIndex++]);
            }

            return(splits.ToArray());
        }