aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/json
diff options
context:
space:
mode:
authorsobols <sobols@yandex-team.ru>2022-02-10 16:47:08 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:08 +0300
commit09961b69c61f471ddd594e0fd877df62a8021562 (patch)
tree54a7b60a9526a7104557a033eb0a8d70d64b604c /library/cpp/protobuf/json
parent4ce8835206f981afa4a61915a49a21fb750416ec (diff)
downloadydb-09961b69c61f471ddd594e0fd877df62a8021562.tar.gz
Restoring authorship annotation for <sobols@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/protobuf/json')
-rw-r--r--library/cpp/protobuf/json/json2proto.cpp26
-rw-r--r--library/cpp/protobuf/json/json2proto.h4
-rw-r--r--library/cpp/protobuf/json/ut/json2proto_ut.cpp30
-rw-r--r--library/cpp/protobuf/json/ut/util_ut.cpp84
-rw-r--r--library/cpp/protobuf/json/ut/ya.make2
-rw-r--r--library/cpp/protobuf/json/util.cpp50
-rw-r--r--library/cpp/protobuf/json/util.h10
7 files changed, 103 insertions, 103 deletions
diff --git a/library/cpp/protobuf/json/json2proto.cpp b/library/cpp/protobuf/json/json2proto.cpp
index 640c10f5a5..ba6f2859f3 100644
--- a/library/cpp/protobuf/json/json2proto.cpp
+++ b/library/cpp/protobuf/json/json2proto.cpp
@@ -110,18 +110,18 @@ JsonString2Field(const NJson::TJsonValue& json,
reflection->SetString(&proto, &field, value);
}
-static const NProtoBuf::EnumValueDescriptor*
-FindEnumValue(const NProtoBuf::EnumDescriptor* enumField,
- TStringBuf target, bool (*equals)(TStringBuf, TStringBuf)) {
- for (int i = 0; i < enumField->value_count(); i++) {
- auto* valueDescriptor = enumField->value(i);
- if (equals(valueDescriptor->name(), target)) {
- return valueDescriptor;
- }
- }
- return nullptr;
-}
-
+static const NProtoBuf::EnumValueDescriptor*
+FindEnumValue(const NProtoBuf::EnumDescriptor* enumField,
+ TStringBuf target, bool (*equals)(TStringBuf, TStringBuf)) {
+ for (int i = 0; i < enumField->value_count(); i++) {
+ auto* valueDescriptor = enumField->value(i);
+ if (equals(valueDescriptor->name(), target)) {
+ return valueDescriptor;
+ }
+ }
+ return nullptr;
+}
+
static void
JsonEnum2Field(const NJson::TJsonValue& json,
google::protobuf::Message& proto,
@@ -148,7 +148,7 @@ JsonEnum2Field(const NJson::TJsonValue& json,
const auto& value = json.GetString();
if (config.EnumValueMode == NProtobufJson::TJson2ProtoConfig::EnumCaseInsensetive) {
enumFieldValue = FindEnumValue(enumField, value, AsciiEqualsIgnoreCase);
- } else if (config.EnumValueMode == NProtobufJson::TJson2ProtoConfig::EnumSnakeCaseInsensitive) {
+ } else if (config.EnumValueMode == NProtobufJson::TJson2ProtoConfig::EnumSnakeCaseInsensitive) {
enumFieldValue = FindEnumValue(enumField, value, NProtobufJson::EqualsIgnoringCaseAndUnderscores);
} else {
enumFieldValue = enumField->FindValueByName(value);
diff --git a/library/cpp/protobuf/json/json2proto.h b/library/cpp/protobuf/json/json2proto.h
index 4c33498dfa..5e7cff44b4 100644
--- a/library/cpp/protobuf/json/json2proto.h
+++ b/library/cpp/protobuf/json/json2proto.h
@@ -32,8 +32,8 @@ namespace NProtobufJson {
enum EnumValueMode {
EnumCaseSensetive = 0, // default
- EnumCaseInsensetive,
- EnumSnakeCaseInsensitive
+ EnumCaseInsensetive,
+ EnumSnakeCaseInsensitive
};
TSelf& SetFieldNameMode(FldNameMode mode) {
diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp
index 0dfe57bc7a..377b1d7836 100644
--- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp
+++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp
@@ -928,21 +928,21 @@ Y_UNIT_TEST(TestComplexMapAsObject_EnumStringCaseInsensetive) {
);
} // TestComplexMapAsObject_EnumStringCaseInsensetive
-Y_UNIT_TEST(TestComplexMapAsObject_EnumStringSnakeCaseInsensitive) {
- TestComplexMapAsObject(
- [](TComplexMapType& proto) {
- auto& items = *proto.MutableEnum();
- items["key1"] = EEnum::E_1;
- items["key2"] = EEnum::E_2;
- items["key3"] = EEnum::E_3;
- },
- R"_({"Enum":{"key1":"e1","key2":"_E_2_","key3":"e_3"}})_",
- TJson2ProtoConfig()
- .SetMapAsObject(true)
- .SetEnumValueMode(NProtobufJson::TJson2ProtoConfig::EnumSnakeCaseInsensitive)
- );
-} // TestComplexMapAsObject_EnumStringCaseInsensetive
-
+Y_UNIT_TEST(TestComplexMapAsObject_EnumStringSnakeCaseInsensitive) {
+ TestComplexMapAsObject(
+ [](TComplexMapType& proto) {
+ auto& items = *proto.MutableEnum();
+ items["key1"] = EEnum::E_1;
+ items["key2"] = EEnum::E_2;
+ items["key3"] = EEnum::E_3;
+ },
+ R"_({"Enum":{"key1":"e1","key2":"_E_2_","key3":"e_3"}})_",
+ TJson2ProtoConfig()
+ .SetMapAsObject(true)
+ .SetEnumValueMode(NProtobufJson::TJson2ProtoConfig::EnumSnakeCaseInsensitive)
+ );
+} // TestComplexMapAsObject_EnumStringCaseInsensetive
+
Y_UNIT_TEST(TestComplexMapAsObject_Float) {
TestComplexMapAsObject(
[](TComplexMapType& proto) {
diff --git a/library/cpp/protobuf/json/ut/util_ut.cpp b/library/cpp/protobuf/json/ut/util_ut.cpp
index 05101dca28..0d22ce86d4 100644
--- a/library/cpp/protobuf/json/ut/util_ut.cpp
+++ b/library/cpp/protobuf/json/ut/util_ut.cpp
@@ -1,42 +1,42 @@
-#include <library/cpp/protobuf/json/util.h>
-
-#include <library/cpp/testing/unittest/registar.h>
-
-using namespace NProtobufJson;
-
-Y_UNIT_TEST_SUITE(TEqualsTest) {
- Y_UNIT_TEST(TestEmpty) {
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("", ""));
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("", "_"));
- UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("f", ""));
- }
-
- Y_UNIT_TEST(TestTrivial) {
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("f", "f"));
- UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("f", "o"));
- UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("fo", "f"));
- UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("f", "fo"));
- UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("bar", "baz"));
- }
-
- Y_UNIT_TEST(TestUnderscores) {
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foo_bar", "foobar"));
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foo_bar_", "foobar"));
- UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("foo_bar_z", "foobar"));
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foo__bar__", "foobar"));
- UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("foo__bar__z", "foobar"));
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("_foo_bar", "foobar"));
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("_foo_bar_", "foobar"));
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("_foo_bar_", "foo___bar"));
- }
-
- Y_UNIT_TEST(TestCase) {
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foo_bar", "FOO_BAR"));
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foobar", "fooBar"));
- }
-
- Y_UNIT_TEST(TestCaseAndUnderscores) {
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("fooBar", "FOO_BAR"));
- UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("FOO_BAR_BAZ", "fooBar_BAZ"));
- }
-}
+#include <library/cpp/protobuf/json/util.h>
+
+#include <library/cpp/testing/unittest/registar.h>
+
+using namespace NProtobufJson;
+
+Y_UNIT_TEST_SUITE(TEqualsTest) {
+ Y_UNIT_TEST(TestEmpty) {
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("", ""));
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("", "_"));
+ UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("f", ""));
+ }
+
+ Y_UNIT_TEST(TestTrivial) {
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("f", "f"));
+ UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("f", "o"));
+ UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("fo", "f"));
+ UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("f", "fo"));
+ UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("bar", "baz"));
+ }
+
+ Y_UNIT_TEST(TestUnderscores) {
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foo_bar", "foobar"));
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foo_bar_", "foobar"));
+ UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("foo_bar_z", "foobar"));
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foo__bar__", "foobar"));
+ UNIT_ASSERT(!EqualsIgnoringCaseAndUnderscores("foo__bar__z", "foobar"));
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("_foo_bar", "foobar"));
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("_foo_bar_", "foobar"));
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("_foo_bar_", "foo___bar"));
+ }
+
+ Y_UNIT_TEST(TestCase) {
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foo_bar", "FOO_BAR"));
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("foobar", "fooBar"));
+ }
+
+ Y_UNIT_TEST(TestCaseAndUnderscores) {
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("fooBar", "FOO_BAR"));
+ UNIT_ASSERT(EqualsIgnoringCaseAndUnderscores("FOO_BAR_BAZ", "fooBar_BAZ"));
+ }
+}
diff --git a/library/cpp/protobuf/json/ut/ya.make b/library/cpp/protobuf/json/ut/ya.make
index b60a6d3c17..966d481639 100644
--- a/library/cpp/protobuf/json/ut/ya.make
+++ b/library/cpp/protobuf/json/ut/ya.make
@@ -11,7 +11,7 @@ SRCS(
string_transform_ut.cpp
filter_ut.proto
test.proto
- util_ut.cpp
+ util_ut.cpp
)
GENERATE_ENUM_SERIALIZATION(test.pb.h)
diff --git a/library/cpp/protobuf/json/util.cpp b/library/cpp/protobuf/json/util.cpp
index 53a065eee2..c0c90c0e5c 100644
--- a/library/cpp/protobuf/json/util.cpp
+++ b/library/cpp/protobuf/json/util.cpp
@@ -39,7 +39,7 @@ namespace {
}
}
}
-
+
namespace NProtobufJson {
void ToSnakeCase(TString* const name) {
ToSnakeCaseImpl(name, [](const char prev) { return prev != '_'; });
@@ -49,28 +49,28 @@ namespace NProtobufJson {
ToSnakeCaseImpl(name, [](const char prev) { return prev != '_' && !IsAsciiUpper(prev); });
}
- bool EqualsIgnoringCaseAndUnderscores(TStringBuf s1, TStringBuf s2) {
- size_t i1 = 0, i2 = 0;
-
- while (i1 < s1.size() && i2 < s2.size()) {
- if (s1[i1] == '_') {
- ++i1;
- } else if (s2[i2] == '_') {
- ++i2;
- } else if (AsciiToUpper(s1[i1]) != AsciiToUpper(s2[i2])) {
- return false;
- } else {
- ++i1, ++i2;
- }
- }
-
- while (i1 < s1.size() && s1[i1] == '_') {
- ++i1;
- }
- while (i2 < s2.size() && s2[i2] == '_') {
- ++i2;
- }
-
- return (i1 == s1.size() && i2 == s2.size());
- }
+ bool EqualsIgnoringCaseAndUnderscores(TStringBuf s1, TStringBuf s2) {
+ size_t i1 = 0, i2 = 0;
+
+ while (i1 < s1.size() && i2 < s2.size()) {
+ if (s1[i1] == '_') {
+ ++i1;
+ } else if (s2[i2] == '_') {
+ ++i2;
+ } else if (AsciiToUpper(s1[i1]) != AsciiToUpper(s2[i2])) {
+ return false;
+ } else {
+ ++i1, ++i2;
+ }
+ }
+
+ while (i1 < s1.size() && s1[i1] == '_') {
+ ++i1;
+ }
+ while (i2 < s2.size() && s2[i2] == '_') {
+ ++i2;
+ }
+
+ return (i1 == s1.size() && i2 == s2.size());
+ }
}
diff --git a/library/cpp/protobuf/json/util.h b/library/cpp/protobuf/json/util.h
index d93342d3f8..7ee2405afd 100644
--- a/library/cpp/protobuf/json/util.h
+++ b/library/cpp/protobuf/json/util.h
@@ -4,11 +4,11 @@
namespace NProtobufJson {
void ToSnakeCase(TString* const name);
-
+
void ToSnakeCaseDense(TString* const name);
- /**
- * "FOO_BAR" ~ "foo_bar" ~ "fooBar"
- */
- bool EqualsIgnoringCaseAndUnderscores(TStringBuf s1, TStringBuf s2);
+ /**
+ * "FOO_BAR" ~ "foo_bar" ~ "fooBar"
+ */
+ bool EqualsIgnoringCaseAndUnderscores(TStringBuf s1, TStringBuf s2);
}