[ObjC] Use absl::StripAsciiWhitespace().

Dropping the custom impl that was used previously.
pull/10720/head
Thomas Van Lenten 2 years ago
parent 78442bb5dd
commit 2e49a8de95
  1. 10
      src/google/protobuf/compiler/objectivec/import_writer.cc
  2. 12
      src/google/protobuf/compiler/objectivec/line_consumer.cc
  3. 16
      src/google/protobuf/compiler/objectivec/names.cc
  4. 3
      src/google/protobuf/compiler/objectivec/names.h

@ -32,6 +32,7 @@
#include "google/protobuf/compiler/objectivec/line_consumer.h"
#include "google/protobuf/compiler/objectivec/names.h"
#include "google/protobuf/io/printer.h"
#include "absl/strings/ascii.h"
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for errors.
@ -63,9 +64,8 @@ bool ProtoFrameworkCollector::ConsumeLine(
std::string(line) + "'.";
return false;
}
absl::string_view framework_name = line.substr(0, offset);
absl::string_view proto_file_list = line.substr(offset + 1);
TrimWhitespace(&framework_name);
absl::string_view framework_name = absl::StripAsciiWhitespace(line.substr(0, offset));
absl::string_view proto_file_list = absl::StripAsciiWhitespace(line.substr(offset + 1));
int start = 0;
while (start < proto_file_list.length()) {
@ -74,8 +74,8 @@ bool ProtoFrameworkCollector::ConsumeLine(
offset = proto_file_list.length();
}
absl::string_view proto_file = proto_file_list.substr(start, offset - start);
TrimWhitespace(&proto_file);
absl::string_view proto_file =
absl::StripAsciiWhitespace(proto_file_list.substr(start, offset - start));
if (!proto_file.empty()) {
std::map<std::string, std::string>::iterator existing_entry =
map_->find(std::string(proto_file));

@ -41,6 +41,7 @@
#include <sstream>
#include <vector>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/objectivec/line_consumer.h"
@ -67,15 +68,6 @@ using ::open;
namespace {
void TrimWhitespace(absl::string_view* input) {
while (!input->empty() && absl::ascii_isspace(*input->data())) {
input->remove_prefix(1);
}
while (!input->empty() && absl::ascii_isspace((*input)[input->length() - 1])) {
input->remove_suffix(1);
}
}
bool ascii_isnewline(char c) {
return c == '\n' || c == '\r';
}
@ -134,7 +126,7 @@ bool Parser::ParseChunk(absl::string_view chunk, std::string* out_error) {
while (ReadLine(&full_chunk, &line)) {
++line_;
RemoveComment(&line);
TrimWhitespace(&line);
line = absl::StripAsciiWhitespace(line);
if (!line.empty() && !line_consumer_->ConsumeLine(line, out_error)) {
if (out_error->empty()) {
*out_error = "ConsumeLine failed without setting an error.";

@ -36,6 +36,7 @@
#include <vector>
#include "google/protobuf/compiler/code_generator.h"
#include "absl/strings/ascii.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/objectivec/line_consumer.h"
#include "google/protobuf/compiler/objectivec/names.h"
@ -497,15 +498,6 @@ void MaybeUnQuote(absl::string_view* input) {
} // namespace
void TrimWhitespace(absl::string_view* input) {
while (!input->empty() && absl::ascii_isspace(*input->data())) {
input->remove_prefix(1);
}
while (!input->empty() && absl::ascii_isspace((*input)[input->length() - 1])) {
input->remove_suffix(1);
}
}
bool IsRetainedName(const std::string& name) {
// List of prefixes from
// http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html
@ -865,10 +857,8 @@ bool PackageToPrefixesCollector::ConsumeLine(
*out_error = usage_ + " file line without equal sign: '" + absl::StrCat(line) + "'.";
return false;
}
absl::string_view package = line.substr(0, offset);
absl::string_view prefix = line.substr(offset + 1);
TrimWhitespace(&package);
TrimWhitespace(&prefix);
absl::string_view package = absl::StripAsciiWhitespace(line.substr(0, offset));
absl::string_view prefix = absl::StripAsciiWhitespace(line.substr(offset + 1));
MaybeUnQuote(&prefix);
// Don't really worry about error checking the package/prefix for
// being valid. Assume the file is validated when it is created/edited.

@ -69,9 +69,6 @@ void PROTOC_EXPORT SetProtoPackagePrefixExceptionList(
std::string PROTOC_EXPORT GetForcedPackagePrefix();
void PROTOC_EXPORT SetForcedPackagePrefix(const std::string& prefix);
// Remove white space from either end of a absl::string_view.
void PROTOC_EXPORT TrimWhitespace(absl::string_view* input);
// Returns true if the name requires a ns_returns_not_retained attribute applied
// to it.
bool PROTOC_EXPORT IsRetainedName(const std::string& name);

Loading…
Cancel
Save