Replace() static private method

Replaces all occurrences of the regex in the string with the replacement evaluator. Note that the special case of no matches is handled on its own: with no matches, the input string is returned unchanged. The right-to-left case is split out because StringBuilder doesn't handle right-to-left string building directly very well.
static private Replace ( MatchEvaluator evaluator, Regex regex, string input, int count, int startat ) : string
evaluator MatchEvaluator
regex Regex
input string
count int
startat int
return string
Example #1
0
File: Regex.cs Project: jnm2/corefx
        /// <summary>
        /// Replaces all occurrences of the previously defined pattern with the recent
        /// replacement pattern, starting at the character position
        /// <paramref name="startat"/>.
        /// </summary>
        public string Replace(string input, MatchEvaluator evaluator, int count, int startat)
        {
            if (input == null)
                throw new ArgumentNullException(nameof(input));

            return RegexReplacement.Replace(evaluator, this, input, count, startat);
        }
Example #2
0
        /// <summary>
        /// Replaces all occurrences of the previously defined pattern with the recent
        /// replacement pattern, starting at the character position
        /// <paramref name="startat"/>.
        /// </summary>
        public String Replace(String input, MatchEvaluator evaluator, int count, int startat)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            return(RegexReplacement.Replace(evaluator, this, input, count, startat));
        }
Example #3
0
        /// <summary>
        /// Replaces all occurrences of the previously defined pattern with the
        /// <paramref name="replacement"/> pattern, starting at the character position
        /// <paramref name="startat"/>.
        /// </summary>
        public string Replace(string input, string replacement, int count, int startat)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (replacement == null)
            {
                throw new ArgumentNullException(nameof(replacement));
            }

            // Gets the weakly cached replacement helper or creates one if there isn't one already.
            RegexReplacement repl = RegexReplacement.GetOrCreate(_replref, replacement, caps, capsize, capnames, roptions);

            return(repl.Replace(this, input, count, startat));
        }
Example #4
0
File: Regex.cs Project: jnm2/corefx
        /// <summary>
        /// Replaces all occurrences of the previously defined pattern with the
        /// <paramref name="replacement"/> pattern, starting at the character position
        /// <paramref name="startat"/>.
        /// </summary>
        public string Replace(string input, string replacement, int count, int startat)
        {
            if (input == null)
                throw new ArgumentNullException(nameof(input));

            if (replacement == null)
                throw new ArgumentNullException(nameof(replacement));

            // a little code to grab a cached parsed replacement object
            RegexReplacement repl = (RegexReplacement)_replref.Get();

            if (repl == null || !repl.Pattern.Equals(replacement))
            {
                repl = RegexParser.ParseReplacement(replacement, caps, capsize, capnames, roptions);
                _replref.Cache(repl);
            }

            return repl.Replace(this, input, count, startat);
        }
Example #5
0
        public string Replace(string input, string replacement, int count, int startat)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (replacement == null)
            {
                throw new ArgumentNullException("replacement");
            }
            RegexReplacement replacement2 = (RegexReplacement)this.replref.Get();

            if ((replacement2 == null) || !replacement2.Pattern.Equals(replacement))
            {
                replacement2 = RegexParser.ParseReplacement(replacement, this.caps, this.capsize, this.capnames, this.roptions);
                this.replref.Cache(replacement2);
            }
            return(replacement2.Replace(this, input, count, startat));
        }