public static string ReplaceGroups(IEnumerable<Group> groups, string input, GroupEvaluator evaluator)
        {
            if (evaluator == null)
                throw new ArgumentNullException(nameof(evaluator));

            var sb = new StringBuilder();
            int index = 0;

            foreach (Group group in groups)
            {
                sb.Append(input, index, group.Index - index);
                sb.Append(evaluator(group));
                index = group.Index + group.Length;
            }

            sb.Append(input, index, input.Length - index);

            return sb.ToString();
        }
Beispiel #2
0
        private static string ReplaceGroups(string input, IEnumerable<Group> groups, GroupEvaluator evaluator, bool rightToLeft)
        {
            if (rightToLeft)
                groups = groups.Reverse();

            var sb = new StringBuilder();
            int index = 0;

            foreach (Group group in groups)
            {
                sb.Append(input, index, group.Index - index);
                sb.Append(evaluator(group));
                index = group.Index + group.Length;
            }

            sb.Append(input, index, input.Length - index);

            return sb.ToString();
        }
 public static string ReplaceGroups(this Regex regex, string input, int groupNumber, GroupEvaluator evaluator)
 {
     return RegexReplace.ReplaceGroups(EnumerateSuccessGroups(regex, input, groupNumber), input, evaluator);
 }
Beispiel #4
0
        private static string ReplaceGroups(string input, IEnumerable <Group> groups, GroupEvaluator evaluator, bool rightToLeft)
        {
            if (rightToLeft)
            {
                groups = groups.Reverse();
            }

            var sb    = new StringBuilder();
            int index = 0;

            foreach (Group group in groups)
            {
                sb.Append(input, index, group.Index - index);
                sb.Append(evaluator(group));
                index = group.Index + group.Length;
            }

            sb.Append(input, index, input.Length - index);

            return(sb.ToString());
        }
Beispiel #5
0
 public static string ReplaceGroups(Regex regex, string input, int groupNumber, GroupEvaluator evaluator)
 {
     return(ReplaceGroups(input, regex.EnumerateSuccessGroups(input, groupNumber), evaluator, regex.RightToLeft));
 }
Beispiel #6
0
 public static string ReplaceGroups(Regex regex, string input, int groupNumber, GroupEvaluator evaluator)
 {
     return ReplaceGroups(input, regex.EnumerateSuccessGroups(input, groupNumber), evaluator, regex.RightToLeft);
 }