diff options
author | Vasily Gerasimov <UgnineSirdis@gmail.com> | 2022-02-10 16:49:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:10 +0300 |
commit | 1eb755fbca92172a6aec2f57371b2b3a19dfab43 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/scheme | |
parent | 6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (diff) | |
download | ydb-1eb755fbca92172a6aec2f57371b2b3a19dfab43.tar.gz |
Restoring authorship annotation for Vasily Gerasimov <UgnineSirdis@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/scheme')
-rw-r--r-- | library/cpp/scheme/scheme.h | 2 | ||||
-rw-r--r-- | library/cpp/scheme/scimpl.h | 8 | ||||
-rw-r--r-- | library/cpp/scheme/scimpl_defs.h | 8 | ||||
-rw-r--r-- | library/cpp/scheme/scimpl_json_read.cpp | 24 | ||||
-rw-r--r-- | library/cpp/scheme/tests/ut/scheme_json_ut.cpp | 12 | ||||
-rw-r--r-- | library/cpp/scheme/tests/ut/scheme_ut.cpp | 10 |
6 files changed, 32 insertions, 32 deletions
diff --git a/library/cpp/scheme/scheme.h b/library/cpp/scheme/scheme.h index b9319c531e..3d7c59f3c9 100644 --- a/library/cpp/scheme/scheme.h +++ b/library/cpp/scheme/scheme.h @@ -294,7 +294,7 @@ namespace NSc { static const EJsonOpts JO_SAFE = TJsonOpts::JO_SAFE; // JO_SORT_KEYS | JO_SKIP_UNSAFE static const EJsonOpts JO_PARSER_STRICT_WITH_COMMENTS = TJsonOpts::JO_PARSER_STRICT_WITH_COMMENTS; // strict json + strict utf8 static const EJsonOpts JO_PARSER_STRICT = TJsonOpts::JO_PARSER_STRICT; // strict json + strict utf8 + comments are disallowed - static const EJsonOpts JO_PARSER_DISALLOW_DUPLICATE_KEYS = TJsonOpts::JO_PARSER_DISALLOW_DUPLICATE_KEYS; + static const EJsonOpts JO_PARSER_DISALLOW_DUPLICATE_KEYS = TJsonOpts::JO_PARSER_DISALLOW_DUPLICATE_KEYS; static TValue FromJson(TStringBuf, const TJsonOpts& = TJsonOpts()); static TValue FromJsonThrow(TStringBuf, const TJsonOpts& = TJsonOpts()); diff --git a/library/cpp/scheme/scimpl.h b/library/cpp/scheme/scimpl.h index 7f0fc758ef..4f68f16290 100644 --- a/library/cpp/scheme/scimpl.h +++ b/library/cpp/scheme/scimpl.h @@ -280,13 +280,13 @@ namespace NSc { TDict::const_iterator it = Dict.find(key); return it != Dict.end() ? it->second : TValue::DefaultValue(); - } - + } + TValue* GetNoAdd(TStringBuf key) { if (!IsDict()) { return nullptr; } - + return Dict.FindPtr(key); } @@ -582,7 +582,7 @@ namespace NSc { TValue& TValue::Back() { return CoreMutable().Back(); } - + const TValue& TValue::Back() const { const TArray& arr = GetArray(); return arr.empty() ? DefaultValue() : arr.back(); diff --git a/library/cpp/scheme/scimpl_defs.h b/library/cpp/scheme/scimpl_defs.h index 2c02806fb9..f3dd66b437 100644 --- a/library/cpp/scheme/scimpl_defs.h +++ b/library/cpp/scheme/scimpl_defs.h @@ -74,7 +74,7 @@ namespace NSc { JO_PARSER_STRICT_JSON = 16, // strict standard json JO_PARSER_STRICT_UTF8 = 32, // strict utf8 JO_PARSER_DISALLOW_COMMENTS = 64, - JO_PARSER_DISALLOW_DUPLICATE_KEYS = 128, + JO_PARSER_DISALLOW_DUPLICATE_KEYS = 128, JO_PRETTY = JO_FORMAT | JO_SORT_KEYS, // pretty print json JO_SAFE = JO_SKIP_UNSAFE | JO_SORT_KEYS, // ensure standard parser-safe json @@ -85,8 +85,8 @@ namespace NSc { public: TJsonOpts(int opts = JO_SORT_KEYS) - : Opts(opts) - , SortKeys(opts & JO_SORT_KEYS) + : Opts(opts) + , SortKeys(opts & JO_SORT_KEYS) , FormatJson(opts & JO_FORMAT) , StringPolicy((opts & JO_SKIP_UNSAFE) ? StringPolicySafe : StringPolicyUnsafe) { @@ -97,7 +97,7 @@ namespace NSc { public: bool RelaxedJson = false; - int Opts = 0; + int Opts = 0; bool SortKeys = true; bool FormatJson = false; diff --git a/library/cpp/scheme/scimpl_json_read.cpp b/library/cpp/scheme/scimpl_json_read.cpp index a0edc15d01..8a29cc7739 100644 --- a/library/cpp/scheme/scimpl_json_read.cpp +++ b/library/cpp/scheme/scimpl_json_read.cpp @@ -22,13 +22,13 @@ namespace NSc { { } - bool Add(TStringBuf v, bool allowDuplicated) { - if (!ExpectKey || Y_UNLIKELY(!Container->IsDict())) + bool Add(TStringBuf v, bool allowDuplicated) { + if (!ExpectKey || Y_UNLIKELY(!Container->IsDict())) + return false; + + if (!allowDuplicated && Y_UNLIKELY(Container->Has(v))) return false; - if (!allowDuplicated && Y_UNLIKELY(Container->Has(v))) - return false; - LastValue = &Container->GetOrAdd(v); ExpectKey = false; return true; @@ -62,16 +62,16 @@ namespace NSc { public: TValue& Root; TJsonError& Error; - const TJsonOpts& Cfg; + const TJsonOpts& Cfg; TStackType Stack; bool Virgin = true; public: - TJsonDeserializer(TValue& root, TJsonError& err, const TJsonOpts& cfg) + TJsonDeserializer(TValue& root, TJsonError& err, const TJsonOpts& cfg) : Root(root) , Error(err) - , Cfg(cfg) + , Cfg(cfg) { Root.SetNull(); Stack.reserve(10); @@ -143,7 +143,7 @@ namespace NSc { bool OnMapKey(const TStringBuf& k) override { if (Y_UNLIKELY(Stack.empty())) return false; - return Stack.back().Add(k, !(Cfg.Opts & TJsonOpts::JO_PARSER_DISALLOW_DUPLICATE_KEYS)); + return Stack.back().Add(k, !(Cfg.Opts & TJsonOpts::JO_PARSER_DISALLOW_DUPLICATE_KEYS)); } bool OnOpenMap() override { @@ -180,8 +180,8 @@ namespace NSc { } }; - static bool DoParseFromJson(TValue& res, TJsonError& err, TStringBuf json, const TJsonOpts& cfg) { - TJsonDeserializer d(res, err, cfg); + static bool DoParseFromJson(TValue& res, TJsonError& err, TStringBuf json, const TJsonOpts& cfg) { + TJsonDeserializer d(res, err, cfg); if (cfg.RelaxedJson) { return NJson::ReadJsonFast(json, &d); @@ -191,7 +191,7 @@ namespace NSc { } } - static bool DoParseFromJson(TValue& res, TStringBuf json, const TJsonOpts& cfg) { + static bool DoParseFromJson(TValue& res, TStringBuf json, const TJsonOpts& cfg) { TJsonError err; return DoParseFromJson(res, err, json, cfg); } diff --git a/library/cpp/scheme/tests/ut/scheme_json_ut.cpp b/library/cpp/scheme/tests/ut/scheme_json_ut.cpp index 37d635238e..daeb2654f9 100644 --- a/library/cpp/scheme/tests/ut/scheme_json_ut.cpp +++ b/library/cpp/scheme/tests/ut/scheme_json_ut.cpp @@ -137,7 +137,7 @@ Y_UNIT_TEST_SUITE(TSchemeJsonTest) { NSc::TValue b = NSc::TValue::FromJsonValue(a.ToJsonValue()); UNIT_ASSERT_JSON_EQ_JSON(a, b); } - + Y_UNIT_TEST(TestJsonEmptyContainers) { { NSc::TValue a = NSc::NUt::AssertFromJson("{a:[]}"); @@ -153,9 +153,9 @@ Y_UNIT_TEST_SUITE(TSchemeJsonTest) { Y_UNIT_TEST(TestDuplicateKeys) { const TStringBuf duplicatedKeys = "{\"a\":[{\"b\":1, \"b\":42}]}"; - UNIT_ASSERT_NO_EXCEPTION(NSc::TValue::FromJsonThrow(duplicatedKeys)); - UNIT_ASSERT_EXCEPTION(NSc::TValue::FromJsonThrow(duplicatedKeys, NSc::TValue::JO_PARSER_DISALLOW_DUPLICATE_KEYS), yexception); - UNIT_ASSERT(NSc::TValue::FromJson(duplicatedKeys).IsDict()); - UNIT_ASSERT(NSc::TValue::FromJson(duplicatedKeys, NSc::TValue::JO_PARSER_DISALLOW_DUPLICATE_KEYS).IsNull()); - } + UNIT_ASSERT_NO_EXCEPTION(NSc::TValue::FromJsonThrow(duplicatedKeys)); + UNIT_ASSERT_EXCEPTION(NSc::TValue::FromJsonThrow(duplicatedKeys, NSc::TValue::JO_PARSER_DISALLOW_DUPLICATE_KEYS), yexception); + UNIT_ASSERT(NSc::TValue::FromJson(duplicatedKeys).IsDict()); + UNIT_ASSERT(NSc::TValue::FromJson(duplicatedKeys, NSc::TValue::JO_PARSER_DISALLOW_DUPLICATE_KEYS).IsNull()); + } }; diff --git a/library/cpp/scheme/tests/ut/scheme_ut.cpp b/library/cpp/scheme/tests/ut/scheme_ut.cpp index 20fe460948..1a5d07c31b 100644 --- a/library/cpp/scheme/tests/ut/scheme_ut.cpp +++ b/library/cpp/scheme/tests/ut/scheme_ut.cpp @@ -863,17 +863,17 @@ Y_UNIT_TEST_SUITE(TSchemeTest) { } Y_UNIT_TEST(TestGetNoAdd) { - NSc::TValue v = NSc::NUt::AssertFromJson("{a:[null,-1,2,3.4],b:3,c:{d:5}}"); + NSc::TValue v = NSc::NUt::AssertFromJson("{a:[null,-1,2,3.4],b:3,c:{d:5}}"); UNIT_ASSERT(v.GetNoAdd("a") != nullptr); UNIT_ASSERT(v.GetNoAdd("b") != nullptr); UNIT_ASSERT(v.GetNoAdd("c") != nullptr); UNIT_ASSERT(v.GetNoAdd("d") == nullptr); UNIT_ASSERT(v.GetNoAdd("value") == nullptr); - + NSc::TValue* child = v.GetNoAdd("c"); UNIT_ASSERT(child != nullptr); (*child)["e"]["f"] = 42; - const NSc::TValue expectedResult = NSc::NUt::AssertFromJson("{a:[null,-1,2,3.4],b:3,c:{d:5,e:{f:42}}}"); - UNIT_ASSERT_VALUES_EQUAL(v, expectedResult); - } + const NSc::TValue expectedResult = NSc::NUt::AssertFromJson("{a:[null,-1,2,3.4],b:3,c:{d:5,e:{f:42}}}"); + UNIT_ASSERT_VALUES_EQUAL(v, expectedResult); + } }; |