From ef80643eb22daab37c74137bea265607d572f78f Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 24 Aug 2022 11:14:34 +0800 Subject: [PATCH] Auto capitalize enums name in Ruby This closes #1965. --- ruby/ext/google/protobuf_c/message.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index b11878545f039..d0481673252c2 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -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)); }