From 9627e2ef8b655df228b5f16d5d1334711a797fc9 Mon Sep 17 00:00:00 2001 From: Kristina Simpson Date: Tue, 7 Apr 2015 10:14:17 +1200 Subject: [PATCH] Made the json parser accept strings delimited with single quotes. --- src/json.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/json.cpp b/src/json.cpp index 39e2c1e..4c8990c 100644 --- a/src/json.cpp +++ b/src/json.cpp @@ -137,7 +137,7 @@ namespace json return std::make_tuple(DOCUMENT_END, variant()); } if(in_string) { - if(*it_ == '"') { + if(*it_ == '"' || *it_ == '\'') { ++it_; variant string_node(new_string); //if(new_string == "true") { @@ -205,7 +205,7 @@ namespace json new_string += *it_++; } } else { - if(*it_ == '{' || *it_ == '}' || *it_ == '[' || *it_ == ']' || *it_ == ',' || *it_ == ':' || *it_ == '"' || is_space(*it_)) { + if(*it_ == '{' || *it_ == '}' || *it_ == '[' || *it_ == ']' || *it_ == ',' || *it_ == ':' || *it_ == '"' || *it_ == '\'' || is_space(*it_)) { if(new_string.empty() == false) { if(new_string == "true") { return std::make_tuple(LIT_TRUE, variant::from_bool(true)); @@ -236,7 +236,7 @@ namespace json } else if(*it_ == ':') { ++it_; return std::make_tuple(COLON, variant()); - } else if(*it_ == '"') { + } else if(*it_ == '"' || *it_ == '\'') { in_string = true; ++it_; } else if(is_digit(*it_) || *it_ == '-') { @@ -356,11 +356,11 @@ namespace json if(tok == lexer::LITERAL || tok == lexer::STRING_LITERAL) { key = token_value; } else { - throw parse_error(formatter() << "Unexpected token type: " << lexer::token_as_string(tok) << " expected string or literal"); + throw parse_error(formatter() << "Unexpected token type: " << lexer::token_as_string(tok) << " expected string or literal : " << token_value.to_debug_string()); } std::tie(tok, token_value) = lex.get_next_token(); if(tok != lexer::COLON) { - throw parse_error(formatter() << "Expected colon ':' found " << lexer::token_as_string(tok)); + throw parse_error(formatter() << "Expected colon ':' found " << lexer::token_as_string(tok) << " : " << token_value.to_debug_string()); } std::tie(tok, token_value) = lex.get_next_token(); if(lexer::is_simple_value(tok)) { @@ -370,7 +370,7 @@ namespace json } else if(tok == lexer::LEFT_BRACKET) { res[key] = read_array(lex); } else { - throw parse_error(formatter() << "Expected colon ':' found " << lexer::token_as_string(tok)); + throw parse_error(formatter() << "Expected colon ':' found " << lexer::token_as_string(tok) << " : " << token_value.to_debug_string()); } std::tie(tok, token_value) = lex.get_next_token(); if(tok == lexer::RIGHT_BRACE) {