예제 #1
0
        /*
         * Return the result string (using the replacement pattern)
         */
        /// <devdoc>
        ///    <para>
        ///       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().
        ///    </para>
        /// </devdoc>
        public virtual String Result(String replacement)
        {
            RegexReplacement repl;

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

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

            repl = (RegexReplacement)_regex.replref.Get();

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

            return(repl.Replacement(this));
        }
예제 #2
0
 public string Replace(string input, string replacement, int count, int startat)
 {
     if ((input == null) || (replacement == null))
     {
         throw new ArgumentNullException();
     }
     return(RegexParser.ParseReplacement(replacement, this.caps, this.capsize, this.capnames, this.roptions).Replace(this, input, count, startat));
 }
예제 #3
0
        /// <summary>
        /// Either returns a weakly cached RegexReplacement helper or creates one and caches it.
        /// </summary>
        /// <returns></returns>
        public static RegexReplacement GetOrCreate(WeakReference <RegexReplacement?> replRef, string replacement, Hashtable caps,
                                                   int capsize, Hashtable capnames, RegexOptions roptions)
        {
            if (!replRef.TryGetTarget(out RegexReplacement? repl) || !repl.Pattern.Equals(replacement))
            {
                repl = RegexParser.ParseReplacement(replacement, roptions, caps, capsize, capnames);
                replRef.SetTarget(repl);
            }

            return(repl);
        }
예제 #4
0
 public virtual string Result(string replacement)
 {
     if (replacement == null)
     {
         throw new ArgumentNullException();
     }
     if (this._regex == null)
     {
         throw new NotSupportedException(RegExRes.GetString(5));
     }
     return(RegexParser.ParseReplacement(replacement, this._regex.caps, this._regex.capsize, this._regex.capnames, this._regex.roptions).Replacement(this));
 }
예제 #5
0
        public virtual string Result(string replacement)
        {
            if (replacement == null)
            {
                throw new ArgumentNullException("replacement");
            }
            if (this._regex == null)
            {
                throw new NotSupportedException(SR.GetString("NoResultOnFailed"));
            }
            RegexReplacement replacement2 = (RegexReplacement)this._regex.replref.Get();

            if ((replacement2 == null) || !replacement2.Pattern.Equals(replacement))
            {
                replacement2 = RegexParser.ParseReplacement(replacement, this._regex.caps, this._regex.capsize, this._regex.capnames, this._regex.roptions);
                this._regex.replref.Cache(replacement2);
            }
            return(replacement2.Replacement(this));
        }
예제 #6
0
파일: Regex.cs 프로젝트: 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);
        }
예제 #7
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));
        }
예제 #8
0
        // Does the replacement
        //| <include file='doc\Regex.uex' path='docs/doc[@for="Regex.Replace4"]/*' />
        /// <devdoc>
        ///    <para>
        ///    Replaces all occurrences of the <paramref name="pattern "/>with the recent
        ///    <paramref name="replacement"/> pattern, starting at the character position
        ///    <paramref name="startat."/>
        /// </para>
        /// </devdoc>
        public String Replace(String input, String replacement, int count, int startat)
        {
            RegexReplacement repl;

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

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

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

            return(repl.Replace(this, input, count, startat));
        }