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
pull/1/merge
temiola 10 years ago committed by Nicolas Noble
parent ddef24620a
commit 5453555255
  1. 7
      src/compiler/ruby_generator.cc
  2. 9
      src/compiler/ruby_generator_string-inl.h
  3. 2
      src/compiler/ruby_plugin.cc

@ -83,7 +83,7 @@ void PrintService(const ServiceDescriptor* service, const string& package,
// Begin the service module // Begin the service module
map<string, string> module_vars = ListToDict({ 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->Print(module_vars, "module $module.name$\n");
out->Indent(); out->Indent();
@ -131,8 +131,9 @@ string GetServices(const FileDescriptor* file) {
"file.name", file->name(), "file.name", file->name(),
"file.package", file->package(), "file.package", file->package(),
}); });
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
out.Print(header_comment_vars, 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) { if (file->service_count() == 0) {
return output; return output;
} }
@ -152,7 +153,7 @@ string GetServices(const FileDescriptor* file) {
vector<string> modules = Split(file->package(), '.'); vector<string> modules = Split(file->package(), '.');
for (size_t i = 0; i < modules.size(); ++i) { for (size_t i = 0; i < modules.size(); ++i) {
map<string, string> module_vars = ListToDict({ 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.Print(module_vars, "module $module.name$\n");
out.Indent(); out.Indent();

@ -93,12 +93,11 @@ inline bool ReplacePrefix(string* s, const string& from, const string& to) {
return true; return true;
} }
// CapitalizeString capitalizes a string. // CapitalizeFirst capitalizes the first char in a string.
inline string CapitalizeString(string s) { inline string CapitalizeFirst(string s) {
if (!s.empty()) { if (s.empty()) {
return s; return s;
} }
transform(s.begin(), s.end(), s.begin(), ::tolower);
s[0] = ::toupper(s[0]); s[0] = ::toupper(s[0]);
return s; return s;
} }
@ -117,7 +116,7 @@ inline string RubyTypeOf(const string& a_type, const string& package) {
res += "::"; // switch '.' to the ruby module delim res += "::"; // switch '.' to the ruby module delim
} }
if (i < prefixes_and_type.size() - 1) { if (i < prefixes_and_type.size() - 1) {
res += CapitalizeString(prefixes_and_type[i]); // capitalize pkgs res += CapitalizeFirst(prefixes_and_type[i]); // capitalize pkgs
} else { } else {
res += prefixes_and_type[i]; res += prefixes_and_type[i];
} }

@ -62,7 +62,7 @@ class RubyGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
} }
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output( 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()); google::protobuf::io::CodedOutputStream coded_out(output.get());
string code = grpc_ruby_generator::GetServices(file); string code = grpc_ruby_generator::GetServices(file);
coded_out.WriteRaw(code.data(), code.size()); coded_out.WriteRaw(code.data(), code.size());

Loading…
Cancel
Save