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