summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yt/yt/core/yson/protobuf_interop.cpp11
-rw-r--r--yt/yt/core/yson/unittests/proto/protobuf_yson_casing_ut.proto7
-rw-r--r--yt/yt/core/yson/unittests/protobuf_yson_ut.cpp2
3 files changed, 15 insertions, 5 deletions
diff --git a/yt/yt/core/yson/protobuf_interop.cpp b/yt/yt/core/yson/protobuf_interop.cpp
index 5900fe24d23..59f62915874 100644
--- a/yt/yt/core/yson/protobuf_interop.cpp
+++ b/yt/yt/core/yson/protobuf_interop.cpp
@@ -132,14 +132,15 @@ bool IsMapKeyType(FieldDescriptor::Type type)
TString ToUnderscoreCase(const TString& protobufName)
{
TStringBuilder builder;
- for (auto ch : protobufName) {
- if (isupper(ch)) {
- if (builder.GetLength() > 0 && builder.GetBuffer()[builder.GetLength() - 1] != '_') {
+ for (size_t i = 0; i < protobufName.size(); ++i) {
+ if (isupper(protobufName[i])) {
+ size_t length = builder.GetLength();
+ if (length && builder.GetBuffer()[length - 1] != '_' && !isupper(protobufName[i - 1])) {
builder.AppendChar('_');
}
- builder.AppendChar(tolower(ch));
+ builder.AppendChar(tolower(protobufName[i]));
} else {
- builder.AppendChar(ch);
+ builder.AppendChar(protobufName[i]);
}
}
return builder.Flush();
diff --git a/yt/yt/core/yson/unittests/proto/protobuf_yson_casing_ut.proto b/yt/yt/core/yson/unittests/proto/protobuf_yson_casing_ut.proto
index 627d6e23ad3..65fea7bc699 100644
--- a/yt/yt/core/yson/unittests/proto/protobuf_yson_casing_ut.proto
+++ b/yt/yt/core/yson/unittests/proto/protobuf_yson_casing_ut.proto
@@ -6,7 +6,14 @@ option (NYT.NYson.NProto.derive_underscore_case_names) = true;
message TCamelCaseStyleMessage
{
+ enum EEnum
+ {
+ VALUE_NONE = 0;
+ VALUE_FIRST = 1;
+ }
+
optional int32 SomeField = 1;
optional int32 AnotherField123 = 2;
optional int32 Crazy_Field = 3;
+ optional EEnum EnumField = 4;
}
diff --git a/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp b/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp
index ebc8afc360d..d6d97d6c1fe 100644
--- a/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp
+++ b/yt/yt/core/yson/unittests/protobuf_yson_ut.cpp
@@ -1822,6 +1822,7 @@ TEST(TProtobufToYsonTest, Casing)
message.set_somefield(1);
message.set_anotherfield123(2);
message.set_crazy_field(3);
+ message.set_enumfield(NYT::NYson::NProto::TCamelCaseStyleMessage::VALUE_FIRST);
TEST_PROLOGUE()
Y_PROTOBUF_SUPPRESS_NODISCARD message.SerializeToCodedStream(&codedStream);
@@ -1833,6 +1834,7 @@ TEST(TProtobufToYsonTest, Casing)
.Item("some_field").Value(1)
.Item("another_field123").Value(2)
.Item("crazy_field").Value(3)
+ .Item("enum_field").Value("value_first")
.EndMap();
EXPECT_TRUE(AreNodesEqual(writtenNode, expectedNode));
}