ReplacementImpl() private method

Given a Match, emits into the StringBuilder the evaluated substitution pattern.
private ReplacementImpl ( StringBuilder sb, Match match ) : void
sb StringBuilder
match Match
return void
Beispiel #1
0
        /// <summary>
        /// Returns the expansion of the passed replacement pattern. For
        /// example, if the replacement pattern is ?$1$2?, Result returns the concatenation
        /// of Group(1).ToString() and Group(2).ToString().
        /// </summary>
        public virtual string Result(string replacement)
        {
            if (replacement == null)
            {
                throw new ArgumentNullException(nameof(replacement));
            }

            if (_regex == null)
            {
                throw new NotSupportedException(SR.NoResultOnFailed);
            }

            // Gets the weakly cached replacement helper or creates one if there isn't one already.
            RegexReplacement repl = RegexReplacement.GetOrCreate(_regex._replref !, replacement, _regex.caps !, _regex.capsize, _regex.capnames !, _regex.roptions);
            var vsb = new ValueStringBuilder(stackalloc char[ReplaceBufferSize]);

            repl.ReplacementImpl(ref vsb, this);
            return(vsb.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Returns the expansion of the passed replacement pattern. For
        /// example, if the replacement pattern is ?$1$2?, Result returns the concatenation
        /// of Group(1).ToString() and Group(2).ToString().
        /// </summary>
        public virtual string Result(string replacement)
        {
            if (replacement is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.replacement);
            }

            Regex?regex = _regex;

            if (regex is null)
            {
                throw new NotSupportedException(SR.NoResultOnFailed);
            }

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

            repl.ReplacementImpl(ref segments, this);
            return(segments.ToString());
        }