Skip to content

Commit

Permalink
FD-101345 Don't convert enum value names to UPPER case
Browse files Browse the repository at this point in the history
  • Loading branch information
troyt-42 committed Oct 7, 2022
1 parent 00a614f commit 5fe8f21
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions src/google/protobuf/compiler/js/js_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,24 +343,6 @@ std::string ToUpperCamel(const std::string& input) {
return result;
}

// Based on code from descriptor.cc (Thanks Kenton!)
// Uppercases the entire string, turning ValueName into
// VALUENAME.
std::string ToEnumCase(const std::string& input) {
std::string result;
result.reserve(input.size());

for (int i = 0; i < input.size(); i++) {
if ('a' <= input[i] && input[i] <= 'z') {
result.push_back(input[i] - 'a' + 'A');
} else {
result.push_back(input[i]);
}
}

return result;
}

std::string ToLower(const std::string& input) {
std::string result;
result.reserve(input.size());
Expand Down Expand Up @@ -2160,9 +2142,9 @@ void Generator::GenerateOneofCaseDefinition(
" * @enum {number}\n"
" */\n"
"$classname$.$oneof$Case = {\n"
" $upcase$_NOT_SET: 0",
" $name$_NOT_SET: 0",
"classname", GetMessagePath(options, oneof->containing_type()), "oneof",
JSOneofName(oneof), "upcase", ToEnumCase(oneof->name()));
JSOneofName(oneof), "name", oneof->name());

for (int i = 0; i < oneof->field_count(); i++) {
if (IgnoreField(oneof->field(i))) {
Expand All @@ -2171,8 +2153,8 @@ void Generator::GenerateOneofCaseDefinition(

printer->Print(
",\n"
" $upcase$: $number$",
"upcase", ToEnumCase(oneof->field(i)->name()), "number",
" $name$: $number$",
"name", oneof->field(i)->name(), "number",
JSFieldIndex(oneof->field(i)));
printer->Annotate("upcase", oneof->field(i));
}
Expand Down Expand Up @@ -3418,15 +3400,15 @@ void Generator::GenerateEnum(const GeneratorOptions& options,
std::vector<int> valid_index;
for (int i = 0; i < enumdesc->value_count(); i++) {
if (enumdesc->options().allow_alias() &&
!used_name.insert(ToEnumCase(enumdesc->value(i)->name())).second) {
!used_name.insert(enumdesc->value(i)->name()).second) {
continue;
}
valid_index.push_back(i);
}
for (auto i : valid_index) {
const EnumValueDescriptor* value = enumdesc->value(i);
printer->Print(" $name$: $value$$comma$\n", "name",
ToEnumCase(value->name()), "value", StrCat(value->number()),
value->name(), "value", StrCat(value->number()),
"comma", (i == valid_index.back()) ? "" : ",");
printer->Annotate("name", value);
}
Expand Down

0 comments on commit 5fe8f21

Please sign in to comment.