diff options
author | luckybug <luckybug@yandex-team.ru> | 2022-02-10 16:50:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:27 +0300 |
commit | b455da0978714a8b8dd026fc564b36dea5948f79 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 | |
parent | a6d369648d0e4e2d446acfd469aced762d3c0492 (diff) | |
download | ydb-b455da0978714a8b8dd026fc564b36dea5948f79.tar.gz |
Restoring authorship annotation for <luckybug@yandex-team.ru>. Commit 2 of 2.
-rw-r--r-- | library/cpp/getopt/small/last_getopt_opt.h | 4 | ||||
-rw-r--r-- | library/cpp/json/ut/json_saveload_ut.cpp | 68 | ||||
-rw-r--r-- | library/cpp/json/ut/ya.make | 2 | ||||
-rw-r--r-- | library/cpp/json/writer/json_value.cpp | 128 | ||||
-rw-r--r-- | library/cpp/json/writer/json_value.h | 6 | ||||
-rw-r--r-- | util/string/join.h | 54 | ||||
-rw-r--r-- | util/string/join_ut.cpp | 150 |
7 files changed, 206 insertions, 206 deletions
diff --git a/library/cpp/getopt/small/last_getopt_opt.h b/library/cpp/getopt/small/last_getopt_opt.h index c1d18a9428..a8dd5adca9 100644 --- a/library/cpp/getopt/small/last_getopt_opt.h +++ b/library/cpp/getopt/small/last_getopt_opt.h @@ -247,7 +247,7 @@ namespace NLastGetopt { * @return optional value * throws exception if optional value wasn't set */ - const TString& GetOptionalValue() const { + const TString& GetOptionalValue() const { return *OptionalValue_; } @@ -272,7 +272,7 @@ namespace NLastGetopt { * @return default value * throws exception if <default value> wasn't set */ - const TString& GetDefaultValue() const { + const TString& GetDefaultValue() const { return *DefaultValue_; } diff --git a/library/cpp/json/ut/json_saveload_ut.cpp b/library/cpp/json/ut/json_saveload_ut.cpp index 7ffe0668dd..b480a80fe4 100644 --- a/library/cpp/json/ut/json_saveload_ut.cpp +++ b/library/cpp/json/ut/json_saveload_ut.cpp @@ -1,36 +1,36 @@ #include <library/cpp/json/json_value.h> - + #include <library/cpp/testing/unittest/registar.h> -#include <util/stream/buffer.h> -#include <util/generic/buffer.h> -#include <util/ysaveload.h> - -Y_UNIT_TEST_SUITE(JsonSaveLoad) { - Y_UNIT_TEST(Serialize) { - - NJson::TJsonValue expected; - - expected["ui64"] = ui64(1); - expected["i64"] = i64(2); - expected["double"] = 2.0; - expected["string"] = "text"; - expected["map"] = expected; - expected["array"].SetType(NJson::JSON_ARRAY).GetArraySafe().emplace_back(expected); - expected["null"].SetType(NJson::JSON_NULL); - expected["undefined"].SetType(NJson::JSON_UNDEFINED); - - TBuffer buffer; - { - TBufferOutput output(buffer); - ::Save(&output, expected); - } - - NJson::TJsonValue load; - { - TBufferInput input(buffer); - ::Load(&input, load); - } - - UNIT_ASSERT_EQUAL_C(expected, load, "expected: " << expected << ", got: " << load); - } -} +#include <util/stream/buffer.h> +#include <util/generic/buffer.h> +#include <util/ysaveload.h> + +Y_UNIT_TEST_SUITE(JsonSaveLoad) { + Y_UNIT_TEST(Serialize) { + + NJson::TJsonValue expected; + + expected["ui64"] = ui64(1); + expected["i64"] = i64(2); + expected["double"] = 2.0; + expected["string"] = "text"; + expected["map"] = expected; + expected["array"].SetType(NJson::JSON_ARRAY).GetArraySafe().emplace_back(expected); + expected["null"].SetType(NJson::JSON_NULL); + expected["undefined"].SetType(NJson::JSON_UNDEFINED); + + TBuffer buffer; + { + TBufferOutput output(buffer); + ::Save(&output, expected); + } + + NJson::TJsonValue load; + { + TBufferInput input(buffer); + ::Load(&input, load); + } + + UNIT_ASSERT_EQUAL_C(expected, load, "expected: " << expected << ", got: " << load); + } +} diff --git a/library/cpp/json/ut/ya.make b/library/cpp/json/ut/ya.make index 401ca6bc4d..8e0362d84b 100644 --- a/library/cpp/json/ut/ya.make +++ b/library/cpp/json/ut/ya.make @@ -11,7 +11,7 @@ SRCS( json_reader_ut.cpp json_prettifier_ut.cpp json_writer_ut.cpp - json_saveload_ut.cpp + json_saveload_ut.cpp ) END() diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp index 7fd7344489..c61e8d1dc4 100644 --- a/library/cpp/json/writer/json_value.cpp +++ b/library/cpp/json/writer/json_value.cpp @@ -11,8 +11,8 @@ #include <util/string/type.h> #include <util/string/vector.h> #include <util/system/yassert.h> -#include <util/ysaveload.h> -#include <util/generic/bt_exception.h> +#include <util/ysaveload.h> +#include <util/generic/bt_exception.h> static bool AreJsonMapsEqual(const NJson::TJsonValue& lhs, const NJson::TJsonValue& rhs) { @@ -989,68 +989,68 @@ namespace NJson { tmp.SwapWithUndefined(rhs); } - void TJsonValue::Save(IOutputStream* s) const { - ::Save(s, static_cast<ui8>(Type)); - switch (Type) { - case JSON_UNDEFINED:break; - case JSON_NULL:break; - case JSON_BOOLEAN: - ::Save(s, Value.Boolean); - break; - case JSON_INTEGER: - ::Save(s, Value.Integer); - break; - case JSON_UINTEGER: - ::Save(s, Value.UInteger); - break; - case JSON_DOUBLE: - ::Save(s, Value.Double); - break; - case JSON_STRING: - ::Save(s, Value.String); - break; - case JSON_MAP: - ::Save(s, *Value.Map); - break; - case JSON_ARRAY: - ::Save(s, *Value.Array); - break; - } - } - - void TJsonValue::Load(IInputStream* s) { - { - ui8 loadedType = {}; - ::Load(s, loadedType); - SetType(static_cast<EJsonValueType>(loadedType)); - } - switch (Type) { - case JSON_UNDEFINED:break; - case JSON_NULL:break; - case JSON_BOOLEAN: - ::Load(s, Value.Boolean); - break; - case JSON_INTEGER: - ::Load(s, Value.Integer); - break; - case JSON_UINTEGER: - ::Load(s, Value.UInteger); - break; - case JSON_DOUBLE: - ::Load(s, Value.Double); - break; - case JSON_STRING: - ::Load(s, Value.String); - break; - case JSON_MAP: - ::Load(s, *Value.Map); - break; - case JSON_ARRAY: - ::Load(s, *Value.Array); - break; - } - } - + void TJsonValue::Save(IOutputStream* s) const { + ::Save(s, static_cast<ui8>(Type)); + switch (Type) { + case JSON_UNDEFINED:break; + case JSON_NULL:break; + case JSON_BOOLEAN: + ::Save(s, Value.Boolean); + break; + case JSON_INTEGER: + ::Save(s, Value.Integer); + break; + case JSON_UINTEGER: + ::Save(s, Value.UInteger); + break; + case JSON_DOUBLE: + ::Save(s, Value.Double); + break; + case JSON_STRING: + ::Save(s, Value.String); + break; + case JSON_MAP: + ::Save(s, *Value.Map); + break; + case JSON_ARRAY: + ::Save(s, *Value.Array); + break; + } + } + + void TJsonValue::Load(IInputStream* s) { + { + ui8 loadedType = {}; + ::Load(s, loadedType); + SetType(static_cast<EJsonValueType>(loadedType)); + } + switch (Type) { + case JSON_UNDEFINED:break; + case JSON_NULL:break; + case JSON_BOOLEAN: + ::Load(s, Value.Boolean); + break; + case JSON_INTEGER: + ::Load(s, Value.Integer); + break; + case JSON_UINTEGER: + ::Load(s, Value.UInteger); + break; + case JSON_DOUBLE: + ::Load(s, Value.Double); + break; + case JSON_STRING: + ::Load(s, Value.String); + break; + case JSON_MAP: + ::Load(s, *Value.Map); + break; + case JSON_ARRAY: + ::Load(s, *Value.Array); + break; + } + } + //**************************************************************** bool GetMapPointer(const TJsonValue& jv, const size_t index, const TJsonValue::TMapType** value) { diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h index 1ce89a9370..3f0f50bc4c 100644 --- a/library/cpp/json/writer/json_value.h +++ b/library/cpp/json/writer/json_value.h @@ -186,11 +186,11 @@ namespace NJson { void Swap(TJsonValue& rhs) noexcept; // save using util/ysaveload.h serialization (not to JSON stream) - void Save(IOutputStream* s) const; + void Save(IOutputStream* s) const; // load using util/ysaveload.h serialization (not as JSON stream) - void Load(IInputStream* s); - + void Load(IInputStream* s); + static const TJsonValue UNDEFINED; private: diff --git a/util/string/join.h b/util/string/join.h index 595674b58e..b166fad1f3 100644 --- a/util/string/join.h +++ b/util/string/join.h @@ -197,22 +197,22 @@ JoinSeq(TCharType delim, const TContainer& data) { return JoinSeq(delimBuf, data); } -/** \brief Functor for streaming iterative objects from TIterB e to TIterE b, separated with delim. - * Difference from JoinSeq, JoinRange, Join is the lack of TString object - all depends on operator<< for the type and - * realization of IOutputStream - */ +/** \brief Functor for streaming iterative objects from TIterB e to TIterE b, separated with delim. + * Difference from JoinSeq, JoinRange, Join is the lack of TString object - all depends on operator<< for the type and + * realization of IOutputStream + */ template <class TIterB, class TIterE> struct TRangeJoiner { - friend constexpr IOutputStream& operator<<(IOutputStream& stream, const TRangeJoiner<TIterB, TIterE>& rangeJoiner) { + friend constexpr IOutputStream& operator<<(IOutputStream& stream, const TRangeJoiner<TIterB, TIterE>& rangeJoiner) { if (rangeJoiner.b != rangeJoiner.e) { - stream << *rangeJoiner.b; - + stream << *rangeJoiner.b; + for (auto it = std::next(rangeJoiner.b); it != rangeJoiner.e; ++it) - stream << rangeJoiner.delim << *it; - } - return stream; - } - + stream << rangeJoiner.delim << *it; + } + return stream; + } + constexpr TRangeJoiner(TStringBuf delim, TIterB&& b, TIterE&& e) : delim(delim) , b(std::forward<TIterB>(b)) @@ -220,27 +220,27 @@ struct TRangeJoiner { { } -private: - const TStringBuf delim; - const TIterB b; - const TIterE e; -}; - +private: + const TStringBuf delim; + const TIterB b; + const TIterE e; +}; + template <class TIterB, class TIterE = TIterB> constexpr auto MakeRangeJoiner(TStringBuf delim, TIterB&& b, TIterE&& e) { - return TRangeJoiner<TIterB, TIterE>(delim, std::forward<TIterB>(b), std::forward<TIterE>(e)); -} - + return TRangeJoiner<TIterB, TIterE>(delim, std::forward<TIterB>(b), std::forward<TIterE>(e)); +} + template <class TContainer> constexpr auto MakeRangeJoiner(TStringBuf delim, const TContainer& data) { - return MakeRangeJoiner(delim, std::cbegin(data), std::cend(data)); -} - + return MakeRangeJoiner(delim, std::cbegin(data), std::cend(data)); +} + template <class TVal> constexpr auto MakeRangeJoiner(TStringBuf delim, const std::initializer_list<TVal>& data) { - return MakeRangeJoiner(delim, std::cbegin(data), std::cend(data)); -} - + return MakeRangeJoiner(delim, std::cbegin(data), std::cend(data)); +} + /* We force (std::initializer_list<TStringBuf>) input type for (TString) and (const char*) types because: * # When (std::initializer_list<TString>) is used, TString objects are copied into the initializer_list object. * Storing TStringBufs instead is faster, even with COW-enabled strings. diff --git a/util/string/join_ut.cpp b/util/string/join_ut.cpp index 60a44d08ad..3ed2b2459c 100644 --- a/util/string/join_ut.cpp +++ b/util/string/join_ut.cpp @@ -51,98 +51,98 @@ Y_UNIT_TEST_SUITE(JoinStringTest) { UNIT_ASSERT_EQUAL(JoinRange(" ", vchar.begin(), vchar.end()), result); UNIT_ASSERT_EQUAL(JoinRange(" ", vbuf.begin(), vbuf.end()), result); UNIT_ASSERT_EQUAL(JoinRange(" ", vstring.begin(), vstring.end()), result); - { - TStringStream stream; - stream << MakeRangeJoiner(" ", v, v + 3); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vchar.begin(), vchar.end()); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vbuf.begin(), vbuf.end()); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vstring.begin(), vstring.end()); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", v, v + 3); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vchar.begin(), vchar.end()); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vbuf.begin(), vbuf.end()); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vstring.begin(), vstring.end()); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } // vectors UNIT_ASSERT_EQUAL(JoinSeq(" ", vchar), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", vbuf), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", vstring), result); - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vchar); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vbuf); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vstring); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vchar); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vbuf); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vstring); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } // initializer lists with type deduction UNIT_ASSERT_EQUAL(JoinSeq(" ", {v[0], v[1], v[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", {vchar[0], vchar[1], vchar[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", {vbuf[0], vbuf[1], vbuf[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", {vstring[0], vstring[1], vstring[2]}), result); - { - TStringStream stream; - stream << MakeRangeJoiner(" ", {v[0], v[1], v[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", {vchar[0], vchar[1], vchar[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", {vbuf[0], vbuf[1], vbuf[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", {vstring[0], vstring[1], vstring[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", {v[0], v[1], v[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", {vchar[0], vchar[1], vchar[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", {vbuf[0], vbuf[1], vbuf[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", {vstring[0], vstring[1], vstring[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } // initializer lists with explicit types UNIT_ASSERT_EQUAL(JoinSeq(" ", std::initializer_list<const char*>{v[0], v[1], v[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", std::initializer_list<const char*>{vchar[0], vchar[1], vchar[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", std::initializer_list<TStringBuf>{vbuf[0], vbuf[1], vbuf[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", std::initializer_list<TString>{vstring[0], vstring[1], vstring[2]}), result); - { - TStringStream stream; - stream << MakeRangeJoiner(" ", std::initializer_list<const char*>{v[0], v[1], v[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", std::initializer_list<const char*>{vchar[0], vchar[1], vchar[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", std::initializer_list<TStringBuf>{vbuf[0], vbuf[1], vbuf[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", std::initializer_list<TString>{vstring[0], vstring[1], vstring[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", std::initializer_list<const char*>{v[0], v[1], v[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", std::initializer_list<const char*>{vchar[0], vchar[1], vchar[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", std::initializer_list<TStringBuf>{vbuf[0], vbuf[1], vbuf[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", std::initializer_list<TString>{vstring[0], vstring[1], vstring[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } // c-style array UNIT_ASSERT_VALUES_EQUAL(JoinSeq(" ", v), result); |