public RegexReplaceConverterHook(ConverterHookType type, RegexReplaceRule rule) { if (rule == null) { throw new ArgumentNullException("rule"); } this.Type = type; this.Rule = rule; }
private static string ApplyRule(string input, RegexReplaceRule rule) { if (input == null) { throw new ArgumentNullException("input"); } if (rule.Pattern == null) { return input; } var regex = new Regex(rule.Pattern, rule.Options); string result = (rule.Replace != null) ? regex.Replace(input, rule.Replace) : input; result = rule.ApplyFactory(result); if (rule.ChildRules.Any()) { result = regex.Replace( result, match => { string childResult = (match.Groups.Count > 1) ? match.Groups[1].Value : match.Value; foreach (var childRule in rule.ChildRules) { childResult = childRule.Apply(childResult); } return childResult; }); } return result; }