static string parse(string template, IKeyValues values) { var matches = TemplateExpression.Matches(template); if (matches.Count == 0) { return(template); } var lastIndex = 0; var builder = new StringBuilder(); foreach (Match match in matches) { var key = match.Groups[TemplateGroup].Value; if ((lastIndex == 0 || match.Index > lastIndex) && values.ContainsKey(key)) { builder.Append(template.Substring(lastIndex, match.Index - lastIndex)); builder.Append(values.Get(key)); } lastIndex = match.Index + match.Length; } if (lastIndex < template.Length) { builder.Append(template.Substring(lastIndex, template.Length - lastIndex)); } return(builder.ToString()); }
static string parse(string template, IKeyValues values) { var matches = TemplateExpression.Matches(template); if (matches.Count == 0) return template; var lastIndex = 0; var builder = new StringBuilder(); foreach (Match match in matches) { var key = match.Groups[TemplateGroup].Value; if ((lastIndex == 0 || match.Index > lastIndex) && values.ContainsKey(key)) { builder.Append(template.Substring(lastIndex, match.Index - lastIndex)); builder.Append(values.Get(key)); } lastIndex = match.Index + match.Length; } if (lastIndex < template.Length) { builder.Append(template.Substring(lastIndex, template.Length - lastIndex)); } return builder.ToString(); }