Automated rollback of commit 694d7935747a5b4eac351b757ad8ff22599c8077.
[google-protobuf.git] / upb_generator / minitable / names.cc
blob976f7723701c8772c5daf5c82eb326a0f2efd311
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
8 #include "upb_generator/minitable/names.h"
10 #include <string>
12 #include "absl/strings/str_replace.h"
13 #include "absl/strings/string_view.h"
14 #include "upb_generator/minitable/names_internal.h"
16 namespace upb {
17 namespace generator {
19 namespace {
21 std::string ToCIdent(absl::string_view str) {
22 return absl::StrReplaceAll(str, {{".", "_"}, {"/", "_"}, {"-", "_"}});
25 std::string MangleName(absl::string_view name) {
26 return absl::StrReplaceAll(name, {{"_", "_0"}, {".", "__"}});
29 } // namespace
31 std::string MiniTableHeaderFilename(absl::string_view proto_filename) {
32 return MiniTableHeaderFilename(proto_filename, false);
35 std::string MiniTableMessageVarName(absl::string_view full_name) {
36 return MangleName(full_name) + "_msg_init";
39 std::string MiniTableMessagePtrVarName(absl::string_view full_name) {
40 return MiniTableMessageVarName(full_name) + "_ptr";
43 std::string MiniTableEnumVarName(absl::string_view full_name) {
44 return MangleName(full_name) + "_enum_init";
47 std::string MiniTableExtensionVarName(absl::string_view full_name) {
48 return ToCIdent(full_name) + "_ext";
51 std::string MiniTableFileVarName(absl::string_view proto_filename) {
52 return ToCIdent(proto_filename) + "_upb_file_layout";
55 } // namespace generator
56 } // namespace upb