internal RegexReplacement(string rep, RegexNode concat, System.Collections.Generic.Dictionary <object, object> _caps) { this._rep = rep; if (concat.Type() != 0x19) { throw new ArgumentException(RegExRes.GetString(0x25)); } StringBuilder builder = new StringBuilder(); ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode node = concat.Child(i); switch (node.Type()) { case 9: { builder.Append(node._ch); continue; } case 12: { builder.Append(node._str); continue; } case 13: { if (builder.Length > 0) { list2.Add(list.Count); list.Add(builder.ToString()); builder.Length = 0; } int num = node._m; if ((_caps != null) && (num >= 0)) { num = (int)_caps[num]; } list2.Add(-5 - num); continue; } } throw new ArgumentException(RegExRes.GetString(0x25)); } if (builder.Length > 0) { list2.Add(list.Count); list.Add(builder.ToString()); } this._strings = new string[list.Count]; list.CopyTo(0, this._strings, 0, list.Count); this._rules = new int[list2.Count]; for (int j = 0; j < list2.Count; j++) { this._rules[j] = (int)list2[j]; } }
private readonly List <int> _rules; // negative -> group #, positive -> string # /// <summary> /// Since RegexReplacement shares the same parser as Regex, /// the constructor takes a RegexNode which is a concatenation /// of constant strings and backreferences. /// </summary> public RegexReplacement(string rep, RegexNode concat, Hashtable _caps) { if (concat.Type() != RegexNode.Concatenate) { throw new ArgumentException(SR.ReplacementError); } StringBuilder sb = StringBuilderCache.Acquire(); List <string> strings = new List <string>(); List <int> rules = new List <int>(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode child = concat.Child(i); switch (child.Type()) { case RegexNode.Multi: sb.Append(child.Str); break; case RegexNode.One: sb.Append(child.Ch); break; case RegexNode.Ref: if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); sb.Length = 0; } int slot = child.M; if (_caps != null && slot >= 0) { slot = (int)_caps[slot]; } rules.Add(-Specials - 1 - slot); break; default: throw new ArgumentException(SR.ReplacementError); } } if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); } StringBuilderCache.Release(sb); Pattern = rep; _strings = strings; _rules = rules; }
private readonly List <int> _rules; // negative -> group #, positive -> string # /// <summary> /// Since RegexReplacement shares the same parser as Regex, /// the constructor takes a RegexNode which is a concatenation /// of constant strings and backreferences. /// </summary> public RegexReplacement(string rep, RegexNode concat, Hashtable _caps) { if (concat.Type() != RegexNode.Concatenate) { throw new ArgumentException(SR.ReplacementError); } Span <char> vsbStack = stackalloc char[256]; var vsb = new ValueStringBuilder(vsbStack); var strings = new List <string>(); var rules = new List <int>(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode child = concat.Child(i); switch (child.Type()) { case RegexNode.Multi: vsb.Append(child.Str !); break; case RegexNode.One: vsb.Append(child.Ch); break; case RegexNode.Ref: if (vsb.Length > 0) { rules.Add(strings.Count); strings.Add(vsb.ToString()); vsb = new ValueStringBuilder(vsbStack); } int slot = child.M; if (_caps != null && slot >= 0) { slot = (int)_caps[slot] !; } rules.Add(-Specials - 1 - slot); break; default: throw new ArgumentException(SR.ReplacementError); } } if (vsb.Length > 0) { rules.Add(strings.Count); strings.Add(vsb.ToString()); } Pattern = rep; _strings = strings; _rules = rules; }
internal RegexReplacement(string rep, RegexNode concat, System.Collections.Generic.Dictionary<object,object> _caps) { this._rep = rep; if (concat.Type() != 0x19) { throw new ArgumentException(RegExRes.GetString(0x25)); } StringBuilder builder = new StringBuilder(); ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode node = concat.Child(i); switch (node.Type()) { case 9: { builder.Append(node._ch); continue; } case 12: { builder.Append(node._str); continue; } case 13: { if (builder.Length > 0) { list2.Add(list.Count); list.Add(builder.ToString()); builder.Length = 0; } int num = node._m; if ((_caps != null) && (num >= 0)) { num = (int) _caps[num]; } list2.Add(-5 - num); continue; } } throw new ArgumentException(RegExRes.GetString(0x25)); } if (builder.Length > 0) { list2.Add(list.Count); list.Add(builder.ToString()); } this._strings = new string[list.Count]; list.CopyTo(0, this._strings, 0, list.Count); this._rules = new int[list2.Count]; for (int j = 0; j < list2.Count; j++) { this._rules[j] = (int) list2[j]; } }
/* * Since RegexReplacement shares the same parser as Regex, * the constructor takes a RegexNode which is a concatenation * of constant strings and backreferences. */ internal RegexReplacement(String rep, RegexNode concat, Dictionary<Int32, Int32> _caps) { StringBuilder sb; List<String> strings; List<Int32> rules; int slot; _rep = rep; if (concat.Type() != RegexNode.Concatenate) throw new ArgumentException(SR.ReplacementError); sb = new StringBuilder(); strings = new List<String>(); rules = new List<Int32>(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode child = concat.Child(i); switch (child.Type()) { case RegexNode.Multi: sb.Append(child._str); break; case RegexNode.One: sb.Append(child._ch); break; case RegexNode.Ref: if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); sb.Length = 0; } slot = child._m; if (_caps != null && slot >= 0) slot = (int)_caps[slot]; rules.Add(-Specials - 1 - slot); break; default: throw new ArgumentException(SR.ReplacementError); } } if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); } _strings = strings; _rules = rules; }
internal RegexNode ReduceGroup() { RegexNode node = this; while (node.Type() == 0x1d) { node = node.Child(0); } return(node); }
private readonly List<Int32> _rules; // negative -> group #, positive -> string # /// <summary> /// Since RegexReplacement shares the same parser as Regex, /// the constructor takes a RegexNode which is a concatenation /// of constant strings and backreferences. /// </summary> internal RegexReplacement(String rep, RegexNode concat, Dictionary<Int32, Int32> _caps) { if (concat.Type() != RegexNode.Concatenate) throw new ArgumentException(SR.ReplacementError); StringBuilder sb = StringBuilderCache.Acquire(); List<String> strings = new List<String>(); List<Int32> rules = new List<Int32>(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode child = concat.Child(i); switch (child.Type()) { case RegexNode.Multi: sb.Append(child._str); break; case RegexNode.One: sb.Append(child._ch); break; case RegexNode.Ref: if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); sb.Length = 0; } int slot = child._m; if (_caps != null && slot >= 0) slot = (int)_caps[slot]; rules.Add(-Specials - 1 - slot); break; default: throw new ArgumentException(SR.ReplacementError); } } if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); } StringBuilderCache.Release(sb); _rep = rep; _strings = strings; _rules = rules; }
internal RegexReplacement(string rep, RegexNode concat, Hashtable _caps) { this._rep = rep; if (concat.Type() != 0x19) { throw new ArgumentException(SR.GetString("ReplacementError")); } StringBuilder builder = new StringBuilder(); List <string> list = new List <string>(); List <int> list2 = new List <int>(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode node = concat.Child(i); switch (node.Type()) { case 9: { builder.Append(node._ch); continue; } case 12: { builder.Append(node._str); continue; } case 13: { if (builder.Length > 0) { list2.Add(list.Count); list.Add(builder.ToString()); builder.Length = 0; } int num = node._m; if ((_caps != null) && (num >= 0)) { num = (int)_caps[num]; } list2.Add(-5 - num); continue; } } throw new ArgumentException(SR.GetString("ReplacementError")); } if (builder.Length > 0) { list2.Add(list.Count); list.Add(builder.ToString()); } this._strings = list; this._rules = list2; }
private readonly List<string> _strings; // table of string constants #endregion Fields #region Constructors /// <summary> /// Since RegexReplacement shares the same parser as Regex, /// the constructor takes a RegexNode which is a concatenation /// of constant strings and backreferences. /// </summary> internal RegexReplacement(string rep, RegexNode concat, Hashtable _caps) { if (concat.Type() != RegexNode.Concatenate) throw new ArgumentException(SR.ReplacementError); StringBuilder sb = StringBuilderCache.Acquire(); List<string> strings = new List<string>(); List<int> rules = new List<int>(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode child = concat.Child(i); switch (child.Type()) { case RegexNode.Multi: sb.Append(child._str); break; case RegexNode.One: sb.Append(child._ch); break; case RegexNode.Ref: if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); sb.Length = 0; } int slot = child._m; if (_caps != null && slot >= 0) slot = (int)_caps[slot]; rules.Add(-Specials - 1 - slot); break; default: throw new ArgumentException(SR.ReplacementError); } } if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); } StringBuilderCache.Release(sb); _rep = rep; _strings = strings; _rules = rules; }
internal RegexNode ReduceRep() { RegexNode node = this; int num = this.Type(); int num2 = this._m; int num3 = this._n; while (true) { if (node.ChildCount() == 0) { break; } RegexNode node2 = node.Child(0); if (node2.Type() != num) { int num4 = node2.Type(); if ((((num4 < 3) || (num4 > 5)) || (num != 0x1a)) && (((num4 < 6) || (num4 > 8)) || (num != 0x1b))) { break; } } if (((node._m == 0) && (node2._m > 1)) || (node2._n < (node2._m * 2))) { break; } node = node2; if (node._m > 0) { node._m = num2 = ((0x7ffffffe / node._m) < num2) ? 0x7fffffff : (node._m * num2); } if (node._n > 0) { node._n = num3 = ((0x7ffffffe / node._n) < num3) ? 0x7fffffff : (node._n * num3); } } if (num2 != 0x7fffffff) { return(node); } return(new RegexNode(0x16, this._options)); }
internal RegexReplacement(string rep, RegexNode concat, Hashtable _caps) { this._rep = rep; if (concat.Type() != 0x19) { throw new ArgumentException(SR.GetString("ReplacementError")); } StringBuilder builder = new StringBuilder(); List<string> list = new List<string>(); List<int> list2 = new List<int>(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode node = concat.Child(i); switch (node.Type()) { case 9: { builder.Append(node._ch); continue; } case 12: { builder.Append(node._str); continue; } case 13: { if (builder.Length > 0) { list2.Add(list.Count); list.Add(builder.ToString()); builder.Length = 0; } int num = node._m; if ((_caps != null) && (num >= 0)) { num = (int) _caps[num]; } list2.Add(-5 - num); continue; } } throw new ArgumentException(SR.GetString("ReplacementError")); } if (builder.Length > 0) { list2.Add(list.Count); list.Add(builder.ToString()); } this._strings = list; this._rules = list2; }
/* * Since RegexReplacement shares the same parser as Regex, * the constructor takes a RegexNode which is a concatenation * of constant strings and backreferences. */ internal RegexReplacement(String rep, RegexNode concat, Hashtable _caps) { StringBuilder sb; ArrayList strings; ArrayList rules; int slot; _rep = rep; if (concat.Type() != RegexNode.Concatenate) { throw new ArgumentException(SR.GetString(SR.ReplacementError)); } sb = new StringBuilder(); strings = new ArrayList(); rules = new ArrayList(); for (int i = 0; i < concat.ChildCount(); i++) { RegexNode child = concat.Child(i); switch (child.Type()) { case RegexNode.Multi: sb.Append(child._str); break; case RegexNode.One: sb.Append(child._ch); break; case RegexNode.Ref: if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); sb.Length = 0; } slot = child._m; if (_caps != null && slot >= 0) { slot = (int)_caps[slot]; } rules.Add(-Specials - 1 - slot); break; default: throw new ArgumentException(SR.GetString(SR.ReplacementError)); } } if (sb.Length > 0) { rules.Add(strings.Count); strings.Add(sb.ToString()); } _strings = strings; _rules = rules; }
/* * Remember the pushed state (in response to a ')') */ internal void PopGroup() { _concatenation = _stack; _alternation = _concatenation._next; _group = _alternation._next; _stack = _group._next; // The first () inside a Testgroup group goes directly to the group if (_group.Type() == RegexNode.Testgroup && _group.ChildCount() == 0) { if (_unit == null) throw MakeException(SR.IllegalCondition); _group.AddChild(_unit); _unit = null; } }