Пример #1
0
        internal static IEnumerable <KeyValuePair <string, string> > ParseKeyValuePairs(string text)
        {
            var    tokens = ParseTokenizer(text);
            bool   atKey  = true;
            string key    = null;
            string value  = null;

            foreach (var s in tokens)
            {
                switch (s)
                {
                case "=":
                    atKey = false;
                    if (key == null)
                    {
                        throw RuntimeFailure.PropertiesParseKeyNameExpected();
                    }
                    break;

                case ";":
                    atKey = true;
                    if (key != null)
                    {
                        yield return(new KeyValuePair <string, string>(key, value ?? string.Empty));

                        key = value = null;
                    }
                    break;

                default:
                    if (atKey)
                    {
                        key = s;
                    }
                    else
                    {
                        value = s;
                    }
                    break;
                }
            }

            if (key != null)
            {
                yield return(new KeyValuePair <string, string>(key, value ?? string.Empty));
            }
        }