use char to find instead of string (#10094)

* [Bazel] Add a doc explaining our C++ build systems and distribution archives. (#10073)

* use char to find instead of string

Co-authored-by: David L. Jones <dlj@google.com>
pull/10101/head
appledragon 3 years ago committed by GitHub
parent bd85edfbd9
commit 45b7f62b1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/google/protobuf/compiler/csharp/csharp_helpers.cc
  2. 2
      src/google/protobuf/compiler/objectivec/objectivec_enum.cc
  3. 6
      src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
  4. 20
      src/google/protobuf/compiler/php/php_generator.cc
  5. 4
      src/google/protobuf/compiler/ruby/ruby_generator.cc

@ -107,7 +107,7 @@ CSharpType GetCSharpType(FieldDescriptor::Type type) {
}
std::string StripDotProto(const std::string& proto_file) {
int lastindex = proto_file.find_last_of(".");
int lastindex = proto_file.find_last_of('.');
return proto_file.substr(0, lastindex);
}
@ -122,7 +122,7 @@ std::string GetFileNamespace(const FileDescriptor* descriptor) {
// input of "google/protobuf/foo_bar.proto" would result in "FooBar".
std::string GetFileNameBase(const FileDescriptor* descriptor) {
std::string proto_file = descriptor->name();
int lastslash = proto_file.find_last_of("/");
int lastslash = proto_file.find_last_of('/');
std::string base = proto_file.substr(lastslash + 1);
return UnderscoresToPascalCase(StripDotProto(base));
}
@ -422,7 +422,7 @@ std::string GetOutputFile(const FileDescriptor* descriptor,
return ""; // This will be ignored, because we've set an error.
}
namespace_suffix = ns.substr(base_namespace.length());
if (namespace_suffix.find(".") == 0) {
if (namespace_suffix.find('.') == 0) {
namespace_suffix = namespace_suffix.substr(1);
}
}

@ -128,7 +128,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
continue;
}
if (all_values_[i]->GetSourceLocation(&location)) {
std::string comments = BuildCommentsString(location, true).c_str();
std::string comments = BuildCommentsString(location, true);
if (comments.length() > 0) {
if (i > 0) {
printer->Print("\n");

@ -990,9 +990,9 @@ static std::string HandleExtremeFloatingPoint(std::string val,
return "-INFINITY";
} else {
// float strings with ., e or E need to have f appended
if (add_float_suffix && (val.find(".") != std::string::npos ||
val.find("e") != std::string::npos ||
val.find("E") != std::string::npos)) {
if (add_float_suffix && (val.find('.') != std::string::npos ||
val.find('e') != std::string::npos ||
val.find('E') != std::string::npos)) {
val += "f";
}
return val;

@ -334,7 +334,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
const Options& options) {
const std::string& proto_file = file->name();
int start_index = 0;
int first_index = proto_file.find_first_of("/", start_index);
int first_index = proto_file.find_first_of('/', start_index);
std::string result = "";
std::string segment = "";
@ -347,7 +347,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
// Append directory name.
std::string file_no_suffix;
int lastindex = proto_file.find_last_of(".");
int lastindex = proto_file.find_last_of('.');
if (proto_file == kEmptyFile) {
return kEmptyMetadataFile;
} else {
@ -371,12 +371,12 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
file_no_suffix.substr(start_index, first_index - start_index), true);
result += ReservedNamePrefix(segment, file) + segment + "/";
start_index = first_index + 1;
first_index = file_no_suffix.find_first_of("/", start_index);
first_index = file_no_suffix.find_first_of('/', start_index);
}
}
// Append file name.
int file_name_start = file_no_suffix.find_last_of("/");
int file_name_start = file_no_suffix.find_last_of('/');
if (file_name_start == std::string::npos) {
file_name_start = 0;
} else {
@ -475,7 +475,7 @@ std::string PhpSetterTypeName(const FieldDescriptor* field,
}
if (field->is_repeated()) {
// accommodate for edge case with multiple types.
size_t start_pos = type.find("|");
size_t start_pos = type.find('|');
if (start_pos != std::string::npos) {
type.replace(start_pos, 1, ">|array<");
}
@ -1207,7 +1207,7 @@ void GenerateHead(const FileDescriptor* file, io::Printer* printer) {
}
std::string FilenameToClassname(const std::string& filename) {
int lastindex = filename.find_last_of(".");
int lastindex = filename.find_last_of('.');
std::string result = filename.substr(0, lastindex);
for (int i = 0; i < result.size(); i++) {
if (result[i] == '/') {
@ -1227,7 +1227,7 @@ void GenerateMetadataFile(const FileDescriptor* file, const Options& options,
GenerateHead(file, &printer);
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
int lastindex = fullname.find_last_of('\\');
if (lastindex != std::string::npos) {
printer.Print(
@ -1263,7 +1263,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
GenerateHead(file, &printer);
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
int lastindex = fullname.find_last_of('\\');
if (lastindex != std::string::npos) {
printer.Print(
@ -1391,7 +1391,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
GenerateHead(file, &printer);
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
int lastindex = fullname.find_last_of('\\');
if (lastindex != std::string::npos) {
printer.Print(
@ -1508,7 +1508,7 @@ void GenerateServiceFile(
GenerateHead(file, &printer);
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
int lastindex = fullname.find_last_of('\\');
if (!file->options().php_namespace().empty() ||
(!file->options().has_php_namespace() && !file->package().empty()) ||

@ -68,7 +68,7 @@ std::string NumberToString(numeric_type value) {
}
std::string GetRequireName(const std::string& proto_file) {
int lastindex = proto_file.find_last_of(".");
int lastindex = proto_file.find_last_of('.');
return proto_file.substr(0, lastindex) + "_pb";
}
@ -421,7 +421,7 @@ int GeneratePackageModules(const FileDescriptor* file, io::Printer* printer) {
// -> A.B.C
if (package_name.find("::") != std::string::npos) {
need_change_to_module = false;
} else if (package_name.find(".") != std::string::npos) {
} else if (package_name.find('.') != std::string::npos) {
GOOGLE_LOG(WARNING) << "ruby_package option should be in the form of:"
<< " 'A::B::C' and not 'A.B.C'";
}

Loading…
Cancel
Save