diff options
author | Arslan Urtashev <urtashev@gmail.com> | 2022-02-10 16:48:55 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:55 +0300 |
commit | 1136f2ce7cce7bcc84e695272c0d92d4eb900c2b (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp | |
parent | b97740540e7302cec9efa181e106ae1990a0cc1c (diff) | |
download | ydb-1136f2ce7cce7bcc84e695272c0d92d4eb900c2b.tar.gz |
Restoring authorship annotation for Arslan Urtashev <urtashev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
36 files changed, 272 insertions, 272 deletions
diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index 429bb53990..c99a1d053d 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -474,11 +474,11 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { Y_UNIT_TEST(TestDefaultValue) { TOptsNoDefault opts; opts.AddLongOption("path").DefaultValue("/etc"); - int value = 42; - opts.AddLongOption("value").StoreResult(&value).DefaultValue(32); + int value = 42; + opts.AddLongOption("value").StoreResult(&value).DefaultValue(32); TOptsParseResultTestWrapper r(&opts, V({"cmd", "dfdf"})); UNIT_ASSERT_VALUES_EQUAL("/etc", r.Get("path")); - UNIT_ASSERT_VALUES_EQUAL(32, value); + UNIT_ASSERT_VALUES_EQUAL(32, value); } Y_UNIT_TEST(TestSplitValue) { diff --git a/library/cpp/histogram/ya.make b/library/cpp/histogram/ya.make index 13237d9ab6..77cfd96902 100644 --- a/library/cpp/histogram/ya.make +++ b/library/cpp/histogram/ya.make @@ -2,8 +2,8 @@ RECURSE( adaptive hdr hdr/ut - simple - simple/ut + simple + simple/ut rt rt/ut ) diff --git a/library/cpp/http/misc/httpreqdata.cpp b/library/cpp/http/misc/httpreqdata.cpp index 035eccf7b9..f6951f68cd 100644 --- a/library/cpp/http/misc/httpreqdata.cpp +++ b/library/cpp/http/misc/httpreqdata.cpp @@ -1,7 +1,7 @@ #include "httpreqdata.h" -#include <util/stream/mem.h> - +#include <util/stream/mem.h> + TBaseServerRequestData::TBaseServerRequestData(SOCKET s) : Addr(nullptr) , Host() @@ -46,14 +46,14 @@ void TBaseServerRequestData::AppendQueryString(const char* str, size_t length) { SearchLength = ModifiedQueryString.size() - 1; // ignore terminator } -void TBaseServerRequestData::SetRemoteAddr(TStringBuf addr) { - TMemoryOutput out(AddrData, Y_ARRAY_SIZE(AddrData) - 1); - out.Write(addr.substr(0, Y_ARRAY_SIZE(AddrData) - 1)); - *out.Buf() = '\0'; - - Addr = AddrData; -} - +void TBaseServerRequestData::SetRemoteAddr(TStringBuf addr) { + TMemoryOutput out(AddrData, Y_ARRAY_SIZE(AddrData) - 1); + out.Write(addr.substr(0, Y_ARRAY_SIZE(AddrData) - 1)); + *out.Buf() = '\0'; + + Addr = AddrData; +} + const char* TBaseServerRequestData::RemoteAddr() const { if (!Addr) { *AddrData = 0; diff --git a/library/cpp/http/misc/httpreqdata.h b/library/cpp/http/misc/httpreqdata.h index 6bc816fcf5..16e59c4d78 100644 --- a/library/cpp/http/misc/httpreqdata.h +++ b/library/cpp/http/misc/httpreqdata.h @@ -57,7 +57,7 @@ public: void AppendQueryString(const char* str, size_t length); const char* RemoteAddr() const; - void SetRemoteAddr(TStringBuf addr); + void SetRemoteAddr(TStringBuf addr); const char* HeaderIn(TStringBuf key) const; const THttpHeadersContainer& HeadersIn() const { diff --git a/library/cpp/http/misc/httpreqdata_ut.cpp b/library/cpp/http/misc/httpreqdata_ut.cpp index 554a4c9645..e7f16ef27c 100644 --- a/library/cpp/http/misc/httpreqdata_ut.cpp +++ b/library/cpp/http/misc/httpreqdata_ut.cpp @@ -135,20 +135,20 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { } Y_UNIT_TEST(SetRemoteAddrSimple) { - static const TString TEST = "abacaba.search.yandex.net"; - - TServerRequestData rd; - rd.SetRemoteAddr(TEST); - UNIT_ASSERT_STRINGS_EQUAL(TEST, rd.RemoteAddr()); - } - + static const TString TEST = "abacaba.search.yandex.net"; + + TServerRequestData rd; + rd.SetRemoteAddr(TEST); + UNIT_ASSERT_STRINGS_EQUAL(TEST, rd.RemoteAddr()); + } + Y_UNIT_TEST(SetRemoteAddrRandom) { - for (size_t size = 0; size < 2 * INET6_ADDRSTRLEN; ++size) { - const TString test = NUnitTest::RandomString(size, size); - TServerRequestData rd; - rd.SetRemoteAddr(test); - UNIT_ASSERT_STRINGS_EQUAL(test.substr(0, INET6_ADDRSTRLEN - 1), rd.RemoteAddr()); - } - } - + for (size_t size = 0; size < 2 * INET6_ADDRSTRLEN; ++size) { + const TString test = NUnitTest::RandomString(size, size); + TServerRequestData rd; + rd.SetRemoteAddr(test); + UNIT_ASSERT_STRINGS_EQUAL(test.substr(0, INET6_ADDRSTRLEN - 1), rd.RemoteAddr()); + } + } + } // TRequestServerDataTest diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index 1a8e44e757..02370c2d79 100644 --- a/library/cpp/json/writer/json.cpp +++ b/library/cpp/json/writer/json.cpp @@ -188,7 +188,7 @@ namespace NJsonWriter { RawWriteChar(':'); return TAfterColonContext(*this); } - + TBuf& TBuf::EndList() { CheckAndPop(JE_LIST); EndValue(); diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h index 80a09de607..0aae2531b9 100644 --- a/library/cpp/json/writer/json.h +++ b/library/cpp/json/writer/json.h @@ -60,7 +60,7 @@ namespace NJsonWriter { TPairContext BeginObject(); TAfterColonContext WriteKey(const TStringBuf& key, EHtmlEscapeMode hem); TAfterColonContext WriteKey(const TStringBuf& key); - TAfterColonContext UnsafeWriteKey(const TStringBuf& key); + TAfterColonContext UnsafeWriteKey(const TStringBuf& key); bool KeyExpected() const { return Stack.back() == JE_OBJECT; } @@ -227,9 +227,9 @@ namespace NJsonWriter { TAfterColonContext WriteKey(const TStringBuf& s) { return Buf.WriteKey(s); } - TAfterColonContext UnsafeWriteKey(const TStringBuf& s) { - return Buf.UnsafeWriteKey(s); - } + TAfterColonContext UnsafeWriteKey(const TStringBuf& s) { + return Buf.UnsafeWriteKey(s); + } TAfterColonContext CompatWriteKeyWithoutQuotes(const TStringBuf& s) { return Buf.CompatWriteKeyWithoutQuotes(s); } diff --git a/library/cpp/json/writer/json_ut.cpp b/library/cpp/json/writer/json_ut.cpp index c278b6f73c..9980555683 100644 --- a/library/cpp/json/writer/json_ut.cpp +++ b/library/cpp/json/writer/json_ut.cpp @@ -252,18 +252,18 @@ Y_UNIT_TEST_SUITE(JsonWriter) { UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"raw_json({"nanvalue":"nan","infvalue":"inf","minus_infvalue":"-inf","l":["nan"]})raw_json"); } - - { - NJsonWriter::TBuf buf; - buf.BeginObject() + + { + NJsonWriter::TBuf buf; + buf.BeginObject() .WriteKey("<>&") .WriteString("Ololo") .UnsafeWriteKey("<>&") .WriteString("Ololo2") .EndObject(); - - UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"({"\u003C\u003E&":"Ololo","<>&":"Ololo2"})"); - } + + UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"({"\u003C\u003E&":"Ololo","<>&":"Ololo2"})"); + } } Y_UNIT_TEST(WriteUninitializedBoolDoesntCrashProgram) { diff --git a/library/cpp/json/yson/json2yson.cpp b/library/cpp/json/yson/json2yson.cpp index 53f4c9bf18..f72cb7a9ef 100644 --- a/library/cpp/json/yson/json2yson.cpp +++ b/library/cpp/json/yson/json2yson.cpp @@ -93,11 +93,11 @@ namespace NJson2Yson { NYson::TYsonParser ysonParser(&writer, inputStream, ::NYson::EYsonType::Node); ysonParser.Parse(); } - + void ConvertYson2Json(TStringBuf yson, IOutputStream* outputStream) { TMemoryInput inputStream(yson); ConvertYson2Json(&inputStream, outputStream); - } + } TString ConvertYson2Json(TStringBuf yson) { TString json; diff --git a/library/cpp/json/yson/json2yson.h b/library/cpp/json/yson/json2yson.h index b0d127a1a2..758eb6d0cf 100644 --- a/library/cpp/json/yson/json2yson.h +++ b/library/cpp/json/yson/json2yson.h @@ -7,7 +7,7 @@ namespace NJson2Yson { class TJsonBuilderImpl: public NYson::TYsonConsumerBase { public: - TJsonBuilderImpl(NJson::TJsonCallbacks* parserCallbacks) + TJsonBuilderImpl(NJson::TJsonCallbacks* parserCallbacks) : ParserCallbacks_(parserCallbacks) { } @@ -66,15 +66,15 @@ namespace NJson2Yson { } private: - NJson::TJsonCallbacks* ParserCallbacks_; + NJson::TJsonCallbacks* ParserCallbacks_; }; template <typename TBase> class TSkipAttributesProxy: public TBase { public: - template <typename... TArgs> - TSkipAttributesProxy<TBase>(TArgs&&... args) - : TBase(std::forward<TArgs>(args)...) + template <typename... TArgs> + TSkipAttributesProxy<TBase>(TArgs&&... args) + : TBase(std::forward<TArgs>(args)...) { } @@ -156,7 +156,7 @@ namespace NJson2Yson { void OnEndAttributes() override { --AttributesDepth; - Y_ASSERT(AttributesDepth >= 0); + Y_ASSERT(AttributesDepth >= 0); } private: @@ -168,7 +168,7 @@ namespace NJson2Yson { void ConvertYson2Json(IInputStream* inputStream, IOutputStream* outputStream); void ConvertYson2Json(TStringBuf yson, IOutputStream* outputStream); TString ConvertYson2Json(TStringBuf yson); - + bool DeserializeYsonAsJsonValue(IInputStream* inputStream, NJson::TJsonValue* outputValue, bool throwOnError = false); bool DeserializeYsonAsJsonValue(TStringBuf str, NJson::TJsonValue* outputValue, bool throwOnError = false); diff --git a/library/cpp/monlib/metrics/metric_registry.cpp b/library/cpp/monlib/metrics/metric_registry.cpp index 18e2884b41..b083163a7b 100644 --- a/library/cpp/monlib/metrics/metric_registry.cpp +++ b/library/cpp/monlib/metrics/metric_registry.cpp @@ -161,7 +161,7 @@ namespace NMonitoring { TMetric* TMetricRegistry::Metric(TLabelsType&& labels, Args&&... args) { { TReadGuard g{Lock_}; - + auto it = Metrics_.find(labels); if (it != Metrics_.end()) { Y_ENSURE(it->second->Type() == type, "cannot create metric " << labels @@ -170,7 +170,7 @@ namespace NMonitoring { return static_cast<TMetric*>(it->second.Get()); } } - + { IMetricPtr metric = MakeHolder<TMetric>(std::forward<Args>(args)...); @@ -186,7 +186,7 @@ namespace NMonitoring { return static_cast<TMetric*>(it->second.Get()); } } - + void TMetricRegistry::RemoveMetric(const ILabels& labels) noexcept { TWriteGuard g{Lock_}; Metrics_.erase(labels); @@ -214,7 +214,7 @@ namespace NMonitoring { consumer->OnStreamEnd(); } - + void TMetricRegistry::Append(TInstant time, IMetricConsumer* consumer) const { TReadGuard g{Lock_}; diff --git a/library/cpp/monlib/metrics/metric_registry.h b/library/cpp/monlib/metrics/metric_registry.h index 6cda12596e..670cf8651e 100644 --- a/library/cpp/monlib/metrics/metric_registry.h +++ b/library/cpp/monlib/metrics/metric_registry.h @@ -124,6 +124,6 @@ namespace NMonitoring { TLabels CommonLabels_; }; - + void WriteLabels(IMetricConsumer* consumer, const ILabels& labels); } diff --git a/library/cpp/monlib/metrics/metric_registry_ut.cpp b/library/cpp/monlib/metrics/metric_registry_ut.cpp index 10002a3897..86d9a52ec0 100644 --- a/library/cpp/monlib/metrics/metric_registry_ut.cpp +++ b/library/cpp/monlib/metrics/metric_registry_ut.cpp @@ -157,15 +157,15 @@ Y_UNIT_TEST_SUITE(TMetricRegistryTest) { Y_UNIT_TEST(DoubleCounter) { TMetricRegistry registry(TLabels{{"common", "label"}}); - + TCounter* c = registry.Counter({{"my", "counter"}}); UNIT_ASSERT_VALUES_EQUAL(c->Get(), 0); - c->Add(10); - - c = registry.Counter({{"my", "counter"}}); + c->Add(10); + + c = registry.Counter({{"my", "counter"}}); UNIT_ASSERT_VALUES_EQUAL(c->Get(), 10); - } - + } + Y_UNIT_TEST(Sample) { TMetricRegistry registry(TLabels{{"common", "label"}}); diff --git a/library/cpp/protobuf/json/config.h b/library/cpp/protobuf/json/config.h index 0ea37f1898..dc84fb4d5d 100644 --- a/library/cpp/protobuf/json/config.h +++ b/library/cpp/protobuf/json/config.h @@ -1,13 +1,13 @@ #pragma once #include "string_transform.h" -#include "name_generator.h" +#include "name_generator.h" #include <util/generic/vector.h> #include <util/generic/yexception.h> -#include <functional> - +#include <functional> + namespace NProtobufJson { struct TProto2JsonConfig { using TSelf = TProto2JsonConfig; @@ -85,14 +85,14 @@ namespace NProtobufJson { /// Custom enum values generator. TEnumValueGenerator EnumValueGenerator = {}; - + bool WriteNanAsString = false; TSelf& SetFormatOutput(bool format) { FormatOutput = format; return *this; } - + TSelf& SetMissingSingleKeyMode(MissingKeyMode mode) { MissingSingleKeyMode = mode; return *this; @@ -149,7 +149,7 @@ namespace NProtobufJson { NameGenerator = callback; return *this; } - + TSelf& SetEnumValueGenerator(TEnumValueGenerator callback) { EnumValueGenerator = callback; return *this; @@ -160,5 +160,5 @@ namespace NProtobufJson { return *this; } }; - + } diff --git a/library/cpp/protobuf/json/json2proto.cpp b/library/cpp/protobuf/json/json2proto.cpp index 5efa6d4b6c..640c10f5a5 100644 --- a/library/cpp/protobuf/json/json2proto.cpp +++ b/library/cpp/protobuf/json/json2proto.cpp @@ -36,10 +36,10 @@ static TString GetFieldName(const google::protobuf::FieldDescriptor& field, const NProtobufJson::TJson2ProtoConfig& config) { - if (config.NameGenerator) { - return config.NameGenerator(field); - } - + if (config.NameGenerator) { + return config.NameGenerator(field); + } + if (config.UseJsonName) { Y_ASSERT(!field.json_name().empty()); TString name = field.json_name(); @@ -409,10 +409,10 @@ namespace NProtobufJson { NJson::TJsonReaderConfig jsonCfg; jsonCfg.DontValidateUtf8 = true; jsonCfg.AllowComments = config.AllowComments; - + NJson::TJsonValue jsonValue; ReadJsonTree(json, &jsonCfg, &jsonValue, /* throwOnError = */ true); - + MergeJson2Proto(jsonValue, proto, config); } @@ -425,4 +425,4 @@ namespace NProtobufJson { proto.Clear(); MergeJson2Proto(json, proto, config); } -} +} diff --git a/library/cpp/protobuf/json/json2proto.h b/library/cpp/protobuf/json/json2proto.h index 5d35991cf3..4c33498dfa 100644 --- a/library/cpp/protobuf/json/json2proto.h +++ b/library/cpp/protobuf/json/json2proto.h @@ -1,7 +1,7 @@ #pragma once #include "string_transform.h" -#include "name_generator.h" +#include "name_generator.h" #include <library/cpp/json/json_reader.h> #include <library/cpp/json/json_value.h> @@ -105,7 +105,7 @@ namespace NProtobufJson { FldNameMode FieldNameMode = FieldNameOriginalCase; bool AllowUnknownFields = true; - + /// Use 'json_name' protobuf option for field name, mutually exclusive /// with FieldNameMode. bool UseJsonName = false; @@ -126,7 +126,7 @@ namespace NProtobufJson { /// Throw exception if there is no required fields in json object. bool CheckRequiredFields = true; - + /// Replace repeated fields content during merging bool ReplaceRepeatedFields = false; @@ -145,7 +145,7 @@ namespace NProtobufJson { /// Allow js-style comments (both // and /**/) bool AllowComments = false; }; - + /// @throw yexception void MergeJson2Proto(const NJson::TJsonValue& json, google::protobuf::Message& proto, const TJson2ProtoConfig& config = TJson2ProtoConfig()); @@ -173,7 +173,7 @@ namespace NProtobufJson { const TJson2ProtoConfig& config = TJson2ProtoConfig()) { Json2Proto(TStringBuf(json), proto, config); } - + /// @throw yexception inline void Json2Proto(IInputStream& in, google::protobuf::Message& proto, const TJson2ProtoConfig& config = TJson2ProtoConfig()) { @@ -190,7 +190,7 @@ namespace NProtobufJson { Json2Proto(jsonValue, protoValue, config); return protoValue; } - + /// @throw yexception template <typename T> T Json2Proto(IInputStream& in, const TJson2ProtoConfig& config = TJson2ProtoConfig()) { @@ -219,4 +219,4 @@ namespace NProtobufJson { return Json2Proto<T>(TStringBuf(ptr), config); } -} +} diff --git a/library/cpp/protobuf/json/json_output_create.cpp b/library/cpp/protobuf/json/json_output_create.cpp index a0515b9ce7..378e4ea65a 100644 --- a/library/cpp/protobuf/json/json_output_create.cpp +++ b/library/cpp/protobuf/json/json_output_create.cpp @@ -16,7 +16,7 @@ namespace NProtobufJson { TJsonMapOutputPtr CreateJsonMapOutput(TString& str, const TProto2JsonConfig& config) { return MakeHolder<TJsonStringWriterOutput>(&str, config); } - + TJsonMapOutputPtr CreateJsonMapOutput(TStringStream& out, const TProto2JsonConfig& config) { return MakeHolder<TJsonWriterOutput>(&out, config); } diff --git a/library/cpp/protobuf/json/json_value_output.cpp b/library/cpp/protobuf/json/json_value_output.cpp index 88f52f8490..d845cc1c74 100644 --- a/library/cpp/protobuf/json/json_value_output.cpp +++ b/library/cpp/protobuf/json/json_value_output.cpp @@ -1,5 +1,5 @@ -#include "json_value_output.h" - +#include "json_value_output.h" + #include <library/cpp/json/json_reader.h> namespace NProtobufJson { @@ -17,7 +17,7 @@ namespace NProtobufJson { void TJsonValueOutput::DoWrite(const TStringBuf& s) { WriteImpl(s); - } + } void TJsonValueOutput::DoWrite(const TString& s) { WriteImpl(s); @@ -34,7 +34,7 @@ namespace NProtobufJson { void TJsonValueOutput::DoWrite(long long i) { WriteImpl(i); } - + void TJsonValueOutput::DoWrite(unsigned long long i) { WriteImpl(i); } @@ -69,7 +69,7 @@ namespace NProtobufJson { void TJsonValueOutput::DoEndList() { Y_ASSERT(Context.top().Type == TContext::JSON_ARRAY); Context.pop(); - } + } void TJsonValueOutput::DoBeginObject() { Y_ASSERT(Context.top().Type == TContext::JSON_ARRAY || Context.top().Type == TContext::JSON_AFTER_KEY); @@ -85,7 +85,7 @@ namespace NProtobufJson { void TJsonValueOutput::DoWriteKey(const TStringBuf& key) { Y_ASSERT(Context.top().Type == TContext::JSON_MAP); Context.emplace(TContext::JSON_AFTER_KEY, Context.top().Value[key]); - } + } void TJsonValueOutput::DoEndObject() { Y_ASSERT(Context.top().Type == TContext::JSON_MAP); diff --git a/library/cpp/protobuf/json/json_value_output.h b/library/cpp/protobuf/json/json_value_output.h index d1127d0673..3fc6ff2ab0 100644 --- a/library/cpp/protobuf/json/json_value_output.h +++ b/library/cpp/protobuf/json/json_value_output.h @@ -1,11 +1,11 @@ #pragma once -#include "json_output.h" - +#include "json_output.h" + #include <library/cpp/json/writer/json_value.h> -#include <util/generic/stack.h> - +#include <util/generic/stack.h> + namespace NProtobufJson { class TJsonValueOutput: public IJsonOutput { public: @@ -54,10 +54,10 @@ namespace NProtobufJson { EType Type; NJson::TJsonValue& Value; - }; + }; NJson::TJsonValue& Root; TStack<TContext, TVector<TContext>> Context; - }; + }; } diff --git a/library/cpp/protobuf/json/json_writer_output.h b/library/cpp/protobuf/json/json_writer_output.h index fbd3f10c6f..3d8a2daa56 100644 --- a/library/cpp/protobuf/json/json_writer_output.h +++ b/library/cpp/protobuf/json/json_writer_output.h @@ -5,7 +5,7 @@ #include <library/cpp/json/json_writer.h> -#include <util/string/builder.h> +#include <util/string/builder.h> #include <util/generic/store_policy.h> namespace NProtobufJson { diff --git a/library/cpp/protobuf/json/name_generator.cpp b/library/cpp/protobuf/json/name_generator.cpp index c692cb3120..c1fb421175 100644 --- a/library/cpp/protobuf/json/name_generator.cpp +++ b/library/cpp/protobuf/json/name_generator.cpp @@ -1 +1 @@ -#include "name_generator.h" +#include "name_generator.h" diff --git a/library/cpp/protobuf/json/name_generator.h b/library/cpp/protobuf/json/name_generator.h index e9ce067800..2b5361bee2 100644 --- a/library/cpp/protobuf/json/name_generator.h +++ b/library/cpp/protobuf/json/name_generator.h @@ -1,18 +1,18 @@ -#pragma once - -#include <util/generic/string.h> - -#include <functional> - -namespace google { +#pragma once + +#include <util/generic/string.h> + +#include <functional> + +namespace google { namespace protobuf { class FieldDescriptor; class EnumValueDescriptor; } } - -namespace NProtobufJson { + +namespace NProtobufJson { using TNameGenerator = std::function<TString(const google::protobuf::FieldDescriptor&)>; using TEnumValueGenerator = std::function<TString(const google::protobuf::EnumValueDescriptor&)>; - + } diff --git a/library/cpp/protobuf/json/proto2json_printer.cpp b/library/cpp/protobuf/json/proto2json_printer.cpp index 31e7fe66d3..6123eab0f2 100644 --- a/library/cpp/protobuf/json/proto2json_printer.cpp +++ b/library/cpp/protobuf/json/proto2json_printer.cpp @@ -14,12 +14,12 @@ namespace NProtobufJson { TJsonKeyBuilder(const FieldDescriptor& field, const TProto2JsonConfig& config, TString& tmpBuf) : NewKeyStr(tmpBuf) { - if (config.NameGenerator) { - NewKeyStr = config.NameGenerator(field); - NewKeyBuf = NewKeyStr; - return; - } - + if (config.NameGenerator) { + NewKeyStr = config.NameGenerator(field); + NewKeyBuf = NewKeyStr; + return; + } + if (config.UseJsonName) { Y_ASSERT(!field.json_name().empty()); NewKeyStr = field.json_name(); @@ -136,11 +136,11 @@ namespace NProtobufJson { void TProto2JsonPrinter::PrintEnumValue(const TStringBuf& key, const EnumValueDescriptor* value, IJsonOutput& json) { - if (Config.EnumValueGenerator) { - WriteWithMaybeEmptyKey<InMapContext>(json, key, Config.EnumValueGenerator(*value)); - return; - } - + if (Config.EnumValueGenerator) { + WriteWithMaybeEmptyKey<InMapContext>(json, key, Config.EnumValueGenerator(*value)); + return; + } + switch (GetConfig().EnumMode) { case TProto2JsonConfig::EnumNumber: { WriteWithMaybeEmptyKey<InMapContext>(json, key, value->number()); @@ -333,7 +333,7 @@ namespace NProtobufJson { default: ythrow yexception() << "Unknown protobuf field type: " << static_cast<int>(field.cpp_type()) << "."; - } + } if (isMap) { json.EndObject(); @@ -462,7 +462,7 @@ namespace NProtobufJson { Y_ASSERT(field); PrintField(proto, *field, json); } - + // Check extensions via ListFields std::vector<const FieldDescriptor*> fields; auto* ref = proto.GetReflection(); diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 42a8ddf2c3..0dfe57bc7a 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -1,6 +1,6 @@ #include "json.h" #include "proto.h" -#include "proto2json.h" +#include "proto2json.h" #include <library/cpp/protobuf/json/ut/test.pb.h> @@ -50,11 +50,11 @@ namespace { TString ConvertToString(double value) { return FloatToString(value); } - - TString JsonValueToString(const NJson::TJsonValue& json) { - NJsonWriter::TBuf buf(NJsonWriter::HEM_UNSAFE); - return buf.WriteJsonValue(&json).Str(); - } + + TString JsonValueToString(const NJson::TJsonValue& json) { + NJsonWriter::TBuf buf(NJsonWriter::HEM_UNSAFE); + return buf.WriteJsonValue(&json).Str(); + } void TestComplexMapAsObject(std::function<void(TComplexMapType&)>&& init, const TString& json, const TJson2ProtoConfig& config = TJson2ProtoConfig().SetMapAsObject(true)) { TComplexMapType modelProto; @@ -121,13 +121,13 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); Y_UNIT_TEST(TestNameGenerator) { TJson2ProtoConfig cfg; cfg.SetNameGenerator([](const NProtoBuf::FieldDescriptor&) { return "42"; }); - + TNameGeneratorType proto; Json2Proto(TStringBuf(R"({"42":42})"), proto, cfg); - + TNameGeneratorType expected; expected.SetField(42); - + UNIT_ASSERT_PROTOS_EQUAL(expected, proto); } @@ -139,11 +139,11 @@ Y_UNIT_TEST(TestFlatNoCheckRequired) { TFlatRequired modelProto; FillFlatProto(&modelProto); UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); - } - + } + TJson2ProtoConfig cfg; cfg.CheckRequiredFields = false; - + // Try to skip each field #define DEFINE_FIELD(name, value) \ { \ @@ -154,9 +154,9 @@ Y_UNIT_TEST(TestFlatNoCheckRequired) { UNIT_ASSERT_NO_EXCEPTION(Json2Proto(json, proto, cfg)); \ } #include <library/cpp/protobuf/json/ut/fields.incl> -#undef DEFINE_FIELD +#undef DEFINE_FIELD } // TestFlatNoCheckRequired - + Y_UNIT_TEST(TestFlatRepeated){ {const NJson::TJsonValue& json = CreateRepeatedFlatJson(); TFlatRepeated proto; @@ -217,7 +217,7 @@ FillCompositeProto(&modelProto); modelProto.MutablePart()->SetDouble(42.5); UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); } - + // Try to skip each field #define DEFINE_FIELD(name, value) \ { \ @@ -237,9 +237,9 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); \ } #include <library/cpp/protobuf/json/ut/fields.incl> -#undef DEFINE_FIELD +#undef DEFINE_FIELD } // TestCompositeOptionalStringBuf - + Y_UNIT_TEST(TestCompositeRequired) { { const NJson::TJsonValue& json = CreateCompositeJson(); diff --git a/library/cpp/protobuf/json/ut/proto.h b/library/cpp/protobuf/json/ut/proto.h index db1e58557d..8183bfc8e1 100644 --- a/library/cpp/protobuf/json/ut/proto.h +++ b/library/cpp/protobuf/json/ut/proto.h @@ -55,8 +55,8 @@ namespace NProtobufJsonTest { Cerr << lhs.DebugString() << Endl; \ Cerr << rhs.DebugString() << Endl; \ UNIT_ASSERT_STRINGS_EQUAL(lhs.DebugString(), rhs.DebugString()); \ - UNIT_ASSERT_STRINGS_EQUAL(lhs.SerializeAsString(), rhs.SerializeAsString()); \ + UNIT_ASSERT_STRINGS_EQUAL(lhs.SerializeAsString(), rhs.SerializeAsString()); \ } \ - } while (false); + } while (false); } diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index 3e21b23371..07e52d7f2f 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -75,31 +75,31 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) { } Y_UNIT_TEST(TestNameGenerator) { - TNameGeneratorType proto; - proto.SetField(42); - - TProto2JsonConfig cfg; + TNameGeneratorType proto; + proto.SetField(42); + + TProto2JsonConfig cfg; cfg.SetNameGenerator([](const NProtoBuf::FieldDescriptor&) { return "42"; }); - - TStringStream str; - Proto2Json(proto, str, cfg); - - UNIT_ASSERT_STRINGS_EQUAL(R"({"42":42})", str.Str()); - } - + + TStringStream str; + Proto2Json(proto, str, cfg); + + UNIT_ASSERT_STRINGS_EQUAL(R"({"42":42})", str.Str()); + } + Y_UNIT_TEST(TestEnumValueGenerator) { - TEnumValueGeneratorType proto; - proto.SetEnum(TEnumValueGeneratorType::ENUM_42); - - TProto2JsonConfig cfg; + TEnumValueGeneratorType proto; + proto.SetEnum(TEnumValueGeneratorType::ENUM_42); + + TProto2JsonConfig cfg; cfg.SetEnumValueGenerator([](const NProtoBuf::EnumValueDescriptor&) { return "42"; }); - - TStringStream str; - Proto2Json(proto, str, cfg); - - UNIT_ASSERT_STRINGS_EQUAL(R"({"Enum":"42"})", str.Str()); - } - + + TStringStream str; + Proto2Json(proto, str, cfg); + + UNIT_ASSERT_STRINGS_EQUAL(R"({"Enum":"42"})", str.Str()); + } + Y_UNIT_TEST(TestFlatOptional){ {TFlatOptional proto; FillFlatProto(&proto); diff --git a/library/cpp/protobuf/json/ut/test.proto b/library/cpp/protobuf/json/ut/test.proto index c8352b8c52..0fa996fd41 100644 --- a/library/cpp/protobuf/json/ut/test.proto +++ b/library/cpp/protobuf/json/ut/test.proto @@ -135,18 +135,18 @@ message TMapType { map<string, string> Items = 1; }; -message TNameGeneratorType { - optional int32 Field = 1; -}; - -message TEnumValueGeneratorType { - enum EEnum { - ENUM_42 = 1; - }; - - optional EEnum Enum = 1; -}; - +message TNameGeneratorType { + optional int32 Field = 1; +}; + +message TEnumValueGeneratorType { + enum EEnum { + ENUM_42 = 1; + }; + + optional EEnum Enum = 1; +}; + message TComplexMapType { map<int32, int32> I32 = 1; map<int64, int64> I64 = 2; diff --git a/library/cpp/protobuf/json/ut/ya.make b/library/cpp/protobuf/json/ut/ya.make index 4b8ed9c804..b60a6d3c17 100644 --- a/library/cpp/protobuf/json/ut/ya.make +++ b/library/cpp/protobuf/json/ut/ya.make @@ -1,6 +1,6 @@ UNITTEST_FOR(library/cpp/protobuf/json) -OWNER(avitella) +OWNER(avitella) SRCS( filter_ut.cpp diff --git a/library/cpp/protobuf/json/ya.make b/library/cpp/protobuf/json/ya.make index a9049e5655..2f2c75cfdb 100644 --- a/library/cpp/protobuf/json/ya.make +++ b/library/cpp/protobuf/json/ya.make @@ -1,15 +1,15 @@ LIBRARY() -OWNER(avitella) +OWNER(avitella) SRCS( json2proto.cpp json_output_create.cpp json_value_output.cpp json_writer_output.cpp - name_generator.cpp - proto2json.cpp - proto2json_printer.cpp + name_generator.cpp + proto2json.cpp + proto2json_printer.cpp string_transform.cpp util.h util.cpp diff --git a/library/cpp/xml/document/ut/ya.make b/library/cpp/xml/document/ut/ya.make index 856b6ad796..e955448c66 100644 --- a/library/cpp/xml/document/ut/ya.make +++ b/library/cpp/xml/document/ut/ya.make @@ -5,7 +5,7 @@ OWNER(finder) SRCS( xml-document_ut.cpp xml-textreader_ut.cpp - xml-options_ut.cpp + xml-options_ut.cpp ) END() diff --git a/library/cpp/xml/document/xml-options.cpp b/library/cpp/xml/document/xml-options.cpp index f84e601b98..74e7545de3 100644 --- a/library/cpp/xml/document/xml-options.cpp +++ b/library/cpp/xml/document/xml-options.cpp @@ -1 +1 @@ -#include "xml-options.h" +#include "xml-options.h" diff --git a/library/cpp/xml/document/xml-options.h b/library/cpp/xml/document/xml-options.h index b81fb8c88d..bb07da0cfb 100644 --- a/library/cpp/xml/document/xml-options.h +++ b/library/cpp/xml/document/xml-options.h @@ -1,67 +1,67 @@ -#pragma once - -#include <contrib/libs/libxml/include/libxml/parser.h> - -namespace NXml { - enum class EOption : int { - // clang-format off - Recover = XML_PARSE_RECOVER, - NoEnt = XML_PARSE_NOENT, - DTDLoad = XML_PARSE_DTDLOAD, - DTDAttr = XML_PARSE_DTDATTR, - DTDValid = XML_PARSE_DTDVALID, - NoError = XML_PARSE_NOERROR, - NoWarning = XML_PARSE_NOWARNING, - Pedantic = XML_PARSE_PEDANTIC, - NoBlanks = XML_PARSE_NOBLANKS, - SAX1 = XML_PARSE_SAX1, - XInclude = XML_PARSE_XINCLUDE, - NoNet = XML_PARSE_NONET, - NoDict = XML_PARSE_NODICT, - NSClean = XML_PARSE_NSCLEAN, - NoCData = XML_PARSE_NOCDATA, - NoXInclude = XML_PARSE_NOXINCNODE, - Compact = XML_PARSE_COMPACT, - Old10 = XML_PARSE_OLD10, - NoBaseFix = XML_PARSE_NOBASEFIX, - Huge = XML_PARSE_HUGE, - OldSAX = XML_PARSE_OLDSAX, - IgnoreEnc = XML_PARSE_IGNORE_ENC, - BigLines = XML_PARSE_BIG_LINES, - // clang-format on - }; - - class TOptions { - public: - TOptions() - : Mask(0) - { - } - - template <typename... TArgs> - TOptions(TArgs... args) - : Mask(0) - { - Set(args...); - } - - TOptions& Set(EOption option) { - Mask |= static_cast<int>(option); - return *this; - } - - template <typename... TArgs> - TOptions& Set(EOption arg, TArgs... args) { - Set(arg); - return Set(args...); - } - - int GetMask() const { - return Mask; - } - - private: - int Mask; - }; - +#pragma once + +#include <contrib/libs/libxml/include/libxml/parser.h> + +namespace NXml { + enum class EOption : int { + // clang-format off + Recover = XML_PARSE_RECOVER, + NoEnt = XML_PARSE_NOENT, + DTDLoad = XML_PARSE_DTDLOAD, + DTDAttr = XML_PARSE_DTDATTR, + DTDValid = XML_PARSE_DTDVALID, + NoError = XML_PARSE_NOERROR, + NoWarning = XML_PARSE_NOWARNING, + Pedantic = XML_PARSE_PEDANTIC, + NoBlanks = XML_PARSE_NOBLANKS, + SAX1 = XML_PARSE_SAX1, + XInclude = XML_PARSE_XINCLUDE, + NoNet = XML_PARSE_NONET, + NoDict = XML_PARSE_NODICT, + NSClean = XML_PARSE_NSCLEAN, + NoCData = XML_PARSE_NOCDATA, + NoXInclude = XML_PARSE_NOXINCNODE, + Compact = XML_PARSE_COMPACT, + Old10 = XML_PARSE_OLD10, + NoBaseFix = XML_PARSE_NOBASEFIX, + Huge = XML_PARSE_HUGE, + OldSAX = XML_PARSE_OLDSAX, + IgnoreEnc = XML_PARSE_IGNORE_ENC, + BigLines = XML_PARSE_BIG_LINES, + // clang-format on + }; + + class TOptions { + public: + TOptions() + : Mask(0) + { + } + + template <typename... TArgs> + TOptions(TArgs... args) + : Mask(0) + { + Set(args...); + } + + TOptions& Set(EOption option) { + Mask |= static_cast<int>(option); + return *this; + } + + template <typename... TArgs> + TOptions& Set(EOption arg, TArgs... args) { + Set(arg); + return Set(args...); + } + + int GetMask() const { + return Mask; + } + + private: + int Mask; + }; + } diff --git a/library/cpp/xml/document/xml-options_ut.cpp b/library/cpp/xml/document/xml-options_ut.cpp index 99a5d877a8..9be16baf3d 100644 --- a/library/cpp/xml/document/xml-options_ut.cpp +++ b/library/cpp/xml/document/xml-options_ut.cpp @@ -1,26 +1,26 @@ -#include "xml-options.h" - +#include "xml-options.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TestXmlOptions) { Y_UNIT_TEST(SetHuge) { - NXml::TOptions opts; - opts.Set(NXml::EOption::Huge); - UNIT_ASSERT_EQUAL(XML_PARSE_HUGE, opts.GetMask()); - } - + NXml::TOptions opts; + opts.Set(NXml::EOption::Huge); + UNIT_ASSERT_EQUAL(XML_PARSE_HUGE, opts.GetMask()); + } + Y_UNIT_TEST(VariadicContructor) { - NXml::TOptions opts(NXml::EOption::Huge, NXml::EOption::Compact, NXml::EOption::SAX1); - UNIT_ASSERT_EQUAL(XML_PARSE_HUGE | XML_PARSE_COMPACT | XML_PARSE_SAX1, opts.GetMask()); - } - + NXml::TOptions opts(NXml::EOption::Huge, NXml::EOption::Compact, NXml::EOption::SAX1); + UNIT_ASSERT_EQUAL(XML_PARSE_HUGE | XML_PARSE_COMPACT | XML_PARSE_SAX1, opts.GetMask()); + } + Y_UNIT_TEST(Chaining) { - NXml::TOptions opts; - - opts - .Set(NXml::EOption::Huge) - .Set(NXml::EOption::Compact); - - UNIT_ASSERT_EQUAL(XML_PARSE_HUGE | XML_PARSE_COMPACT, opts.GetMask()); - } -} + NXml::TOptions opts; + + opts + .Set(NXml::EOption::Huge) + .Set(NXml::EOption::Compact); + + UNIT_ASSERT_EQUAL(XML_PARSE_HUGE | XML_PARSE_COMPACT, opts.GetMask()); + } +} diff --git a/library/cpp/xml/document/xml-textreader.cpp b/library/cpp/xml/document/xml-textreader.cpp index 0dbfe761fa..b946f1fbf2 100644 --- a/library/cpp/xml/document/xml-textreader.cpp +++ b/library/cpp/xml/document/xml-textreader.cpp @@ -11,7 +11,7 @@ namespace NXml { : Stream(stream) , IsError(false) { - Impl.Reset(xmlReaderForIO(ReadFromInputStreamCallback, nullptr, this, nullptr, nullptr, options.GetMask())); + Impl.Reset(xmlReaderForIO(ReadFromInputStreamCallback, nullptr, this, nullptr, nullptr, options.GetMask())); if (!Impl) { ythrow yexception() << "cannot instantiate underlying xmlTextReader structure"; diff --git a/library/cpp/xml/document/xml-textreader.h b/library/cpp/xml/document/xml-textreader.h index c62b958f78..ab4c329d26 100644 --- a/library/cpp/xml/document/xml-textreader.h +++ b/library/cpp/xml/document/xml-textreader.h @@ -1,7 +1,7 @@ #pragma once #include "xml-document.h" -#include "xml-options.h" +#include "xml-options.h" #include <contrib/libs/libxml/include/libxml/xmlreader.h> diff --git a/library/cpp/xml/document/ya.make b/library/cpp/xml/document/ya.make index d5ba699713..86bbd639cf 100644 --- a/library/cpp/xml/document/ya.make +++ b/library/cpp/xml/document/ya.make @@ -5,7 +5,7 @@ OWNER(finder) SRCS( xml-document.cpp xml-textreader.cpp - xml-options.cpp + xml-options.cpp ) PEERDIR( |