Skip to content

Commit 20d3ae3

Browse files
j2objc-copybaracopybara-github
authored andcommitted
Make code forward-compatible with returning string_view in protobuf descriptor API.
PiperOrigin-RevId: 715359147
1 parent ee14b71 commit 20d3ae3

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

protobuf/compiler/src/google/protobuf/compiler/protolite/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#ifndef GOOGLE_PROTOBUF_COMPILER_J2OBJC_COMMON_H__
4141
#define GOOGLE_PROTOBUF_COMPILER_J2OBJC_COMMON_H__
4242

43+
#include "absl/strings/str_cat.h"
4344
#include "absl/strings/str_replace.h"
4445
#include "google/protobuf/compiler/code_generator.h"
4546
#include "google/protobuf/io/printer.h"

protobuf/compiler/src/google/protobuf/compiler/protolite/j2objc_helpers.cc

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ std::string GetPackagePrefix(const FileDescriptor *file) {
9797
const UnknownField *package_prefix_field =
9898
FindUnknownField(file, kPackagePrefixFieldNumber);
9999
if (package_prefix_field) {
100-
return globalPrefix + package_prefix_field->length_delimited();
100+
return absl::StrCat(globalPrefix, package_prefix_field->length_delimited());
101101
}
102102

103103
// Look for a matching prefix from the prefixes file.
@@ -221,8 +221,8 @@ bool HasConflictingClassName(const FileDescriptor *file,
221221

222222
std::string FileBaseName(const FileDescriptor *file) {
223223
std::string::size_type last_slash = file->name().find_last_of('/');
224-
return last_slash == std::string::npos ? file->name()
225-
: file->name().substr(last_slash + 1);
224+
return std::string(last_slash == std::string::npos ? file->name()
225+
: file->name().substr(last_slash + 1));
226226
}
227227

228228
std::string FileJavaPackage(const FileDescriptor *file) {
@@ -248,32 +248,37 @@ std::string JavaPackageToDir(std::string package_name) {
248248
}
249249

250250
std::string ClassName(const Descriptor *descriptor) {
251-
return GetClassPrefix(descriptor->file(), descriptor->containing_type()) +
252-
descriptor->name() + globalPostfix;
251+
return absl::StrCat(GetClassPrefix(descriptor->file(),
252+
descriptor->containing_type()),
253+
descriptor->name(), globalPostfix);
253254
}
254255

255256
std::string ClassName(const EnumDescriptor *descriptor) {
256-
return GetClassPrefix(descriptor->file(), descriptor->containing_type()) +
257-
descriptor->name() + globalPostfix;
257+
return absl::StrCat(GetClassPrefix(descriptor->file(),
258+
descriptor->containing_type()),
259+
descriptor->name(), globalPostfix);
258260
}
259261

260262
std::string ClassName(const FileDescriptor *descriptor) {
261-
return GetPackagePrefix(descriptor) + FileClassName(descriptor) +
262-
globalPostfix;
263+
return absl::StrCat(GetPackagePrefix(descriptor), FileClassName(descriptor),
264+
globalPostfix);
263265
}
264266

265267
std::string JavaClassName(const Descriptor *descriptor) {
266-
return GetJavaClassPrefix(descriptor->file(), descriptor->containing_type())
267-
+ "." + descriptor->name();
268+
return absl::StrCat(GetJavaClassPrefix(descriptor->file(),
269+
descriptor->containing_type()),
270+
".", descriptor->name());
268271
}
269272

270273
std::string JavaClassName(const EnumDescriptor *descriptor) {
271-
return GetJavaClassPrefix(descriptor->file(), descriptor->containing_type())
272-
+ "." + descriptor->name();
274+
return absl::StrCat(GetJavaClassPrefix(descriptor->file(),
275+
descriptor->containing_type()),
276+
".", descriptor->name());
273277
}
274278

275279
std::string JavaClassName(const FileDescriptor *descriptor) {
276-
return FileJavaPackage(descriptor) + "." + FileClassName(descriptor);
280+
return absl::StrCat(FileJavaPackage(descriptor), ".",
281+
FileClassName(descriptor));
277282
}
278283

279284
std::string MappedInputName(const FileDescriptor *file) {

0 commit comments

Comments
 (0)