internal static int OpcodeSize(int Opcode) { Opcode &= 0x3f; switch (Opcode) { case 0: case 1: case 3: case 4: case 6: case 7: return(3); case 2: case 5: case 8: return(4); case 9: case 10: case 12: case 13: case 0x17: case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x25: case 0x26: case 0x27: return(2); case 11: case 0x1c: case 0x1d: case 0x20: return(3); case 14: case 15: case 0x10: case 0x11: case 0x12: case 0x13: case 20: case 0x15: case 0x16: case 30: case 0x1f: case 0x21: case 0x22: case 0x23: case 0x24: case 40: case 0x29: case 0x2a: return(1); } throw MakeException(RegExRes.GetString(4, Opcode.ToString())); }
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]; } }
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)); }
internal void EmitFragment(int nodetype, RegexNode node, int CurIndex) { int num = 0; if (nodetype <= 13) { if (node.UseOptionR()) { num |= 0x40; } if ((node._options & RegexOptions.IgnoreCase) != RegexOptions.None) { num |= 0x200; } } int num8 = nodetype; switch (num8) { case 3: case 4: case 6: case 7: if (node._m > 0) { this.Emit((((node._type == 3) || (node._type == 6)) ? 0 : 1) | num, node._ch, node._m); } if (node._n > node._m) { this.Emit(node._type | num, node._ch, (node._n == 0x7fffffff) ? 0x7fffffff : (node._n - node._m)); } return; case 5: case 8: if (node._m > 0) { this.Emit(2 | num, this.StringCode(node._str), this.StringCode(node._str2), node._m); } if (node._n > node._m) { this.Emit(node._type | num, this.StringCode(node._str), this.StringCode(node._str2), (node._n == 0x7fffffff) ? 0x7fffffff : (node._n - node._m)); } return; case 9: case 10: this.Emit(node._type | num, node._ch); return; case 11: this.Emit(node._type | num, this.StringCode(node._str), this.StringCode(node._str2)); return; case 12: this.Emit(node._type | num, this.StringCode(node._str)); return; case 13: this.Emit(node._type | num, this.MapCapnum(node._m)); return; case 14: case 15: case 0x10: case 0x11: case 0x12: case 0x13: case 20: case 0x15: case 0x16: case 0x29: case 0x2a: this.Emit(node._type); return; case 0x17: case 0x59: case 0x5d: case 0x99: case 0x9d: return; case 0x58: if (CurIndex < (node._children.Count - 1)) { this.PushInt(this.CurPos()); this.Emit(0x17, 0); } return; case 90: case 0x5b: if ((node._n >= 0x7fffffff) && (node._m <= 1)) { this.Emit((node._m == 0) ? 30 : 0x1f); } else { this.Emit((node._m == 0) ? 0x1a : 0x1b, (node._m == 0) ? 0 : (1 - node._m)); } if (node._m == 0) { this.PushInt(this.CurPos()); this.Emit(0x26, 0); } this.PushInt(this.CurPos()); return; case 0x5c: this.Emit(0x1f); return; case 0x5e: this.Emit(0x22); this.Emit(0x1f); return; case 0x5f: this.Emit(0x22); this.PushInt(this.CurPos()); this.Emit(0x17, 0); return; case 0x60: this.Emit(0x22); return; case 0x61: num8 = CurIndex; if (num8 == 0) { this.Emit(0x22); this.PushInt(this.CurPos()); this.Emit(0x17, 0); this.Emit(0x25, this.MapCapnum(node._m)); this.Emit(0x24); return; } return; case 0x62: num8 = CurIndex; if (num8 == 0) { this.Emit(0x22); this.Emit(0x1f); this.PushInt(this.CurPos()); this.Emit(0x17, 0); return; } return; case 0x98: { if (CurIndex >= (node._children.Count - 1)) { for (int i = 0; i < CurIndex; i++) { this.PatchJump(this.PopInt(), this.CurPos()); } return; } int offset = this.PopInt(); this.PushInt(this.CurPos()); this.Emit(0x26, 0); this.PatchJump(offset, this.CurPos()); return; } case 0x9a: case 0x9b: { int jumpDest = this.CurPos(); int num7 = nodetype - 0x9a; if ((node._n >= 0x7fffffff) && (node._m <= 1)) { this.Emit(0x18 + num7, this.PopInt()); } else { this.Emit(0x1c + num7, this.PopInt(), (node._n == 0x7fffffff) ? 0x7fffffff : (node._n - node._m)); } if (node._m == 0) { this.PatchJump(this.PopInt(), jumpDest); } return; } case 0x9c: this.Emit(0x20, this.MapCapnum(node._m), this.MapCapnum(node._n)); return; case 0x9e: this.Emit(0x21); this.Emit(0x24); return; case 0x9f: this.Emit(0x23); this.PatchJump(this.PopInt(), this.CurPos()); this.Emit(0x24); return; case 160: this.Emit(0x24); return; case 0xa1: switch (CurIndex) { case 0: { int num4 = this.PopInt(); this.PushInt(this.CurPos()); this.Emit(0x26, 0); this.PatchJump(num4, this.CurPos()); this.Emit(0x24); if (node._children.Count > 1) { return; } break; } } return; case 0xa2: switch (CurIndex) { case 0: this.Emit(0x21); this.Emit(0x24); return; case 1: { int num5 = this.PopInt(); this.PushInt(this.CurPos()); this.Emit(0x26, 0); this.PatchJump(num5, this.CurPos()); this.Emit(0x21); this.Emit(0x24); if (node._children.Count > 2) { return; } goto Label_0312; } case 2: goto Label_0312; } return; default: throw MakeException(RegExRes.GetString(4, nodetype.ToString())); } this.PatchJump(this.PopInt(), this.CurPos()); return; Label_0312: this.PatchJump(this.PopInt(), this.CurPos()); }
internal void CalculateFC(int NodeType, RegexNode node, int CurIndex) { bool caseInsensitive = false; bool flag2 = false; if (NodeType <= 13) { if ((node._options & RegexOptions.IgnoreCase) != RegexOptions.None) { caseInsensitive = true; } if ((node._options & RegexOptions.RightToLeft) != RegexOptions.None) { flag2 = true; } } switch (NodeType) { case 3: case 6: this.PushFC(new RegexFC(node._ch, false, node._m == 0, caseInsensitive)); return; case 4: case 7: this.PushFC(new RegexFC(node._ch, true, node._m == 0, caseInsensitive)); return; case 5: case 8: this.PushFC(new RegexFC(node._str, true, caseInsensitive)); return; case 9: case 10: this.PushFC(new RegexFC(node._ch, NodeType == 10, false, caseInsensitive)); return; case 11: this.PushFC(new RegexFC(node._str, (node._str2 != null) && (node._str2.Length != 0), caseInsensitive)); return; case 12: if (node._str.Length != 0) { if (!flag2) { this.PushFC(new RegexFC(node._str[0], false, false, caseInsensitive)); return; } this.PushFC(new RegexFC(node._str[node._str.Length - 1], false, false, caseInsensitive)); return; } this.PushFC(new RegexFC(true)); return; case 13: this.PushFC(new RegexFC("\0", true, false)); return; case 14: case 15: case 0x10: case 0x11: case 0x12: case 0x13: case 20: case 0x15: case 0x16: case 0x29: case 0x2a: this.PushFC(new RegexFC(true)); return; case 0x17: this.PushFC(new RegexFC(true)); return; case 0x58: case 0x59: case 90: case 0x5b: case 0x5c: case 0x5d: case 0x60: case 0x61: case 0x9c: case 0x9d: case 0x9e: case 0x9f: case 160: return; case 0x5e: case 0x5f: this.SkipChild(); this.PushFC(new RegexFC(true)); return; case 0x62: if (CurIndex == 0) { this.SkipChild(); } return; case 0x98: case 0xa1: if (CurIndex != 0) { RegexFC fc = this.PopFC(); this.TopFC().AddFC(fc, false); } return; case 0x99: if (CurIndex != 0) { RegexFC xfc = this.PopFC(); this.TopFC().AddFC(xfc, true); } if (!this.TopFC()._nullable) { this.EarlyExit(); } return; case 0x9a: case 0x9b: if (node._m == 0) { this.TopFC()._nullable = true; } return; case 0xa2: if (CurIndex > 1) { RegexFC xfc3 = this.PopFC(); this.TopFC().AddFC(xfc3, false); } return; } throw new ArgumentException(RegExRes.GetString(4, NodeType.ToString())); }
protected override void Go() { this.Goto(0); Label_0007: switch (this.Operator()) { case 0: { int num12 = this.Operand(1); if (this.Forwardchars() < num12) { goto Label_0EA3; } char ch = (char)this.Operand(0); while (num12-- > 0) { if (this.Forwardcharnext() != ch) { goto Label_0EA3; } } this.Advance(2); goto Label_0007; } case 1: { int num13 = this.Operand(1); if (this.Forwardchars() < num13) { goto Label_0EA3; } char ch2 = (char)this.Operand(0); while (num13-- > 0) { if (this.Forwardcharnext() == ch2) { goto Label_0EA3; } } this.Advance(2); goto Label_0007; } case 2: { int num14 = this.Operand(2); if (this.Forwardchars() < num14) { goto Label_0EA3; } string set = this.runstrings[this.Operand(0)]; string category = this.runstrings[this.Operand(1)]; while (num14-- > 0) { if (!RegexCharClass.CharInSet(this.Forwardcharnext(), set, category)) { goto Label_0EA3; } } this.Advance(3); goto Label_0007; } case 3: { int num15 = this.Operand(1); if (num15 > this.Forwardchars()) { num15 = this.Forwardchars(); } char ch3 = (char)this.Operand(0); int num16 = num15; while (num16 > 0) { if (this.Forwardcharnext() != ch3) { this.Backwardnext(); break; } num16--; } if (num15 > num16) { this.Track((num15 - num16) - 1, this.Textpos() - this.Bump()); } this.Advance(2); goto Label_0007; } case 4: { int num17 = this.Operand(1); if (num17 > this.Forwardchars()) { num17 = this.Forwardchars(); } char ch4 = (char)this.Operand(0); int num18 = num17; while (num18 > 0) { if (this.Forwardcharnext() == ch4) { this.Backwardnext(); break; } num18--; } if (num17 > num18) { this.Track((num17 - num18) - 1, this.Textpos() - this.Bump()); } this.Advance(2); goto Label_0007; } case 5: { int num19 = this.Operand(2); if (num19 > this.Forwardchars()) { num19 = this.Forwardchars(); } string str3 = this.runstrings[this.Operand(0)]; string str4 = this.runstrings[this.Operand(1)]; int num20 = num19; while (num20 > 0) { if (!RegexCharClass.CharInSet(this.Forwardcharnext(), str3, str4)) { this.Backwardnext(); break; } num20--; } if (num19 > num20) { this.Track((num19 - num20) - 1, this.Textpos() - this.Bump()); } this.Advance(3); goto Label_0007; } case 6: case 7: { int num25 = this.Operand(1); if (num25 > this.Forwardchars()) { num25 = this.Forwardchars(); } if (num25 > 0) { this.Track(num25 - 1, this.Textpos()); } this.Advance(2); goto Label_0007; } case 8: { int num26 = this.Operand(2); if (num26 > this.Forwardchars()) { num26 = this.Forwardchars(); } if (num26 > 0) { this.Track(num26 - 1, this.Textpos()); } this.Advance(3); goto Label_0007; } case 9: if ((this.Forwardchars() < 1) || (this.Forwardcharnext() != ((char)this.Operand(0)))) { goto Label_0EA3; } this.Advance(1); goto Label_0007; case 10: if ((this.Forwardchars() < 1) || (this.Forwardcharnext() == ((char)this.Operand(0)))) { goto Label_0EA3; } this.Advance(1); goto Label_0007; case 11: if ((this.Forwardchars() < 1) || !RegexCharClass.CharInSet(this.Forwardcharnext(), this.runstrings[this.Operand(0)], this.runstrings[this.Operand(1)])) { goto Label_0EA3; } this.Advance(2); goto Label_0007; case 12: if (!this.Stringmatch(this.runstrings[this.Operand(0)])) { goto Label_0EA3; } this.Advance(1); goto Label_0007; case 13: { int cap = this.Operand(0); if (!base.IsMatched(cap)) { if ((base.runregex.roptions & RegexOptions.ECMAScript) == RegexOptions.None) { goto Label_0EA3; } goto Label_0A06; } if (this.Refmatch(base.MatchIndex(cap), base.MatchLength(cap))) { goto Label_0A06; } goto Label_0EA3; } case 14: if ((this.Leftchars() > 0) && (this.CharAt(this.Textpos() - 1) != '\n')) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 15: if ((this.Rightchars() > 0) && (this.CharAt(this.Textpos()) != '\n')) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 0x10: if (!base.IsBoundary(this.Textpos(), base.runtextbeg, base.runtextend)) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 0x11: if (base.IsBoundary(this.Textpos(), base.runtextbeg, base.runtextend)) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 0x12: if (this.Leftchars() > 0) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 0x13: if (this.Textpos() != this.Textstart()) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 20: if ((this.Rightchars() > 1) || ((this.Rightchars() == 1) && (this.CharAt(this.Textpos()) != '\n'))) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 0x15: if (this.Rightchars() > 0) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 0x16: goto Label_0EA3; case 0x17: this.Track(this.Textpos()); this.Advance(1); goto Label_0007; case 0x18: this.Stackframe(1); if ((this.Textpos() - this.Stacked(0)) == 0) { this.Track2(this.Stacked(0)); this.Advance(1); } else { this.Track(this.Stacked(0), this.Textpos()); this.Stack(this.Textpos()); this.Goto(this.Operand(0)); } goto Label_0007; case 0x19: this.Stackframe(1); if ((this.Textpos() - this.Stacked(0)) == 0) { this.Track2(this.Stacked(0)); break; } this.Track(this.Stacked(0), this.Textpos()); break; case 0x1a: this.Stack(-1, this.Operand(0)); this.Track(); this.Advance(1); goto Label_0007; case 0x1b: this.Stack(this.Textpos(), this.Operand(0)); this.Track(); this.Advance(1); goto Label_0007; case 0x1c: { this.Stackframe(2); int num4 = this.Stacked(0); int num5 = this.Stacked(1); int num6 = this.Textpos() - num4; if ((num5 < this.Operand(1)) && ((num6 != 0) || (num5 < 0))) { this.Track(num4); this.Stack(this.Textpos(), num5 + 1); this.Goto(this.Operand(0)); } else { this.Track2(num4, num5); this.Advance(2); } goto Label_0007; } case 0x1d: { this.Stackframe(2); int num7 = this.Stacked(0); int num8 = this.Stacked(1); if (num8 >= 0) { this.Track(num7, num8, this.Textpos()); this.Advance(2); } else { this.Track2(num7); this.Stack(this.Textpos(), num8 + 1); this.Goto(this.Operand(0)); } goto Label_0007; } case 30: this.Stack(-1); this.Track(); this.Advance(); goto Label_0007; case 0x1f: this.Stack(this.Textpos()); this.Track(); this.Advance(); goto Label_0007; case 0x20: if ((this.Operand(1) != -1) && !base.IsMatched(this.Operand(1))) { goto Label_0EA3; } this.Stackframe(1); if (this.Operand(1) != -1) { base.TransferCapture(this.Operand(0), this.Operand(1), this.Stacked(0), this.Textpos()); } else { base.Capture(this.Operand(0), this.Stacked(0), this.Textpos()); } this.Track(this.Stacked(0)); this.Advance(2); goto Label_0007; case 0x21: this.Stackframe(1); this.Track(this.Stacked(0)); this.Textto(this.Stacked(0)); this.Advance(); goto Label_0007; case 0x22: this.Stack(this.Trackpos(), base.Crawlpos()); this.Track(); this.Advance(); goto Label_0007; case 0x23: this.Stackframe(2); this.Trackto(this.Stacked(0)); while (base.Crawlpos() != this.Stacked(1)) { base.Uncapture(); } goto Label_0EA3; case 0x24: this.Stackframe(2); this.Trackto(this.Stacked(0)); this.Track(this.Stacked(1)); this.Advance(); goto Label_0007; case 0x25: if (!base.IsMatched(this.Operand(0))) { goto Label_0EA3; } this.Advance(1); goto Label_0007; case 0x26: this.Goto(this.Operand(0)); goto Label_0007; case 40: return; case 0x29: if (!base.IsECMABoundary(this.Textpos(), base.runtextbeg, base.runtextend)) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 0x2a: if (base.IsECMABoundary(this.Textpos(), base.runtextbeg, base.runtextend)) { goto Label_0EA3; } this.Advance(); goto Label_0007; case 0x83: case 0x84: { this.Trackframe(2); int num21 = this.Tracked(0); int newpos = this.Tracked(1); this.Textto(newpos); if (num21 > 0) { this.Track(num21 - 1, newpos - this.Bump()); } this.Advance(2); goto Label_0007; } case 0x85: { this.Trackframe(2); int num23 = this.Tracked(0); int num24 = this.Tracked(1); this.Textto(num24); if (num23 > 0) { this.Track(num23 - 1, num24 - this.Bump()); } this.Advance(3); goto Label_0007; } case 0x86: { this.Trackframe(2); int num27 = this.Tracked(1); this.Textto(num27); if (this.Forwardcharnext() != ((char)this.Operand(0))) { goto Label_0EA3; } int num28 = this.Tracked(0); if (num28 > 0) { this.Track(num28 - 1, num27 + this.Bump()); } this.Advance(2); goto Label_0007; } case 0x87: { this.Trackframe(2); int num29 = this.Tracked(1); this.Textto(num29); if (this.Forwardcharnext() == ((char)this.Operand(0))) { goto Label_0EA3; } int num30 = this.Tracked(0); if (num30 > 0) { this.Track(num30 - 1, num29 + this.Bump()); } this.Advance(2); goto Label_0007; } case 0x88: { this.Trackframe(2); int num31 = this.Tracked(1); this.Textto(num31); if (!RegexCharClass.CharInSet(this.Forwardcharnext(), this.runstrings[this.Operand(0)], this.runstrings[this.Operand(1)])) { goto Label_0EA3; } int num32 = this.Tracked(0); if (num32 > 0) { this.Track(num32 - 1, num31 + this.Bump()); } this.Advance(3); goto Label_0007; } case 0x97: this.Trackframe(1); this.Textto(this.Tracked(0)); this.Goto(this.Operand(0)); goto Label_0007; case 0x98: this.Trackframe(2); this.Stackframe(1); this.Textto(this.Tracked(1)); this.Track2(this.Tracked(0)); this.Advance(1); goto Label_0007; case 0x99: { this.Trackframe(2); int num3 = this.Tracked(1); this.Track2(this.Tracked(0)); this.Stack(num3); this.Textto(num3); this.Goto(this.Operand(0)); goto Label_0007; } case 0x9a: this.Stackframe(2); goto Label_0EA3; case 0x9b: this.Stackframe(2); goto Label_0EA3; case 0x9c: this.Trackframe(1); this.Stackframe(2); if (this.Stacked(1) <= 0) { this.Stack(this.Tracked(0), this.Stacked(1) - 1); goto Label_0EA3; } this.Textto(this.Stacked(0)); this.Track2(this.Tracked(0), this.Stacked(1) - 1); this.Advance(2); goto Label_0007; case 0x9d: { this.Trackframe(3); int num9 = this.Tracked(0); int num10 = this.Tracked(2); if ((this.Tracked(1) > this.Operand(1)) || (num10 == num9)) { this.Stack(this.Tracked(0), this.Tracked(1)); goto Label_0EA3; } this.Textto(num10); this.Stack(num10, this.Tracked(1) + 1); this.Track2(num9); this.Goto(this.Operand(0)); goto Label_0007; } case 0x9e: case 0x9f: this.Stackframe(1); goto Label_0EA3; case 160: this.Trackframe(1); this.Stack(this.Tracked(0)); base.Uncapture(); if ((this.Operand(0) != -1) && (this.Operand(1) != -1)) { base.Uncapture(); } goto Label_0EA3; case 0xa1: this.Trackframe(1); this.Stack(this.Tracked(0)); goto Label_0EA3; case 0xa2: this.Stackframe(2); goto Label_0EA3; case 0xa4: this.Trackframe(1); while (base.Crawlpos() != this.Tracked(0)) { base.Uncapture(); } goto Label_0EA3; case 280: this.Trackframe(1); this.Stack(this.Tracked(0)); goto Label_0EA3; case 0x119: this.Stackframe(1); this.Trackframe(1); this.Stack(this.Tracked(0)); goto Label_0EA3; case 0x11c: this.Trackframe(2); this.Stack(this.Tracked(0), this.Tracked(1)); goto Label_0EA3; case 0x11d: this.Trackframe(1); this.Stackframe(2); this.Stack(this.Tracked(0), this.Stacked(1) - 1); goto Label_0EA3; default: throw new Exception(RegExRes.GetString(3)); } this.Advance(1); goto Label_0007; Label_0A06: this.Advance(1); goto Label_0007; Label_0EA3: this.Backtrack(); goto Label_0007; }