public RegexFormatter(Rule rule) { this.rule = rule; var options = RegexOptions.Compiled; if(!this.rule.CaseSensitive) { options |= RegexOptions.IgnoreCase; } this.regex = new Regex(this.rule.Pattern, options); }
internal static IFormatter GetFormatter(IConfig config) { var formatters = new CompositeFormatter(); string[] patterns = config.GetAttributeArray(".", "rule", "pattern"); foreach(string pattern in patterns) { string replacement = config.GetAttribute(".", string.Format("rule[@pattern='{0}']", pattern), "replacement"); bool caseSensitive = false; if(config.ContainsAttribute(".", string.Format("rule[@pattern='{0}']", pattern), "caseSensitive")) { caseSensitive = config.GetAttribute<bool>(".", string.Format("rule[@pattern='{0}']", pattern), "caseSensitive"); } var rule = new Rule(pattern, replacement, caseSensitive); var ruleFormatter = new RegexFormatter(rule); formatters.Add(ruleFormatter); } return formatters; }