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());
        }
Ejemplo n.º 2
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)
            {
                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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 5
0
 public static void ReadAll(this IKeyValues values, Action <string, string> callback)
 {
     values.GetKeys().ToList().Each(key => callback(key, values.Get(key)));
 }
Ejemplo n.º 6
0
 public T Get(string key)
 {
     return(_inner.Get(_prefix + key));
 }