void JSON_Parser::GetNextToken()

in Include/json_cpp/details/json_parsing.hpp [864:962]


void JSON_Parser<CharType>::GetNextToken(typename JSON_Parser<CharType>::Token& result)
{
try_again:
    auto ch = EatWhitespace();

    CreateToken(result, Token::TKN_EOF);

    if (ch == eof<CharType>()) return;

    switch (ch)
    {
    case '{':
    case '[':
        {
            if(++m_currentParsingDepth > JSON_Parser<CharType>::maxParsingDepth)
            {
                SetErrorCode(result, json_error::nesting);
                break;
            }

            typename JSON_Parser<CharType>::Token::Kind tk = ch == '{' ? Token::TKN_OpenBrace : Token::TKN_OpenBracket;
            CreateToken(result, tk, result.start);
            break;
        }
    case '}':
    case ']':
        {
            if((signed int)(--m_currentParsingDepth) < 0)
            {
                SetErrorCode(result, json_error::mismatched_brances);
                break;
            }

            typename JSON_Parser<CharType>::Token::Kind tk = ch == '}' ? Token::TKN_CloseBrace : Token::TKN_CloseBracket;
            CreateToken(result, tk, result.start);
            break;
        }
    case ',':
        CreateToken(result, Token::TKN_Comma, result.start);
        break;

    case ':':
        CreateToken(result, Token::TKN_Colon, result.start);
        break;

    case 't':
        if (!CompleteKeywordTrue(result))
        {
            SetErrorCode(result, json_error::malformed_literal);
        }
        break;
    case 'f':
        if (!CompleteKeywordFalse(result))
        {
            SetErrorCode(result, json_error::malformed_literal);
        }
        break;
    case 'n':
        if (!CompleteKeywordNull(result))
        {
            SetErrorCode(result, json_error::malformed_literal);
        }
        break;
    case '/':
        if (!CompleteComment(result))
        {
            SetErrorCode(result, json_error::malformed_comment);
            break;
        }
        // For now, we're ignoring comments.
        goto try_again;
    case '"':
        if (!CompleteStringLiteral(result))
        {
            SetErrorCode(result, json_error::malformed_string_literal);
        }
        break;

    case '-':
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
        if (!CompleteNumberLiteral(static_cast<CharType>(ch), result))
        {
            SetErrorCode(result, json_error::malformed_numeric_literal);
        }
        break;
    default:
        SetErrorCode(result, json_error::malformed_token);
        break;
    }
}