diff options
author | xpahos <xpahos@yandex-team.ru> | 2022-02-10 16:47:21 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:21 +0300 |
commit | da8fe75e5a837ef6a6e8a21f96dcee631e8b5a1e (patch) | |
tree | 9814fbd1c3effac9b8377c5d604b367b14e2db55 /library/cpp/json | |
parent | 52faf709473af8421da1e2ea84ae1879b16665b8 (diff) | |
download | ydb-da8fe75e5a837ef6a6e8a21f96dcee631e8b5a1e.tar.gz |
Restoring authorship annotation for <xpahos@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/json')
-rw-r--r-- | library/cpp/json/json_reader.cpp | 70 | ||||
-rw-r--r-- | library/cpp/json/json_reader.h | 36 | ||||
-rw-r--r-- | library/cpp/json/ut/json_reader_ut.cpp | 46 |
3 files changed, 76 insertions, 76 deletions
diff --git a/library/cpp/json/json_reader.cpp b/library/cpp/json/json_reader.cpp index e2f1d4102f..072c8deafe 100644 --- a/library/cpp/json/json_reader.cpp +++ b/library/cpp/json/json_reader.cpp @@ -312,37 +312,37 @@ namespace NJson { rapidjson::Reader& reader, TRapidJsonCompliantInputStream& is, THandler& handler) { - - ui8 flags = ReaderConfigToRapidJsonFlags::NOCOMMENTS_VALID_NOESCAPE; - + + ui8 flags = ReaderConfigToRapidJsonFlags::NOCOMMENTS_VALID_NOESCAPE; + if (config.AllowComments) { - flags |= ReaderConfigFlags::COMMENTS; - } - - if (config.DontValidateUtf8) { - flags &= ~(ReaderConfigFlags::VALIDATE); - } - - if (config.AllowEscapedApostrophe) { - flags |= ReaderConfigFlags::ESCAPE; - } - - switch (flags) { - case ReaderConfigToRapidJsonFlags::COMMENTS_NOVALID_NOESCAPE: + flags |= ReaderConfigFlags::COMMENTS; + } + + if (config.DontValidateUtf8) { + flags &= ~(ReaderConfigFlags::VALIDATE); + } + + if (config.AllowEscapedApostrophe) { + flags |= ReaderConfigFlags::ESCAPE; + } + + switch (flags) { + case ReaderConfigToRapidJsonFlags::COMMENTS_NOVALID_NOESCAPE: return reader.Parse<rapidjson::kParseCommentsFlag>(is, handler); - case ReaderConfigToRapidJsonFlags::COMMENTS_VALID_NOESCAPE: + case ReaderConfigToRapidJsonFlags::COMMENTS_VALID_NOESCAPE: return reader.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseValidateEncodingFlag>(is, handler); - case ReaderConfigToRapidJsonFlags::COMMENTS_VALID_ESCAPE: - return reader.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseValidateEncodingFlag | rapidjson::kParseEscapedApostropheFlag>(is, handler); - case ReaderConfigToRapidJsonFlags::COMMENTS_NOVALID_ESCAPE: - return reader.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseEscapedApostropheFlag>(is, handler); - case ReaderConfigToRapidJsonFlags::NOCOMMENTS_VALID_NOESCAPE: - return reader.Parse<rapidjson::kParseValidateEncodingFlag>(is, handler); - case ReaderConfigToRapidJsonFlags::NOCOMMENTS_VALID_ESCAPE: - return reader.Parse<rapidjson::kParseValidateEncodingFlag | rapidjson::kParseEscapedApostropheFlag>(is, handler); - case ReaderConfigToRapidJsonFlags::NOCOMMENTS_NOVALID_ESCAPE: - return reader.Parse<rapidjson::kParseEscapedApostropheFlag>(is, handler); - default: + case ReaderConfigToRapidJsonFlags::COMMENTS_VALID_ESCAPE: + return reader.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseValidateEncodingFlag | rapidjson::kParseEscapedApostropheFlag>(is, handler); + case ReaderConfigToRapidJsonFlags::COMMENTS_NOVALID_ESCAPE: + return reader.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseEscapedApostropheFlag>(is, handler); + case ReaderConfigToRapidJsonFlags::NOCOMMENTS_VALID_NOESCAPE: + return reader.Parse<rapidjson::kParseValidateEncodingFlag>(is, handler); + case ReaderConfigToRapidJsonFlags::NOCOMMENTS_VALID_ESCAPE: + return reader.Parse<rapidjson::kParseValidateEncodingFlag | rapidjson::kParseEscapedApostropheFlag>(is, handler); + case ReaderConfigToRapidJsonFlags::NOCOMMENTS_NOVALID_ESCAPE: + return reader.Parse<rapidjson::kParseEscapedApostropheFlag>(is, handler); + default: return reader.Parse<rapidjson::kParseNoFlags>(is, handler); } } @@ -523,13 +523,13 @@ namespace NJson { return ReadJson(in, &config, cbs); } - bool ReadJson(IInputStream* in, bool allowComments, bool allowEscapedApostrophe, TJsonCallbacks* cbs) { - TJsonReaderConfig config; - config.AllowComments = allowComments; - config.AllowEscapedApostrophe = allowEscapedApostrophe; - return ReadJson(in, &config, cbs); - } - + bool ReadJson(IInputStream* in, bool allowComments, bool allowEscapedApostrophe, TJsonCallbacks* cbs) { + TJsonReaderConfig config; + config.AllowComments = allowComments; + config.AllowEscapedApostrophe = allowEscapedApostrophe; + return ReadJson(in, &config, cbs); + } + bool ReadJson(IInputStream* in, const TJsonReaderConfig* config, TJsonCallbacks* cbs) { TJsonCallbacksWrapper wrapper(*cbs); TInputStreamWrapper is(*in); diff --git a/library/cpp/json/json_reader.h b/library/cpp/json/json_reader.h index c55e251a23..b673788330 100644 --- a/library/cpp/json/json_reader.h +++ b/library/cpp/json/json_reader.h @@ -18,7 +18,7 @@ namespace NJson { // js-style comments (both // and /**/) bool AllowComments = false; bool DontValidateUtf8 = false; - bool AllowEscapedApostrophe = false; + bool AllowEscapedApostrophe = false; void SetBufferSize(size_t bufferSize); size_t GetBufferSize() const; @@ -41,25 +41,25 @@ namespace NJson { bool ReadJson(IInputStream* in, TJsonCallbacks* callbacks); bool ReadJson(IInputStream* in, bool allowComments, TJsonCallbacks* callbacks); - bool ReadJson(IInputStream* in, bool allowComments, bool allowEscapedApostrophe, TJsonCallbacks* callbacks); + bool ReadJson(IInputStream* in, bool allowComments, bool allowEscapedApostrophe, TJsonCallbacks* callbacks); bool ReadJson(IInputStream* in, const TJsonReaderConfig* config, TJsonCallbacks* callbacks); - enum ReaderConfigFlags { - COMMENTS = 0b100, - VALIDATE = 0b010, - ESCAPE = 0b001, - }; - - enum ReaderConfigToRapidJsonFlags { - COMMENTS_NOVALID_NOESCAPE = 0b100, - COMMENTS_VALID_NOESCAPE = 0b110, - COMMENTS_VALID_ESCAPE = 0b111, - COMMENTS_NOVALID_ESCAPE = 0b101, - NOCOMMENTS_VALID_NOESCAPE = 0b010, - NOCOMMENTS_VALID_ESCAPE = 0b011, - NOCOMMENTS_NOVALID_ESCAPE = 0b001, - }; - + enum ReaderConfigFlags { + COMMENTS = 0b100, + VALIDATE = 0b010, + ESCAPE = 0b001, + }; + + enum ReaderConfigToRapidJsonFlags { + COMMENTS_NOVALID_NOESCAPE = 0b100, + COMMENTS_VALID_NOESCAPE = 0b110, + COMMENTS_VALID_ESCAPE = 0b111, + COMMENTS_NOVALID_ESCAPE = 0b101, + NOCOMMENTS_VALID_NOESCAPE = 0b010, + NOCOMMENTS_VALID_ESCAPE = 0b011, + NOCOMMENTS_NOVALID_ESCAPE = 0b001, + }; + inline bool ValidateJson(IInputStream* in, const TJsonReaderConfig* config, bool throwOnError = false) { TJsonCallbacks c(throwOnError); return ReadJson(in, config, &c); diff --git a/library/cpp/json/ut/json_reader_ut.cpp b/library/cpp/json/ut/json_reader_ut.cpp index f112e111e2..cd31afa0b8 100644 --- a/library/cpp/json/ut/json_reader_ut.cpp +++ b/library/cpp/json/ut/json_reader_ut.cpp @@ -96,29 +96,29 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) { UNIT_ASSERT_VALUES_EQUAL(result1, result2); } - Y_UNIT_TEST(TJsonEscapedApostrophe) { - TString jsonString = "{ \"foo\" : \"bar\\'buzz\" }"; - { - TStringStream in; - in << jsonString; - TStringStream out; - TJsonWriter writer(&out, false); - TReformatCallbacks cb(writer); - UNIT_ASSERT(!ReadJson(&in, &cb)); - } - - { - TStringStream in; - in << jsonString; - TStringStream out; - TJsonWriter writer(&out, false); - TReformatCallbacks cb(writer); - UNIT_ASSERT(ReadJson(&in, false, true, &cb)); - writer.Flush(); - UNIT_ASSERT_EQUAL(out.Str(), "[\"foo\",\"bar'buzz\"]"); - } - } - + Y_UNIT_TEST(TJsonEscapedApostrophe) { + TString jsonString = "{ \"foo\" : \"bar\\'buzz\" }"; + { + TStringStream in; + in << jsonString; + TStringStream out; + TJsonWriter writer(&out, false); + TReformatCallbacks cb(writer); + UNIT_ASSERT(!ReadJson(&in, &cb)); + } + + { + TStringStream in; + in << jsonString; + TStringStream out; + TJsonWriter writer(&out, false); + TReformatCallbacks cb(writer); + UNIT_ASSERT(ReadJson(&in, false, true, &cb)); + writer.Flush(); + UNIT_ASSERT_EQUAL(out.Str(), "[\"foo\",\"bar'buzz\"]"); + } + } + Y_UNIT_TEST(TJsonTreeTest) { TString data = "{\"intkey\": 10, \"double key\": 11.11, \"null value\":null, \"string key\": \"string\", \"array\": [1,2,3,\"TString\"], \"bool key\": true}"; TStringStream in; |