public string Match(ControlString controlString) { if (!Matches(controlString)) { throw new ArgumentException("Argument cannot be matched by this matcher.", nameof(controlString)); } return(matcher.Match(controlString)); }
public string Parse(string input) { if (input is null) { throw new System.ArgumentNullException(nameof(input)); } var controlStrings = finder.FindAllControlStrings(input); string result = input; foreach (var controlString in controlStrings) { if (matcher.Matches(controlString)) { var originalString = input.Substring(controlString.Index, controlString.Length); var specialPrepending = finder.FindPrependingSpecial(originalString.Substring(1, originalString.Length - 2)); var specialPostpending = finder.FindPostpendingSpecial(originalString.Substring(1, originalString.Length - 2)); var matchedString = matcher.Match(controlString); matchedString = string.IsNullOrEmpty(matchedString) ? matchedString : specialPrepending + matchedString + specialPostpending; foreach (var transformCode in controlString.Transformers) { if (!transformer.Matches(transformCode)) { throw new MissingTransformerException($"Could not find a transformer that matched the string {transformCode}"); } matchedString = transformer.Transform(transformCode, matchedString); } result = result.Replace(originalString, matchedString); } } return(result); }
public string Match(ControlString controlString) => matcher.Match(controlString);