예제 #1
0
        public string ReadString()
        {
            SkipWhitespace();
            Consume('"');
            List <Char> sb = new List <char>(100);

            while (_next != '"')
            {
                if (_next == '\\')
                {
                    Consume('\\'); //skip the escape
                    char ch = ReadChar();
                    switch (ch)
                    {
                    case 'b':
                        sb.Add('\b');
                        break;

                    case 'f':
                        sb.Add('\f');
                        break;

                    case 'n':
                        sb.Add('\n');
                        break;

                    case 'r':
                        sb.Add('\r');
                        break;

                    case 't':
                        sb.Add('\t');
                        break;

                    case 'u':
                    {
                        string hex = new string(new char[] { ReadChar(), ReadChar(), ReadChar(), ReadChar() });
                        int    result;
                        Assert(
                            FrameworkPortability.TryParseInt32(hex, NumberStyles.AllowHexSpecifier, FrameworkPortability.InvariantCulture,
                                                               out result),
                            "Expected a 4-character hex specifier.");
                        sb.Add((char)result);
                        break;
                    }

                    default:
                        sb.Add(ch);
                        break;
                    }
                }
                else
                {
                    Assert(_next != '\n' && _next != '\r' && _next != '\f' && _next != -1, '"');
                    sb.Add(ReadChar());
                }
            }
            Consume('"');
            return(new String(sb.ToArray()));
        }
        /// <summary>
        /// returns true if it was able to read a single value into the value reference.  The value
        /// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
        /// </summary>
        protected override bool ReadEnum(ref object value)
        {
            int    number;
            string temp;

            if (null != (temp = _input.GetAttribute("value")) && FrameworkPortability.TryParseInt32(temp, out number))
            {
                Skip();
                value = number;
                return(true);
            }
            return(base.ReadEnum(ref value));
        }
예제 #3
0
        /// <summary>
        /// returns true if it was able to read a single value into the value reference.  The value
        /// stored may be of type System.String, System.Int32, or an IEnumLite from the IEnumLiteMap.
        /// </summary>
        protected override bool ReadEnum(ref object value)
        {
            string text = null;

            if (ReadAsText(ref text, typeof(Enum)))
            {
                int number;
                if (FrameworkPortability.TryParseInt32(text, NumberStyles.Integer, FrameworkPortability.InvariantCulture, out number))
                {
                    value = number;
                    return(true);
                }
                value = text;
                return(true);
            }
            return(false);
        }