From 9851c703ae371236e4d4b4dbe537d3de8760931e Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Tue, 11 Dec 2018 16:43:05 -0800 Subject: [PATCH 1/4] Rename StringPieceTrimWhitespace() for rewriting purposes. --- .../protobuf/compiler/objectivec/objectivec_helpers.cc | 6 +++--- .../protobuf/compiler/objectivec/objectivec_helpers.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index c25b0c9de9..ef81f5776f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -364,7 +364,7 @@ string StripProto(const string& filename) { } } -void StringPieceTrimWhitespace(StringPiece* input) { +void TrimWhitespace(StringPiece* input) { while (!input->empty() && ascii_isspace(*input->data())) { input->remove_prefix(1); } @@ -1054,8 +1054,8 @@ bool ExpectedPrefixesCollector::ConsumeLine( } StringPiece package(line, 0, offset); StringPiece prefix(line, offset + 1, line.length() - offset - 1); - StringPieceTrimWhitespace(&package); - StringPieceTrimWhitespace(&prefix); + TrimWhitespace(&package); + TrimWhitespace(&prefix); // Don't really worry about error checking the package/prefix for // being valid. Assume the file is validated when it is created/edited. (*prefix_map_)[package.ToString()] = prefix.ToString(); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index e2f70245d9..98ec7db8fb 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -62,7 +62,7 @@ string PROTOC_EXPORT EscapeTrigraphs(const string& to_escape); string PROTOC_EXPORT StripProto(const string& filename); // Remove white space from either end of a StringPiece. -void PROTOC_EXPORT StringPieceTrimWhitespace(StringPiece* input); +void PROTOC_EXPORT TrimWhitespace(StringPiece* input); // Returns true if the name requires a ns_returns_not_retained attribute applied // to it. From eff1a6a01492988448685c6f9771e80e735d6030 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 13 Dec 2018 16:29:34 -0800 Subject: [PATCH 2/4] More fixes for import. --- .../compiler/objectivec/objectivec_helpers.cc | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index ef81f5776f..9db79b871c 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -659,7 +659,7 @@ string GetCapitalizedType(const FieldDescriptor* field) { // Some compilers report reaching end of function even though all cases of // the enum are handed in the switch. GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; + return string(); } ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type) { @@ -1052,13 +1052,13 @@ bool ExpectedPrefixesCollector::ConsumeLine( line.ToString() + "'."; return false; } - StringPiece package(line, 0, offset); - StringPiece prefix(line, offset + 1, line.length() - offset - 1); + StringPiece package = line.substr(0, offset); + StringPiece prefix = line.substr(offset + 1); TrimWhitespace(&package); TrimWhitespace(&prefix); // Don't really worry about error checking the package/prefix for // being valid. Assume the file is validated when it is created/edited. - (*prefix_map_)[package.ToString()] = prefix.ToString(); + (*prefix_map_)[string(package)] = string(prefix); return true; } @@ -1474,7 +1474,7 @@ class Parser { bool Parser::ParseChunk(StringPiece chunk) { if (!leftover_.empty()) { - chunk.AppendToString(&leftover_); + leftover_ += chunk; p_ = StringPiece(leftover_); } else { p_ = chunk; @@ -1483,7 +1483,7 @@ bool Parser::ParseChunk(StringPiece chunk) { if (p_.empty()) { leftover_.clear(); } else { - leftover_ = p_.ToString(); + leftover_ = string(p_); } return result; } @@ -1506,7 +1506,7 @@ bool Parser::ParseLoop() { while (ReadLine(&p_, &line)) { ++line_; RemoveComment(&line); - StringPieceTrimWhitespace(&line); + TrimWhitespace(&line); if (line.size() == 0) { continue; // Blank line. } @@ -1698,7 +1698,7 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( } StringPiece framework_name(line, 0, offset); StringPiece proto_file_list(line, offset + 1, line.length() - offset - 1); - StringPieceTrimWhitespace(&framework_name); + TrimWhitespace(&framework_name); int start = 0; while (start < proto_file_list.length()) { @@ -1708,24 +1708,24 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( } StringPiece proto_file(proto_file_list, start, offset - start); - StringPieceTrimWhitespace(&proto_file); + TrimWhitespace(&proto_file); if (proto_file.size() != 0) { std::map::iterator existing_entry = - map_->find(proto_file.ToString()); + map_->find(string(proto_file)); if (existing_entry != map_->end()) { std::cerr << "warning: duplicate proto file reference, replacing framework entry for '" - << proto_file.ToString() << "' with '" << framework_name.ToString() + << string(proto_file) << "' with '" << string(framework_name) << "' (was '" << existing_entry->second << "')." << std::endl; std::cerr.flush(); } if (proto_file.find(' ') != StringPiece::npos) { std::cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '" - << proto_file.ToString() << "'" << std::endl; + << string(proto_file) << "'" << std::endl; std::cerr.flush(); } - (*map_)[proto_file.ToString()] = framework_name.ToString(); + (*map_)[string(proto_file)] = string(framework_name); } start = offset + 1; From 401db44e6a1f4216925f26642db3dd68edc1b103 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 13 Dec 2018 17:48:52 -0800 Subject: [PATCH 3/4] More fixes. --- .../compiler/objectivec/objectivec_helpers.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 9db79b871c..1d6aaa9f52 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -48,9 +48,9 @@ #include #include #include +#include #include - // 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. @@ -859,7 +859,7 @@ string DefaultValue(const FieldDescriptor* field) { // Some compilers report reaching end of function even though all cases of // the enum are handed in the switch. GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; + return string(); } bool HasNonZeroDefaultValue(const FieldDescriptor* field) { @@ -1047,9 +1047,8 @@ bool ExpectedPrefixesCollector::ConsumeLine( const StringPiece& line, string* out_error) { int offset = line.find('='); if (offset == StringPiece::npos) { - *out_error = - string("Expected prefixes file line without equal sign: '") + - line.ToString() + "'."; + *out_error = string("Expected prefixes file line without equal sign: '") + + string(line) + "'."; return false; } StringPiece package = line.substr(0, offset); @@ -1474,7 +1473,7 @@ class Parser { bool Parser::ParseChunk(StringPiece chunk) { if (!leftover_.empty()) { - leftover_ += chunk; + leftover_ += string(chunk); p_ = StringPiece(leftover_); } else { p_ = chunk; @@ -1693,11 +1692,11 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( if (offset == StringPiece::npos) { *out_error = string("Framework/proto file mapping line without colon sign: '") + - line.ToString() + "'."; + string(line) + "'."; return false; } - StringPiece framework_name(line, 0, offset); - StringPiece proto_file_list(line, offset + 1, line.length() - offset - 1); + StringPiece framework_name = line.substr(0, offset); + StringPiece proto_file_list = line.substr(offset + 1); TrimWhitespace(&framework_name); int start = 0; From 5eb34cd72714668c66339d66a3476c24e279843f Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 13 Dec 2018 18:02:04 -0800 Subject: [PATCH 4/4] More fixes. --- .../compiler/objectivec/objectivec_helpers.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 1d6aaa9f52..3d0b0d2933 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -787,7 +787,7 @@ string GPBGenericValueFieldName(const FieldDescriptor* field) { // Some compilers report reaching end of function even though all cases of // the enum are handed in the switch. GOOGLE_LOG(FATAL) << "Can't get here."; - return NULL; + return string(); } @@ -1706,21 +1706,23 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( offset = proto_file_list.length(); } - StringPiece proto_file(proto_file_list, start, offset - start); + StringPiece proto_file = proto_file_list.substr(start, offset - start); TrimWhitespace(&proto_file); if (proto_file.size() != 0) { std::map::iterator existing_entry = map_->find(string(proto_file)); if (existing_entry != map_->end()) { - std::cerr << "warning: duplicate proto file reference, replacing framework entry for '" - << string(proto_file) << "' with '" << string(framework_name) - << "' (was '" << existing_entry->second << "')." << std::endl; + std::cerr << "warning: duplicate proto file reference, replacing " + "framework entry for '" + << string(proto_file) << "' with '" << string(framework_name) + << "' (was '" << existing_entry->second << "')." << std::endl; std::cerr.flush(); } if (proto_file.find(' ') != StringPiece::npos) { - std::cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '" - << string(proto_file) << "'" << std::endl; + std::cerr << "note: framework mapping file had a proto file with a " + "space in, hopefully that isn't a missing comma: '" + << string(proto_file) << "'" << std::endl; std::cerr.flush(); }