private static List <FilterItem> GetFilters(string input, Match match, ReplaceTemplateItem item) { List <FilterItem> lstFilter = new List <FilterItem>(); foreach (DataRow drWhen in item.When) { bool action = false; if (drWhen.IsNull("action")) { action = (bool)drWhen.Table.Columns["action"].DefaultValue; } else { action = (bool)drWhen["action"]; } string pattern = ReplaceUtils.GetRegexPattern(drWhen); //pattern = ReplaceReference.Reference(pattern, match); RegexOptions options = ReplaceUtils.GetRegexOptions(drWhen); Regex reg = new Regex(pattern, options); if (reg != null) { GetFilters(input, reg, action, lstFilter); } } return(lstFilter); }
public void CanReplace(Match result) { foreach (DataRow drWhen in this.When) { Regex wFinder = ReplaceUtils.GetRegex(drWhen); } }
private ReplaceTemplate GetTemplate(DataRow drTemplate, string templateName) { ReplaceTemplate template = new ReplaceTemplate(templateName); foreach (DataRow row in drTemplate.GetChildRows("template_item")) { template.Items.Add(ReplaceUtils.GetTemplateItem(row)); } return(template); }
/// <summary> /// string Reference Dictionary<name, value>. /// </summary> /// <param name="input"></param> /// <param name="pattern"></param> /// <param name="args"></param> /// <returns></returns> public static string Reference(string input, string pattern, Dictionary <string, string> args) { MatchCollection matches = Regex.Matches(input, pattern); Dictionary <Capture, string> map = new Dictionary <Capture, string>(); foreach (Match mt in matches) { string key = mt.Groups[1].Value; if (!args.ContainsKey(key)) { continue; } map[mt] = args[key]; } return(ReplaceUtils.GetReplaced(input, map)); }
/// <summary> /// Trim Reference to Const Strings. /// <remarks> /// e.g /// [$ABCD$] => ABCD /// </remarks> /// </summary> /// <param name="input">Trim Object</param> /// <returns>real string</returns> public static string Reference(string input) { // ============================================== string refconst = Parameters.Instance["refconst"]; if (string.IsNullOrEmpty(refconst)) { return(input); } Dictionary <Capture, string> map = new Dictionary <Capture, string>(); MatchCollection matches = Regex.Matches(input, refconst); foreach (Match mt in matches) { map[mt] = mt.Groups[1].Value; } return(ReplaceUtils.GetReplaced(input, map)); }
public static string Reference(string input, Match match) { // ============================================== // First: Reference Match Group, get groupindex \{\$(\d+)\$\} string pattern = Parameters.Instance["refmatch"]; if (string.IsNullOrEmpty(pattern)) { return(input); } Dictionary <Capture, string> map = new Dictionary <Capture, string>(); MatchCollection matches = Regex.Matches(input, pattern); foreach (Match mt in matches) { int idx = int.Parse(mt.Groups[1].Value); map[mt] = match.Groups[idx].Value; } return(ReplaceUtils.GetReplaced(input, map)); }