GroupToStringImpl() private method

private GroupToStringImpl ( int groupnum ) : string
groupnum int
return string
Esempio n. 1
0
 /// <summary>
 /// Given a Match, emits into the StringBuilder the evaluated
 /// substitution pattern.
 /// </summary>
 private void ReplacementImpl(StringBuilder sb, Match match)
 {
     for (int i = 0; i < _rules.Count; i++)
     {
         int r = _rules[i];
         if (r >= 0)   // string lookup
             sb.Append(_strings[r]);
         else if (r < -Specials) // group lookup
             sb.Append(match.GroupToStringImpl(-Specials - 1 - r));
         else
         {
             switch (-Specials - 1 - r)
             { // special insertion patterns
                 case LeftPortion:
                     sb.Append(match.GetLeftSubstring());
                     break;
                 case RightPortion:
                     sb.Append(match.GetRightSubstring());
                     break;
                 case LastGroup:
                     sb.Append(match.LastGroupToStringImpl());
                     break;
                 case WholeString:
                     sb.Append(match.GetOriginalString());
                     break;
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Given a Match, emits into the builder the evaluated
        /// Right-to-Left substitution pattern.
        /// </summary>
        public void ReplacementImplRTL(ref SegmentStringBuilder segments, Match match)
        {
            for (int i = _rules.Length - 1; i >= 0; i--)
            {
                int rule = _rules[i];

                ReadOnlyMemory <char> segment =
                    rule >= 0 ? _strings[rule].AsMemory() :                          // string lookup
                    rule < -Specials?match.GroupToStringImpl(-Specials - 1 - rule) : // group lookup
                        (-Specials - 1 - rule) switch                                // special insertion patterns
                {
                    LeftPortion => match.GetLeftSubstring(),
                    RightPortion => match.GetRightSubstring(),
                    LastGroup => match.LastGroupToStringImpl(),
                    WholeString => match.Text.AsMemory(),
                    _ => default
                };

                // Add the segment to the list if it's not empty.  A common case for it being
                // empty is if the developer is using Regex.Replace as a way to implement
                // Regex.Remove, where the replacement string is empty.
                if (segment.Length != 0)
                {
                    segments.Add(segment);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Given a Match, emits into the List<String> the evaluated
 /// Right-to-Left substitution pattern.
 /// </summary>
 private void ReplacementImplRTL(List<String> al, Match match)
 {
     for (int i = _rules.Count - 1; i >= 0; i--)
     {
         int r = _rules[i];
         if (r >= 0)  // string lookup
             al.Add(_strings[r]);
         else if (r < -Specials) // group lookup
             al.Add(match.GroupToStringImpl(-Specials - 1 - r));
         else
         {
             switch (-Specials - 1 - r)
             { // special insertion patterns
                 case LeftPortion:
                     al.Add(match.GetLeftSubstring());
                     break;
                 case RightPortion:
                     al.Add(match.GetRightSubstring());
                     break;
                 case LastGroup:
                     al.Add(match.LastGroupToStringImpl());
                     break;
                 case WholeString:
                     al.Add(match.GetOriginalString());
                     break;
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Given a Match, emits into the builder the evaluated
        /// Right-to-Left substitution pattern.
        /// </summary>
        public void ReplacementImplRTL(ref SegmentStringBuilder segments, Match match)
        {
            for (int i = _rules.Length - 1; i >= 0; i--)
            {
                int r = _rules[i];
                if (r >= 0)
                {
                    // string lookup
                    segments.Add(_strings[r].AsMemory());
                }
                else if (r < -Specials)
                {
                    // group lookup
                    segments.Add(match.GroupToStringImpl(-Specials - 1 - r));
                }
                else
                {
                    // special insertion patterns
                    switch (-Specials - 1 - r)
                    {
                    case LeftPortion:
                        segments.Add(match.GetLeftSubstring());
                        break;

                    case RightPortion:
                        segments.Add(match.GetRightSubstring());
                        break;

                    case LastGroup:
                        segments.Add(match.LastGroupToStringImpl());
                        break;

                    case WholeString:
                        segments.Add(match.Text.AsMemory());
                        break;
                    }
                }
            }
        }
        /*
         *
         * Given a Match, emits into the StringBuilder the evaluated
         * substitution pattern.
         */
        private void ReplacementImpl(StringBuilder sb, Match match)
        {
            for (int i = 0; i < _rules.Count; i++)
            {
                int r = (int)_rules[i];
                if (r >= 0)
                {
                    sb.Append((string)_strings[r]);
                }
                else if (r < -Specials)
                {
                    sb.Append(match.GroupToStringImpl(-Specials - 1 - r));
                }
                else
                {
                    switch (-Specials - 1 - r)
                    {
                    case LeftPortion:
                        sb.Append(match.GetLeftSubstring());
                        break;

                    case RightPortion:
                        sb.Append(match.GetRightSubstring());
                        break;

                    case LastGroup:
                        sb.Append(match.LastGroupToStringImpl());
                        break;

                    case WholeString:
                        sb.Append(match.GetOriginalString());
                        break;
                    }
                }
            }
        }
        private void ReplacementImplRTL(List <string> al, Match match)
        {
            for (int i = this._rules.Count - 1; i >= 0; i--)
            {
                int num2 = this._rules[i];
                if (num2 >= 0)
                {
                    al.Add(this._strings[num2]);
                }
                else if (num2 < -4)
                {
                    al.Add(match.GroupToStringImpl(-5 - num2));
                }
                else
                {
                    switch ((-5 - num2))
                    {
                    case -4:
                        al.Add(match.GetOriginalString());
                        break;

                    case -3:
                        al.Add(match.LastGroupToStringImpl());
                        break;

                    case -2:
                        al.Add(match.GetRightSubstring());
                        break;

                    case -1:
                        al.Add(match.GetLeftSubstring());
                        break;
                    }
                }
            }
        }
        private void ReplacementImpl(StringBuilder sb, Match match)
        {
            for (int i = 0; i < this._rules.Count; i++)
            {
                int num2 = this._rules[i];
                if (num2 >= 0)
                {
                    sb.Append(this._strings[num2]);
                }
                else if (num2 < -4)
                {
                    sb.Append(match.GroupToStringImpl(-5 - num2));
                }
                else
                {
                    switch ((-5 - num2))
                    {
                    case -4:
                        sb.Append(match.GetOriginalString());
                        break;

                    case -3:
                        sb.Append(match.LastGroupToStringImpl());
                        break;

                    case -2:
                        sb.Append(match.GetRightSubstring());
                        break;

                    case -1:
                        sb.Append(match.GetLeftSubstring());
                        break;
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Given a Match, emits into the ValueStringBuilder the evaluated
        /// Right-to-Left substitution pattern.
        /// </summary>
        public void ReplacementImplRTL(ref ValueStringBuilder vsb, Match match)
        {
            for (int i = _rules.Count - 1; i >= 0; i--)
            {
                int r = _rules[i];
                if (r >= 0)  // string lookup
                {
                    vsb.AppendReversed(_strings[r]);
                }
                else if (r < -Specials) // group lookup
                {
                    vsb.AppendReversed(match.GroupToStringImpl(-Specials - 1 - r));
                }
                else
                {
                    switch (-Specials - 1 - r)
                    { // special insertion patterns
                    case LeftPortion:
                        vsb.AppendReversed(match.GetLeftSubstring());
                        break;

                    case RightPortion:
                        vsb.AppendReversed(match.GetRightSubstring());
                        break;

                    case LastGroup:
                        vsb.AppendReversed(match.LastGroupToStringImpl());
                        break;

                    case WholeString:
                        vsb.AppendReversed(match.Text);
                        break;
                    }
                }
            }
        }
        private void ReplacementImplRTL(List<string> al, Match match)
        {
            for (int i = this._rules.Count - 1; i >= 0; i--)
            {
                int num2 = this._rules[i];
                if (num2 >= 0)
                {
                    al.Add(this._strings[num2]);
                }
                else if (num2 < -4)
                {
                    al.Add(match.GroupToStringImpl(-5 - num2));
                }
                else
                {
                    switch ((-5 - num2))
                    {
                        case -4:
                            al.Add(match.GetOriginalString());
                            break;

                        case -3:
                            al.Add(match.LastGroupToStringImpl());
                            break;

                        case -2:
                            al.Add(match.GetRightSubstring());
                            break;

                        case -1:
                            al.Add(match.GetLeftSubstring());
                            break;
                    }
                }
            }
        }
        private void ReplacementImpl(StringBuilder sb, Match match)
        {
            for (int i = 0; i < this._rules.Count; i++)
            {
                int num2 = this._rules[i];
                if (num2 >= 0)
                {
                    sb.Append(this._strings[num2]);
                }
                else if (num2 < -4)
                {
                    sb.Append(match.GroupToStringImpl(-5 - num2));
                }
                else
                {
                    switch ((-5 - num2))
                    {
                        case -4:
                            sb.Append(match.GetOriginalString());
                            break;

                        case -3:
                            sb.Append(match.LastGroupToStringImpl());
                            break;

                        case -2:
                            sb.Append(match.GetRightSubstring());
                            break;

                        case -1:
                            sb.Append(match.GetLeftSubstring());
                            break;
                    }
                }
            }
        }
Esempio n. 11
0
        internal string Replace(Regex regex, string input, int count, int startat)
        {
            StringBuilder builder;

            if (count < -1)
            {
                throw new ArgumentOutOfRangeException();
            }
            if ((startat < 0) || (startat > input.Length))
            {
                throw new ArgumentOutOfRangeException();
            }
            if (count == 0)
            {
                return(input);
            }
            Match match = regex.Match(input, startat);

            if (!match.Success)
            {
                return(input);
            }
            if (regex.RightToLeft)
            {
                ArrayList list   = new ArrayList();
                int       length = input.Length;
Label_00BF:
                if ((match.Index + match.Length) != length)
                {
                    list.Add(input.Substring(match.Index + match.Length, (length - match.Index) - match.Length));
                }
                length = match.Index;
                for (int i = this._rules.Length - 1; i >= 0; i--)
                {
                    int index = this._rules[i];
                    if (index >= 0)
                    {
                        list.Add(this._strings[index]);
                    }
                    else
                    {
                        list.Add(match.GroupToStringImpl(-5 - index));
                    }
                }
                if (--count != 0)
                {
                    match = match.NextMatch();
                    if (match.Success)
                    {
                        goto Label_00BF;
                    }
                }
                builder = new StringBuilder();
                if (length > 0)
                {
                    builder.Append(input, 0, length);
                }
                for (int j = list.Count - 1; j >= 0; j--)
                {
                    builder.Append((string)list[j]);
                }
                goto Label_01AA;
            }
            builder = new StringBuilder();
            int startIndex = 0;

Label_0048:
            if (match.Index != startIndex)
            {
                builder.Append(input, startIndex, match.Index - startIndex);
            }
            startIndex = match.Index + match.Length;
            this.ReplacementImpl(builder, match);
            if (--count != 0)
            {
                match = match.NextMatch();
                if (match.Success)
                {
                    goto Label_0048;
                }
            }
            if (startIndex < input.Length)
            {
                builder.Append(input, startIndex, input.Length - startIndex);
            }
Label_01AA:
            return(builder.ToString());
        }