Skip to content

Commit

Permalink
Fix lowerCamelCase to UpperCamelCase (per Cpp style guide)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 595753465
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 4, 2024
1 parent fbbe681 commit 8d36600
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/google/protobuf/compiler/rust/enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ namespace rust {

namespace {

std::string enumName(const EnumDescriptor& desc) {
std::string EnumName(const EnumDescriptor& desc) {
return cpp::UnderscoresToCamelCase(desc.name(), /*cap first letter=*/true);
}

// Constructs input for `EnumValues` from an enum descriptor.
std::vector<std::pair<absl::string_view, int32_t>> enumValuesInput(
std::vector<std::pair<absl::string_view, int32_t>> EnumValuesInput(
const EnumDescriptor& desc) {
std::vector<std::pair<absl::string_view, int32_t>> result;
result.reserve(static_cast<size_t>(desc.value_count()));
Expand Down Expand Up @@ -165,10 +165,10 @@ std::string ScreamingSnakeToUpperCamelCase(absl::string_view input) {
}

void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc) {
std::string name = enumName(desc);
std::string name = EnumName(desc);
ABSL_CHECK(desc.value_count() > 0);
std::vector<RustEnumValue> values =
EnumValues(desc.name(), enumValuesInput(desc));
EnumValues(desc.name(), EnumValuesInput(desc));
ABSL_CHECK(!values.empty());

ctx.Emit(
Expand Down
22 changes: 11 additions & 11 deletions src/google/protobuf/compiler/rust/oneof.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ std::string ToCamelCase(absl::string_view name) {
return cpp::UnderscoresToCamelCase(name, /* upper initial letter */ true);
}

std::string oneofViewEnumRsName(const OneofDescriptor& oneof) {
std::string OneofViewEnumRsName(const OneofDescriptor& oneof) {
return ToCamelCase(oneof.name());
}

std::string oneofMutEnumRsName(const OneofDescriptor& oneof) {
std::string OneofMutEnumRsName(const OneofDescriptor& oneof) {
return ToCamelCase(oneof.name()) + "Mut";
}

std::string oneofCaseEnumName(const OneofDescriptor& oneof) {
std::string OneofCaseEnumName(const OneofDescriptor& oneof) {
// Note: This is the name used for the cpp Case enum, we use it for both
// the Rust Case enum as well as for the cpp case enum in the cpp thunk.
return ToCamelCase(oneof.name()) + "Case";
Expand Down Expand Up @@ -167,8 +167,8 @@ std::string RsTypeNameMut(Context& ctx, const FieldDescriptor& field) {

void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) {
ctx.Emit(
{{"view_enum_name", oneofViewEnumRsName(oneof)},
{"mut_enum_name", oneofMutEnumRsName(oneof)},
{{"view_enum_name", OneofViewEnumRsName(oneof)},
{"mut_enum_name", OneofMutEnumRsName(oneof)},
{"view_fields",
[&] {
for (int i = 0; i < oneof.field_count(); ++i) {
Expand Down Expand Up @@ -230,7 +230,7 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) {

// Note: This enum is used as the Thunk return type for getting which case is
// used: it exactly matches the generate case enum that both cpp and upb use.
ctx.Emit({{"case_enum_name", oneofCaseEnumName(oneof)},
ctx.Emit({{"case_enum_name", OneofCaseEnumName(oneof)},
{"cases",
[&] {
for (int i = 0; i < oneof.field_count(); ++i) {
Expand Down Expand Up @@ -258,9 +258,9 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) {
void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) {
ctx.Emit(
{{"oneof_name", oneof.name()},
{"view_enum_name", oneofViewEnumRsName(oneof)},
{"mut_enum_name", oneofMutEnumRsName(oneof)},
{"case_enum_name", oneofCaseEnumName(oneof)},
{"view_enum_name", OneofViewEnumRsName(oneof)},
{"mut_enum_name", OneofMutEnumRsName(oneof)},
{"case_enum_name", OneofCaseEnumName(oneof)},
{"view_cases",
[&] {
for (int i = 0; i < oneof.field_count(); ++i) {
Expand Down Expand Up @@ -341,7 +341,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) {
void GenerateOneofExternC(Context& ctx, const OneofDescriptor& oneof) {
ctx.Emit(
{
{"case_enum_rs_name", oneofCaseEnumName(oneof)},
{"case_enum_rs_name", OneofCaseEnumName(oneof)},
{"case_thunk", ThunkName(ctx, oneof, "case")},
},
R"rs(
Expand All @@ -353,7 +353,7 @@ void GenerateOneofThunkCc(Context& ctx, const OneofDescriptor& oneof) {
ctx.Emit(
{
{"oneof_name", oneof.name()},
{"case_enum_name", oneofCaseEnumName(oneof)},
{"case_enum_name", OneofCaseEnumName(oneof)},
{"case_thunk", ThunkName(ctx, oneof, "case")},
{"QualifiedMsg", cpp::QualifiedClassName(oneof.containing_type())},
},
Expand Down

0 comments on commit 8d36600

Please sign in to comment.