Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the use of c++ keywords within namespace names #15954

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/google/protobuf/compiler/cpp/helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ namespace {
constexpr absl::string_view kAnyMessageName = "Any";
constexpr absl::string_view kAnyProtoFile = "google/protobuf/any.proto";

std::string DotsToColons(absl::string_view name) {
return absl::StrReplaceAll(name, {{".", "::"}});
}

static const char* const kKeywordList[] = {
// clang-format off
"NULL",
Expand Down Expand Up @@ -427,6 +423,22 @@ std::string QualifiedExtensionName(const FieldDescriptor* d) {
return QualifiedExtensionName(d, Options());
}

std::string ResolveKeyword(absl::string_view name) {
if (Keywords().count(name) > 0) {
return absl::StrCat(name, "_");
}
return std::string(name);
}

std::string DotsToColons(absl::string_view name) {
std::vector<std::string> scope =
absl::StrSplit(name, ".", absl::SkipEmpty());
for (auto &word : scope) {
word = ResolveKeyword(word);
}
return absl::StrJoin(scope, "::");
}

std::string Namespace(absl::string_view package) {
if (package.empty()) return "";
return absl::StrCat("::", DotsToColons(package));
Expand Down Expand Up @@ -504,13 +516,6 @@ std::string SuperClassName(const Descriptor* descriptor,
"::internal::", simple_base);
}

std::string ResolveKeyword(absl::string_view name) {
if (Keywords().count(name) > 0) {
return absl::StrCat(name, "_");
}
return std::string(name);
}

std::string FieldName(const FieldDescriptor* field) {
std::string result = field->name();
absl::AsciiStrToLower(&result);
Expand Down
Loading