Skip to content

Commit

Permalink
Auto capitalize enums name in Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun authored Aug 24, 2022
1 parent bf1a377 commit ef80643
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ruby/ext/google/protobuf_c/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,13 +1263,17 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
int n = upb_EnumDef_ValueCount(e);
for (int i = 0; i < n; i++) {
const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i);
const char* name = upb_EnumValueDef_Name(ev);
char* name = upb_EnumValueDef_Name(ev);
int32_t value = upb_EnumValueDef_Number(ev);
if (name[0] < 'A' || name[0] > 'Z') {
rb_warn(
if (name[0] >= 'a' && name[0] <= 'z') {
name[0] -= 32; // auto capitalize
} else {
rb_warn(
"Enum value '%s' does not start with an uppercase letter "
"as is required for Ruby constants.",
name);
}
}
rb_define_const(mod, name, INT2NUM(value));
}
Expand Down

0 comments on commit ef80643

Please sign in to comment.