Deduplicate StripProto methods

This commit is contained in:
Yuriy Chernyshov 2020-11-06 15:35:18 +03:00 committed by Adam Cozzette
parent 2f6a7546e4
commit 20c780045a
11 changed files with 14 additions and 51 deletions

View File

@ -123,6 +123,15 @@ void ParseGeneratorParameter(
}
}
// Strips ".proto" or ".protodevel" from the end of a filename.
std::string StripProto(const std::string& filename) {
if (HasSuffixString(filename, ".protodevel")) {
return StripSuffixString(filename, ".protodevel");
} else {
return StripSuffixString(filename, ".proto");
}
}
} // namespace compiler
} // namespace protobuf
} // namespace google

View File

@ -193,6 +193,9 @@ typedef GeneratorContext OutputDirectory;
PROTOC_EXPORT void ParseGeneratorParameter(
const std::string&, std::vector<std::pair<std::string, std::string> >*);
// Strips ".proto" or ".protodevel" from the end of a filename.
PROTOC_EXPORT std::string StripProto(const std::string& filename);
} // namespace compiler
} // namespace protobuf
} // namespace google

View File

@ -515,14 +515,6 @@ std::string FieldMessageTypeName(const FieldDescriptor* field,
return QualifiedClassName(field->message_type(), options);
}
std::string StripProto(const std::string& filename) {
if (HasSuffixString(filename, ".protodevel")) {
return StripSuffixString(filename, ".protodevel");
} else {
return StripSuffixString(filename, ".proto");
}
}
const char* PrimitiveTypeName(FieldDescriptor::CppType type) {
switch (type) {
case FieldDescriptor::CPPTYPE_INT32:

View File

@ -205,9 +205,6 @@ inline const Descriptor* FieldScope(const FieldDescriptor* field) {
std::string FieldMessageTypeName(const FieldDescriptor* field,
const Options& options);
// Strips ".proto" or ".protodevel" from the end of a filename.
PROTOC_EXPORT std::string StripProto(const std::string& filename);
// Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.).
const char* PrimitiveTypeName(FieldDescriptor::CppType type);
std::string PrimitiveTypeName(const Options& options,

View File

@ -227,14 +227,6 @@ std::string CamelCaseFieldName(const FieldDescriptor* field) {
return fieldName;
}
std::string StripProto(const std::string& filename) {
if (HasSuffixString(filename, ".protodevel")) {
return StripSuffixString(filename, ".protodevel");
} else {
return StripSuffixString(filename, ".proto");
}
}
std::string FileClassName(const FileDescriptor* file, bool immutable) {
ClassNameResolver name_resolver;
return name_resolver.GetFileClassName(file, immutable);

View File

@ -95,9 +95,6 @@ std::string CamelCaseFieldName(const FieldDescriptor* field);
// outermost file scope.
std::string UniqueFileScopeIdentifier(const Descriptor* descriptor);
// Strips ".proto" or ".protodevel" from the end of a filename.
std::string StripProto(const std::string& filename);
// Gets the unqualified class name for the file. For each .proto file, there
// will be one Java class containing all the immutable messages and another
// Java class containing all the mutable messages.

View File

@ -33,6 +33,7 @@
#include <map>
#include <string>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/java/java_helpers.h>
#include <google/protobuf/stubs/substitute.h>

View File

@ -99,15 +99,6 @@ bool StrEndsWith(StringPiece sp, StringPiece x) {
return sp.size() >= x.size() && sp.substr(sp.size() - x.size()) == x;
}
// Returns a copy of |filename| with any trailing ".protodevel" or ".proto
// suffix stripped.
// TODO(haberman): Unify with copy in compiler/cpp/internal/helpers.cc.
std::string StripProto(const std::string& filename) {
const char* suffix =
StrEndsWith(filename, ".protodevel") ? ".protodevel" : ".proto";
return StripSuffixString(filename, suffix);
}
std::string GetSnakeFilename(const std::string& filename) {
std::string snake_name = filename;
ReplaceCharacters(&snake_name, "/", '_');

View File

@ -41,6 +41,7 @@
#include <unordered_set>
#include <vector>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
#include <google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h>
#include <google/protobuf/descriptor.pb.h>
@ -362,14 +363,6 @@ std::string EscapeTrigraphs(const std::string& to_escape) {
return StringReplace(to_escape, "?", "\\?", true);
}
std::string StripProto(const std::string& filename) {
if (HasSuffixString(filename, ".protodevel")) {
return StripSuffixString(filename, ".protodevel");
} else {
return StripSuffixString(filename, ".proto");
}
}
void TrimWhitespace(StringPiece* input) {
while (!input->empty() && ascii_isspace(*input->data())) {
input->remove_prefix(1);

View File

@ -59,9 +59,6 @@ struct Options {
// Escape C++ trigraphs by escaping question marks to "\?".
std::string PROTOC_EXPORT EscapeTrigraphs(const std::string& to_escape);
// Strips ".proto" or ".protodevel" from the end of a filename.
std::string PROTOC_EXPORT StripProto(const std::string& filename);
// Remove white space from either end of a StringPiece.
void PROTOC_EXPORT TrimWhitespace(StringPiece* input);

View File

@ -69,15 +69,6 @@ namespace python {
namespace {
// Returns a copy of |filename| with any trailing ".protodevel" or ".proto
// suffix stripped.
// TODO(robinson): Unify with copy in compiler/cpp/internal/helpers.cc.
std::string StripProto(const std::string& filename) {
const char* suffix =
HasSuffixString(filename, ".protodevel") ? ".protodevel" : ".proto";
return StripSuffixString(filename, suffix);
}
// Returns the Python module name expected for a given .proto filename.
std::string ModuleName(const std::string& filename) {
std::string basename = StripProto(filename);