Commit 75f1c32c authored by Robert Edmonds's avatar Robert Edmonds

Convert string views to owned strings where necessary

parent bc2cb66d
...@@ -152,7 +152,7 @@ void EnumGenerator::GenerateValueInitializer(google::protobuf::io::Printer *prin ...@@ -152,7 +152,7 @@ void EnumGenerator::GenerateValueInitializer(google::protobuf::io::Printer *prin
descriptor_->file()->options().optimize_for() == descriptor_->file()->options().optimize_for() ==
google::protobuf::FileOptions_OptimizeMode_CODE_SIZE; google::protobuf::FileOptions_OptimizeMode_CODE_SIZE;
vars["enum_value_name"] = vd->name(); vars["enum_value_name"] = vd->name();
vars["c_enum_value_name"] = FullNameToUpper(descriptor_->full_name(), descriptor_->file()) + "__" + vd->name(); vars["c_enum_value_name"] = FullNameToUpper(descriptor_->full_name(), descriptor_->file()) + "__" + std::string(vd->name());
vars["value"] = SimpleItoa(vd->number()); vars["value"] = SimpleItoa(vd->number());
if (optimize_code_size) if (optimize_code_size)
printer->Print(vars, " { NULL, NULL, $value$ }, /* CODE_SIZE */\n"); printer->Print(vars, " { NULL, NULL, $value$ }, /* CODE_SIZE */\n");
......
...@@ -78,7 +78,7 @@ void SetEnumVariables(const google::protobuf::FieldDescriptor* descriptor, ...@@ -78,7 +78,7 @@ void SetEnumVariables(const google::protobuf::FieldDescriptor* descriptor,
(*variables)["type"] = FullNameToC(descriptor->enum_type()->full_name(), descriptor->enum_type()->file()); (*variables)["type"] = FullNameToC(descriptor->enum_type()->full_name(), descriptor->enum_type()->file());
const google::protobuf::EnumValueDescriptor* default_value = descriptor->default_value_enum(); const google::protobuf::EnumValueDescriptor* default_value = descriptor->default_value_enum();
(*variables)["default"] = FullNameToUpper(default_value->type()->full_name(), default_value->type()->file()) (*variables)["default"] = FullNameToUpper(default_value->type()->full_name(), default_value->type()->file())
+ "__" + default_value->name(); + "__" + std::string(default_value->name());
(*variables)["deprecated"] = FieldDeprecated(descriptor); (*variables)["deprecated"] = FieldDeprecated(descriptor);
} }
......
...@@ -178,13 +178,13 @@ std::string ToCamel(compat::StringView name) { ...@@ -178,13 +178,13 @@ std::string ToCamel(compat::StringView name) {
std::string OverrideFullName(compat::StringView full_name, const google::protobuf::FileDescriptor* file) { std::string OverrideFullName(compat::StringView full_name, const google::protobuf::FileDescriptor* file) {
const ProtobufCFileOptions opt = file->options().GetExtension(pb_c_file); const ProtobufCFileOptions opt = file->options().GetExtension(pb_c_file);
if (!opt.has_c_package()) if (!opt.has_c_package())
return full_name; return std::string(full_name);
std::string new_name = opt.c_package(); std::string new_name = opt.c_package();
if (file->package().empty()) if (file->package().empty())
new_name += "."; new_name += ".";
return new_name + full_name.substr(file->package().length()); return new_name + std::string(full_name.substr(file->package().length()));
} }
std::string FullNameToLower(compat::StringView full_name, const google::protobuf::FileDescriptor* file) { std::string FullNameToLower(compat::StringView full_name, const google::protobuf::FileDescriptor* file) {
...@@ -418,10 +418,10 @@ void SplitStringToIteratorUsing(compat::StringView full, ...@@ -418,10 +418,10 @@ void SplitStringToIteratorUsing(compat::StringView full,
while (begin_index != std::string::npos) { while (begin_index != std::string::npos) {
end_index = full.find_first_of(delim, begin_index); end_index = full.find_first_of(delim, begin_index);
if (end_index == std::string::npos) { if (end_index == std::string::npos) {
*result++ = full.substr(begin_index); *result++ = std::string(full.substr(begin_index));
return; return;
} }
*result++ = full.substr(begin_index, (end_index - begin_index)); *result++ = std::string(full.substr(begin_index, (end_index - begin_index)));
begin_index = full.find_first_not_of(delim, end_index); begin_index = full.find_first_not_of(delim, end_index);
} }
} }
......
...@@ -89,10 +89,9 @@ std::string SimpleDtoa(double f); ...@@ -89,10 +89,9 @@ std::string SimpleDtoa(double f);
void SplitStringUsing(compat::StringView str, const char *delim, std::vector<std::string> *out); void SplitStringUsing(compat::StringView str, const char *delim, std::vector<std::string> *out);
std::string CEscape(compat::StringView src); std::string CEscape(compat::StringView src);
inline bool HasSuffixString(compat::StringView str, compat::StringView suffix) { return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } inline bool HasSuffixString(compat::StringView str, compat::StringView suffix) { return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; }
inline std::string StripSuffixString(compat::StringView str, compat::StringView suffix) { if (HasSuffixString(str, suffix)) { return str.substr(0, str.size() - suffix.size()); } else { return str; } } inline std::string StripSuffixString(compat::StringView str, compat::StringView suffix) { if (HasSuffixString(str, suffix)) { return std::string(str.substr(0, str.size() - suffix.size())); } else { return std::string(str); } }
char* FastHexToBuffer(int i, char* buffer); char* FastHexToBuffer(int i, char* buffer);
// Get the (unqualified) name that should be used for this field in C code. // Get the (unqualified) name that should be used for this field in C code.
// The name is coerced to lower-case to emulate proto1 behavior. People // The name is coerced to lower-case to emulate proto1 behavior. People
// should be using lowercase-with-underscores style for proto field names // should be using lowercase-with-underscores style for proto field names
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment