Esempio n. 1
0
        private char UnEscapeUnicode()
        {
            var code = 0;

            for (var i = 0; i < 4; i++)
            {
                Consume();
                var ch = _nextChar;
                code <<= 4;
                if ('0' <= ch && ch <= '9')
                {
                    code += ch - '0';
                }
                else if ('a' <= ch && ch <= 'f')
                {
                    code += 10 + ch - 'a';
                }
                else if ('A' <= ch && ch <= 'F')
                {
                    code += 10 + ch - 'A';
                }
                else
                {
                    throw JsonParserException.InvalidError(string.Format("unicode escape '{0}'", ch), _position);
                }
            }
            return((char)code);
        }
Esempio n. 2
0
        private char UnEscape()
        {
            Consume();
            var ch = _nextChar;

            switch (ch)
            {
            case '\\':
            case '/':
            case '"':
                break;

            case 'b':
                ch = '\b';
                break;

            case 'f':
                ch = '\f';
                break;

            case 'n':
                ch = '\n';
                break;

            case 'r':
                ch = '\r';
                break;

            case 't':
                ch = '\t';
                break;

            case 'u':
                ch = UnEscapeUnicode();
                break;

            default:
                throw JsonParserException.InvalidError(string.Format("escape character '{0}'", ch), _position);
            }
            return(ch);
        }