System.Runtime.Serialization.Json.JavaScriptReader.ReadStringLiteral C# (CSharp) Method

ReadStringLiteral() private method

private ReadStringLiteral ( ) : string
return string
        private string ReadStringLiteral()
        {
            if (PeekChar() != '"')
            {
                throw JsonError(SR.ArgumentException_InvalidLiteralFormat);
            }

            ReadChar();
            _vb.Length = 0;
            while (true)
            {
                int c = ReadChar();
                if (c < 0)
                {
                    throw JsonError(SR.ArgumentException_StringNotClosed);
                }

                if (c == '"')
                {
                    return _vb.ToString();
                }
                else if (c != '\\')
                {
                    _vb.Append((char)c);
                    continue;
                }

                // escaped expression
                c = ReadChar();
                if (c < 0)
                {
                    throw JsonError(SR.ArgumentException_IncompleteEscapeSequence);
                }
                switch (c)
                {
                    case '"':
                    case '\\':
                    case '/':
                        _vb.Append((char)c);
                        break;
                    case 'b':
                        _vb.Append('\x8');
                        break;
                    case 'f':
                        _vb.Append('\f');
                        break;
                    case 'n':
                        _vb.Append('\n');
                        break;
                    case 'r':
                        _vb.Append('\r');
                        break;
                    case 't':
                        _vb.Append('\t');
                        break;
                    case 'u':
                        ushort cp = 0;
                        for (int i = 0; i < 4; i++)
                        {
                            cp <<= 4;
                            if ((c = ReadChar()) < 0)
                            {
                                throw JsonError(SR.ArgumentException_IncompleteEscapeLiteral);
                            }

                            if ('0' <= c && c <= '9')
                            {
                                cp += (ushort)(c - '0');
                            }
                            if ('A' <= c && c <= 'F')
                            {
                                cp += (ushort)(c - 'A' + 10);
                            }
                            if ('a' <= c && c <= 'f')
                            {
                                cp += (ushort)(c - 'a' + 10);
                            }
                        }
                        _vb.Append((char)cp);
                        break;
                    default:
                        throw JsonError(SR.ArgumentException_UnexpectedEscapeCharacter);
                }
            }
        }