From 54535552559beae3465a92b2f5ed53e9636d45aa Mon Sep 17 00:00:00 2001 From: temiola <temiola@google.com> Date: Tue, 6 Jan 2015 17:50:59 -0800 Subject: [PATCH] bugfix: ruby code-gen capitalization Change on 2015/01/06 by temiola <temiola@google.com> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=83391912 --- src/compiler/ruby_generator.cc | 7 ++++--- src/compiler/ruby_generator_string-inl.h | 9 ++++----- src/compiler/ruby_plugin.cc | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/ruby_generator.cc b/src/compiler/ruby_generator.cc index 64a81526fe2..e4ba387cbef 100644 --- a/src/compiler/ruby_generator.cc +++ b/src/compiler/ruby_generator.cc @@ -83,7 +83,7 @@ void PrintService(const ServiceDescriptor* service, const string& package, // Begin the service module map<string, string> module_vars = ListToDict({ - "module.name", CapitalizeString(service->name()), + "module.name", CapitalizeFirst(service->name()), }); out->Print(module_vars, "module $module.name$\n"); out->Indent(); @@ -131,8 +131,9 @@ string GetServices(const FileDescriptor* file) { "file.name", file->name(), "file.package", file->package(), }); + out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n"); out.Print(header_comment_vars, - "### Generated from $file.name$ for $file.package$\n"); + "# Source: $file.name$ for package '$file.package$'\n"); if (file->service_count() == 0) { return output; } @@ -152,7 +153,7 @@ string GetServices(const FileDescriptor* file) { vector<string> modules = Split(file->package(), '.'); for (size_t i = 0; i < modules.size(); ++i) { map<string, string> module_vars = ListToDict({ - "module.name", CapitalizeString(modules[i]), + "module.name", CapitalizeFirst(modules[i]), }); out.Print(module_vars, "module $module.name$\n"); out.Indent(); diff --git a/src/compiler/ruby_generator_string-inl.h b/src/compiler/ruby_generator_string-inl.h index f74f2c7355a..85a76fa4215 100644 --- a/src/compiler/ruby_generator_string-inl.h +++ b/src/compiler/ruby_generator_string-inl.h @@ -93,12 +93,11 @@ inline bool ReplacePrefix(string* s, const string& from, const string& to) { return true; } -// CapitalizeString capitalizes a string. -inline string CapitalizeString(string s) { - if (!s.empty()) { +// CapitalizeFirst capitalizes the first char in a string. +inline string CapitalizeFirst(string s) { + if (s.empty()) { return s; } - transform(s.begin(), s.end(), s.begin(), ::tolower); s[0] = ::toupper(s[0]); return s; } @@ -117,7 +116,7 @@ inline string RubyTypeOf(const string& a_type, const string& package) { res += "::"; // switch '.' to the ruby module delim } if (i < prefixes_and_type.size() - 1) { - res += CapitalizeString(prefixes_and_type[i]); // capitalize pkgs + res += CapitalizeFirst(prefixes_and_type[i]); // capitalize pkgs } else { res += prefixes_and_type[i]; } diff --git a/src/compiler/ruby_plugin.cc b/src/compiler/ruby_plugin.cc index 73d1508ad06..62229f92174 100644 --- a/src/compiler/ruby_plugin.cc +++ b/src/compiler/ruby_plugin.cc @@ -62,7 +62,7 @@ class RubyGrpcGenerator : public google::protobuf::compiler::CodeGenerator { } std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output( - context->OpenForInsert(file_name, "module_scope")); + context->Open(file_name)); google::protobuf::io::CodedOutputStream coded_out(output.get()); string code = grpc_ruby_generator::GetServices(file); coded_out.WriteRaw(code.data(), code.size());