// This static call constructs a RegexTree from a regular expression // pattern string and an option string. // // The method creates, drives, and drops a parser instance. internal static RegexTree Parse(String re, RegexOptions op) { RegexParser p; RegexNode root; String[] capnamelist; p = new RegexParser((op & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture); p._options = op; p.SetPattern(re); p.CountCaptures(); p.Reset(op); root = p.ScanRegex(); if (p._capnamelist == null) capnamelist = null; else capnamelist = (String[])p._capnamelist.ToArray(typeof(String)); return new RegexTree(root, p._caps, p._capnumlist, p._captop, p._capnames, capnamelist, op); }
internal static RegexReplacement ParseReplacement(string rep, Hashtable caps, int capsize, Hashtable capnames, RegexOptions op) { RegexParser parser = new RegexParser(((op & RegexOptions.CultureInvariant) != RegexOptions.None) ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture) { _options = op }; parser.NoteCaptures(caps, capsize, capnames); parser.SetPattern(rep); return new RegexReplacement(rep, parser.ScanReplacement(), caps); }
internal static RegexTree Parse(string re, RegexOptions op) { string[] strArray; RegexParser parser = new RegexParser(((op & RegexOptions.CultureInvariant) != RegexOptions.None) ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture) { _options = op }; parser.SetPattern(re); parser.CountCaptures(); parser.Reset(op); RegexNode root = parser.ScanRegex(); if (parser._capnamelist == null) { strArray = null; } else { strArray = parser._capnamelist.ToArray(); } return new RegexTree(root, parser._caps, parser._capnumlist, parser._captop, parser._capnames, strArray, op); }
internal static string Unescape(string input) { for (int i = 0; i < input.Length; i++) { if (input[i] == '\\') { StringBuilder builder = new StringBuilder(); RegexParser parser = new RegexParser(CultureInfo.InvariantCulture); parser.SetPattern(input); builder.Append(input, 0, i); do { i++; parser.Textto(i); if (i < input.Length) { builder.Append(parser.ScanCharEscape()); } i = parser.Textpos(); int startIndex = i; while ((i < input.Length) && (input[i] != '\\')) { i++; } builder.Append(input, startIndex, i - startIndex); } while (i < input.Length); return builder.ToString(); } } return input; }
/* * This static call constructs a flat concatenation node given * a replacement pattern. */ internal static RegexReplacement ParseReplacement(String rep, Hashtable caps, int capsize, Hashtable capnames, RegexOptions op) { RegexParser p; RegexNode root; p = new RegexParser((op & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture); p._options = op; p.NoteCaptures(caps, capsize, capnames); p.SetPattern(rep); root = p.ScanReplacement(); return new RegexReplacement(rep, root, caps); }
/* * Escapes all metacharacters (including (,),[,],{,},|,^,$,*,+,?,\, spaces and #) */ internal static String Unescape(String input) { for (int i = 0; i < input.Length; i++) { if (input[i] == '\\') { StringBuilder sb = StringBuilderCache.Acquire(); RegexParser p = new RegexParser(CultureInfo.InvariantCulture); int lastpos; p.SetPattern(input); sb.Append(input, 0, i); do { i++; p.Textto(i); if (i < input.Length) sb.Append(p.ScanCharEscape()); i = p.Textpos(); lastpos = i; while (i < input.Length && input[i] != '\\') i++; sb.Append(input, lastpos, i - lastpos); } while (i < input.Length); return StringBuilderCache.GetStringAndRelease(sb); } } return input; }
internal static RegexReplacement ParseReplacement(string rep, System.Collections.Generic.Dictionary<object,object> caps, int capsize, System.Collections.Generic.Dictionary<object,object> capnames, RegexOptions op) { RegexParser parser = new RegexParser(((op & RegexOptions.CultureInvariant) != RegexOptions.None) ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture); parser.NoteCaptures(caps, capsize, capnames); parser.SetPattern(rep); return new RegexReplacement(rep, parser.ScanReplacement(), caps); }