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

No public description #452

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions protoc/literals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// https://opensource.org/licenses/MIT.

#include "literals.h"
#include <string>
#include <string_view>

#include "absl/strings/str_cat.h"

Expand Down Expand Up @@ -49,7 +51,7 @@ const std::string LispSimpleDtoa(double value) {
return result + "d0";
}

const std::string LispEscapeString(const std::string& str) {
const std::string LispEscapeString(std::string_view str) {
std::string lisp;
lisp.append(1, '"');
for (char c : str) {
Expand All @@ -60,7 +62,7 @@ const std::string LispEscapeString(const std::string& str) {
return lisp;
}

const std::string StringOctets(const std::string& str) {
const std::string StringOctets(std::string_view str) {
std::string octets;
for (char c : str) {
if (!octets.empty()) octets += " ";
Expand Down
5 changes: 3 additions & 2 deletions protoc/literals.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
#define THIRD_PARTY_LISP_CL_PROTOBUFS_PROTOC_LITERALS_H_

#include <string>
#include <string_view>

namespace google {
namespace protobuf {
namespace cl_protobufs {

const std::string LispSimpleFtoa(float value);
const std::string LispSimpleDtoa(double value);
const std::string LispEscapeString(const std::string& str);
const std::string StringOctets(const std::string& str);
const std::string LispEscapeString(std::string_view str);
const std::string StringOctets(std::string_view str);
const std::string LispBool(bool value);

} // namespace cl_protobufs
Expand Down
29 changes: 16 additions & 13 deletions protoc/names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "names.h"

#include <ctype.h>
#include <string>
#include <string_view>

#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/extension_set.h>
Expand Down Expand Up @@ -60,7 +62,7 @@ const void StrToLower(std::string* s) {
}
}

const std::string DeCamel(const std::string& name, const bool to_lower_case,
const std::string DeCamel(std::string_view name, const bool to_lower_case,
const bool to_upper_case, const char* sep) {
// Needs to be kept in sync with class-name->proto.
std::string result;
Expand Down Expand Up @@ -103,21 +105,22 @@ const std::string DeCamel(const std::string& name, const bool to_lower_case,
return result;
}

const std::string ToLispName(const std::string& name) {
const std::string ToLispName(std::string_view name) {
return DeCamel(name, true, false, "-");
}

const std::string GetSchemaName(std::string filename) {
const size_t slash = filename.find_last_of("\\/");
const std::string GetSchemaName(std::string_view filename) {
std::string schema_name(filename);
const size_t slash = schema_name.find_last_of("\\/");
if (std::string::npos != slash) {
filename.erase(0, slash + 1);
schema_name.erase(0, slash + 1);
}
const size_t period = filename.rfind('.');
const size_t period = schema_name.rfind('.');
if (std::string::npos != period) {
filename.erase(period);
schema_name.erase(period);
}
StrToLower(&filename);
return filename;
StrToLower(&schema_name);
return schema_name;
}

// Namespace prefix for all generated packages.
Expand All @@ -143,7 +146,7 @@ const std::string EnumLispName(const EnumDescriptor* descriptor) {
}
}

const std::string ToLispEnumValue(const std::string& name) {
const std::string ToLispEnumValue(std::string_view name) {
// Enum values are usually uppercase separated by underscore.
std::string v = absl::StrReplaceAll(name, {{"_", "-"}});
absl::AsciiStrToLower(&v);
Expand Down Expand Up @@ -186,7 +189,7 @@ const std::string QualifiedMessageLispName(const Descriptor* msg,
}
}

const std::string ToCamelCase(const std::string& name) {
const std::string ToCamelCase(std::string_view name) {
// Needs to be kept in sync with the Lisp function proto->class-name.
std::string result;
CharType previous_type = unknown;
Expand Down Expand Up @@ -217,11 +220,11 @@ const std::string ToCamelCase(const std::string& name) {
return result;
}

bool CamelIsSpitting(const std::string& name) {
bool CamelIsSpitting(std::string_view name) {
return ToCamelCase(ToLispName(name)) != name;
}

const std::string ToLispAliasSymbolName(const std::string& symbol_name) {
const std::string ToLispAliasSymbolName(std::string_view symbol_name) {
auto splitter = absl::StrSplit(symbol_name, ":", absl::SkipWhitespace());
return NonDestructiveStrToLower(absl::StrJoin(splitter, "::"));
}
Expand Down
13 changes: 7 additions & 6 deletions protoc/names.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define GOOGLE_CL_PROTOBUF_COMPILER_LISP_NAMES_H__

#include <string>
#include <string_view>

#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
Expand All @@ -23,12 +24,12 @@ const std::string NonDestructiveStrToLower(std::string s);
const void StrToLower(std::string* s);

// Removes camel-case, and puts the name in lower case.
const std::string ToLispName(const std::string& name);
const std::string ToLispName(std::string_view name);

// Provides a name for the Enum described by the descriptor.
const std::string EnumLispName(const EnumDescriptor* descriptor);
// Provides a name for the Lisp Enum Value that turns into a keyword.
const std::string ToLispEnumValue(const std::string& name);
const std::string ToLispEnumValue(std::string_view name);

// Provides a name for the Message described by the descriptor.
// Uses lisp_name extension.
Expand All @@ -44,14 +45,14 @@ const std::string QualifiedMessageLispName(const Descriptor* descriptor,

const std::string FileLispPackage(const FileDescriptor* descriptor);

const std::string GetSchemaName(std::string filename);
const std::string GetSchemaName(std::string_view filename);

const std::string ToCamelCase(const std::string& name);
const std::string ToCamelCase(std::string_view name);

// True if the conversion to Lisp name and back differs from original.
bool CamelIsSpitting(const std::string& name);
bool CamelIsSpitting(std::string_view name);

const std::string ToLispAliasSymbolName(const std::string& symbol_name);
const std::string ToLispAliasSymbolName(std::string_view symbol_name);

} // namespace cl_protobufs
} // namespace protobuf
Expand Down
Loading