Ejemplo n.º 1
0
        private static string ReadValue(string value, ref int pos)
        {
            int           startIndex    = pos;
            StringBuilder stringBuilder = new StringBuilder();

            while (pos < value.Length)
            {
                char c = value[pos];
                switch (c)
                {
                case ';':
                case '<':
                case '=':
                case '>':
                {
                    string text = Locale.GetText("Malformed value '{0}' contains '{1}' outside quotes.");
                    throw new FormatException(string.Format(text, value.Substring(startIndex), value[pos]));
                }

                default:
                    if (c != '"')
                    {
                        if (c == '#' || c == '+')
                        {
                            throw new NotImplementedException();
                        }
                        if (c == ',')
                        {
                            pos++;
                            return(stringBuilder.ToString());
                        }
                        if (c != '\\')
                        {
                            stringBuilder.Append(value[pos]);
                        }
                        else
                        {
                            pos = X501.ReadEscaped(stringBuilder, value, ++pos);
                        }
                    }
                    else
                    {
                        pos = X501.ReadQuoted(stringBuilder, value, ++pos);
                    }
                    pos++;
                    break;
                }
            }
            return(stringBuilder.ToString());
        }
Ejemplo n.º 2
0
        private static int ReadQuoted(StringBuilder sb, string value, int pos)
        {
            int startIndex = pos;

            while (pos <= value.Length)
            {
                char c = value[pos];
                if (c == '"')
                {
                    return(pos);
                }
                if (c == '\\')
                {
                    return(X501.ReadEscaped(sb, value, pos));
                }
                sb.Append(value[pos]);
                pos++;
            }
            string text = Locale.GetText("Malformed quoted value '{0}'.");

            throw new FormatException(string.Format(text, value.Substring(startIndex)));
        }