Add missing enum case in TypeKind calculation.
[google-protobuf.git] / upb_generator / common / names.cc
blob8cec63fdbe5a67d66e0eafddaeff8bb222ecba32
1 // Copyright (c) 2009-2024, Google LLC
2 // 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/common/names.h"
10 #include <cstddef>
11 #include <string>
13 #include "absl/strings/ascii.h"
14 #include "absl/strings/str_cat.h"
15 #include "absl/strings/str_replace.h"
16 #include "absl/strings/string_view.h"
17 #include "absl/strings/substitute.h"
19 namespace upb {
20 namespace generator {
22 namespace {
24 std::string ToCIdent(absl::string_view str) {
25 return absl::StrReplaceAll(str, {{".", "_"}, {"/", "_"}, {"-", "_"}});
28 std::string ToPreproc(absl::string_view str) {
29 return absl::AsciiStrToUpper(ToCIdent(str));
32 } // namespace
34 bool IsDescriptorProto(absl::string_view filename) {
35 return filename == "net/proto2/proto/descriptor.proto" ||
36 filename == "google/protobuf/descriptor.proto";
39 std::string StripExtension(absl::string_view fname) {
40 size_t lastdot = fname.find_last_of('.');
41 if (lastdot == std::string::npos) {
42 return std::string(fname);
44 return std::string(fname.substr(0, lastdot));
47 std::string IncludeGuard(absl::string_view filename) {
48 return ToPreproc(filename) + "_UPB_H_";
51 std::string FileWarning(absl::string_view filename) {
52 return absl::Substitute(
53 "/* This file was generated by upb_generator from the input file:\n"
54 " *\n"
55 " * $0\n"
56 " *\n"
57 " * Do not edit -- your changes will be discarded when the file is\n"
58 " * regenerated.\n"
59 " * NO CHECKED-IN "
60 // Intentional line break.
61 "PROTOBUF GENCODE */\n"
62 "\n",
63 filename);
66 std::string PadPrefix(absl::string_view tag) {
67 return tag.empty() ? "" : absl::StrCat(" ", tag);
70 } // namespace generator
71 } // namespace upb