This is an automated email from the ASF dual-hosted git repository.

allengeorge pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 372ada9  THRIFT-5363 Render constant names correctly (#2343)
372ada9 is described below

commit 372ada90df60c7c4d0cc48da5f09c6988950049c
Author: Allen George <[email protected]>
AuthorDate: Sun Mar 7 09:03:52 2021 -0500

    THRIFT-5363 Render constant names correctly (#2343)
    
    Client: rs
---
 compiler/cpp/src/thrift/generate/t_rs_generator.cc | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/compiler/cpp/src/thrift/generate/t_rs_generator.cc 
b/compiler/cpp/src/thrift/generate/t_rs_generator.cc
index 78064fd..e113604 100644
--- a/compiler/cpp/src/thrift/generate/t_rs_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_rs_generator.cc
@@ -3318,7 +3318,7 @@ string t_rs_generator::rust_enum_variant_name(const 
string &name) {
   bool all_uppercase = true;
 
   for (char i : name) {
-    if (isalnum(i) && islower(i)) {
+    if (isalpha(i) && islower(i)) {
       all_uppercase = false;
       break;
     }
@@ -3334,9 +3334,22 @@ string t_rs_generator::rust_enum_variant_name(const 
string &name) {
 }
 
 string t_rs_generator::rust_upper_case(const string& name) {
-  string str(uppercase(underscore(name)));
-  string_replace(str, "__", "_");
-  return str;
+  bool all_uppercase = true;
+
+  for (char i : name) {
+    if (isalpha(i) && islower(i)) {
+      all_uppercase = false;
+      break;
+    }
+  }
+
+  if (all_uppercase) {
+    return name;
+  } else {
+    string str(uppercase(underscore(name)));
+    string_replace(str, "__", "_");
+    return str;
+  }
 }
 
 string t_rs_generator::rust_snake_case(const string& name) {

Reply via email to