1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC. All rights reserved.
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"
12 #include "absl/strings/str_replace.h"
13 #include "absl/strings/string_view.h"
14 #include "upb_generator/minitable/names_internal.h"
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"}, {".", "__"}});
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