From aef81d632f7605835e83d3610695fb5c3a281be8 Mon Sep 17 00:00:00 2001 From: Mark Erickson Date: Mon, 7 Mar 2016 11:01:34 -0600 Subject: [PATCH] THRIFT-3710 Dart generator does not camel case Constants class names Client: Dart This closes #922 --- compiler/cpp/src/generate/t_dart_generator.cc | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/compiler/cpp/src/generate/t_dart_generator.cc b/compiler/cpp/src/generate/t_dart_generator.cc index 3d7f59775..1bd2ce621 100644 --- a/compiler/cpp/src/generate/t_dart_generator.cc +++ b/compiler/cpp/src/generate/t_dart_generator.cc @@ -180,6 +180,7 @@ public: std::string get_args_class_name(std::string name); std::string get_result_class_name(std::string name); std::string get_file_name(std::string name); + std::string get_class_name(std::string name); std::string generate_isset_check(t_field* field); std::string generate_isset_check(std::string field); void generate_isset_set(ofstream& out, t_field* field); @@ -534,7 +535,7 @@ void t_dart_generator::generate_consts(std::vector consts) { return; } - string class_name = get_cap_name(program_name_) + "Constants"; + string class_name = get_class_name(program_name_) + "Constants"; string file_name = get_file_name(class_name); string f_consts_name = src_dir_ + "/" + file_name + ".dart"; @@ -2360,6 +2361,29 @@ std::string t_dart_generator::get_file_name(std::string name) { return ret; } +std::string t_dart_generator::get_class_name(std::string name) { + // e.g. change my_great_model to MyGreatModel + string ret; + const char* tmp = name.c_str(); + bool is_prev_underscore = true; + + for (unsigned int i = 0; i < name.length(); i++) { + if (tmp[i] == '_') { + is_prev_underscore = true; + } else { + if (is_prev_underscore) { + ret += toupper(tmp[i]); + } else { + ret += tmp[i]; + } + + is_prev_underscore = false; + } + } + + return ret; +} + string t_dart_generator::constant_name(string name) { string constant_name;