Esempio n. 1
0
        private void EnterText(string line)
        {
            int equalsIndex = line.IndexOf('=');

            if (equalsIndex < 0)
            {
                throw RuntimeFailure.PropertyDeclarationMissingKey();
            }

            string newKey   = null;
            string newValue = null;

            if (equalsIndex == line.Length - 1)
            {
                newKey   = line.Substring(0, line.Length - 1);
                newValue = string.Empty;
            }
            else
            {
                newKey   = line.Substring(0, equalsIndex);
                newValue = line.Substring(equalsIndex + 1).Trim();
            }

            _key      = newKey;
            _value    = StringUnescaper.Unescape(newValue);
            _nodeKind = PropertyNodeKind.Property;
        }
Esempio n. 2
0
        static IEnumerable <string> ParseTokenizer(string text)
        {
            char          quoteChar = '\0';
            StringBuilder sb        = new StringBuilder();
            var           c         = ((IEnumerable <char>)text).GetEnumerator();

            while (c.MoveNext())
            {
                switch (c.Current)
                {
                case '\\':
                    sb.Append(StringUnescaper.UnescapeChar(c));
                    break;

                case '"':
                case '\'':
                    if (quoteChar == '\0')
                    {
                        quoteChar = c.Current;
                    }
                    else if (quoteChar == c.Current)
                    {
                        quoteChar = '\0';
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case '=':
                case ';':
                    if (quoteChar != '\0')
                    {
                        goto default;
                    }

                    if (sb.Length > 0)
                    {
                        yield return(sb.ToString());

                        sb.Length = 0;
                    }
                    yield return((c.Current == ';') ? ";" : "=");

                    break;

                default:
                    sb.Append(c.Current);
                    break;
                }
            }
            if (sb.Length > 0)
            {
                yield return(sb.ToString());
            }
        }