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.Has(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.Has(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());
        }
Exemple #3
0
        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)
            {
                builder.Append(template.Substring(lastIndex, match.Index - lastIndex));

                var key = match.Groups[TemplateGroup].Value;
                if ((lastIndex == 0 || match.Index > lastIndex) && values.Has(key))
                {
                    builder.Append(values.Get(key));
                }
                else
                {
                    builder.Append("{{" + key + "}}"); // escape the missing key so that the while loop ContainsTemplate will terminate
                }

                lastIndex = match.Index + match.Length;
            }

            if (lastIndex < template.Length)
            {
                builder.Append(template.Substring(lastIndex, template.Length - lastIndex));
            }

            return builder.ToString();
        }
Exemple #4
0
        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)
            {
                builder.Append(template.Substring(lastIndex, match.Index - lastIndex));

                var key = match.Groups[TemplateGroup].Value;
                if ((lastIndex == 0 || match.Index > lastIndex) && values.Has(key))
                {
                    builder.Append(values.Get(key));
                }
                else
                {
                    builder.Append("{{" + key + "}}"); // escape the missing key so that the while loop ContainsTemplate will terminate
                }

                lastIndex = match.Index + match.Length;
            }

            if (lastIndex < template.Length)
            {
                builder.Append(template.Substring(lastIndex, template.Length - lastIndex));
            }

            return(builder.ToString());
        }
 public bool Has(string key)
 {
     return(_inner.Has(_prefix + key));
 }