[OBJC] Don't add unnecessary prefixes to service class names (#28554)

* [OBJC] Don't add unnecessary prefixes to service class names

This is the same semantics as the Objective-C protoc.

This prevents cases where you have an RPC named `FOOOpener` and a objc class prefix of `FOO` becoming `FOOFOOOpener`.

* Update objective_c_generator_helpers.h

Apply "sanity" check

* Update objective_c_generator_helpers.h

Fix up bad namespacing

* Update objective_c_generator_helpers.h

adding `::std::string`. Not quite sure why it's needed, but apparently it's a thing.

* Update objective_c_generator_helpers.h

Missing semi-colon. Hopefully caffeine will kick in at some point today... thanks tvl.

* Automated change: Fix sanity tests

Co-authored-by: dmaclach <dmaclach@users.noreply.github.com>
pull/28486/head
dmaclach 3 years ago committed by GitHub
parent b38b706200
commit d4e09406c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      src/compiler/objective_c_generator_helpers.h

@ -36,10 +36,30 @@ inline string MessageHeaderName(const FileDescriptor* file) {
return google::protobuf::compiler::objectivec::FilePath(file) + ".pbobjc.h";
}
inline string ServiceClassName(const ServiceDescriptor* service) {
inline bool AsciiIsUpper(char c) { return c >= 'A' && c <= 'Z'; }
inline ::std::string ServiceClassName(const ServiceDescriptor* service) {
const FileDescriptor* file = service->file();
string prefix = google::protobuf::compiler::objectivec::FileClassPrefix(file);
return prefix + service->name();
::std::string prefix =
google::protobuf::compiler::objectivec::FileClassPrefix(file);
::std::string class_name = service->name();
// We add the prefix in the cases where the string is missing a prefix.
// We define "missing a prefix" as where 'input':
// a) Doesn't start with the prefix or
// b) Isn't equivalent to the prefix or
// c) Has the prefix, but the letter after the prefix is lowercase
// This is the same semantics as the Objective-C protoc.
// https://github.com/protocolbuffers/protobuf/blob/c160ae52a91ca4c76936531d68cc846f8230dbb1/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc#L389
if (class_name.rfind(prefix, 0) == 0) {
if (class_name.length() == prefix.length() ||
!AsciiIsUpper(class_name[prefix.length()])) {
return prefix + class_name;
} else {
return class_name;
}
} else {
return prefix + class_name;
}
}
inline ::std::string LocalImport(const ::std::string& import) {

Loading…
Cancel
Save