Migrating downstream error collectors to use the new string_view overrides.

PiperOrigin-RevId: 504607264
pull/11664/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 6fd3783b4a
commit 7bc3ed8835
  1. 17
      python/google/protobuf/pyext/descriptor_pool.cc
  2. 4
      src/google/protobuf/compiler/cpp/bootstrap_unittest.cc
  3. 4
      src/google/protobuf/compiler/cpp/unittest.inc
  4. 4
      src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
  5. 2
      src/google/protobuf/io/tokenizer_unittest.cc

@ -39,14 +39,15 @@
#include <Python.h>
#include "google/protobuf/descriptor.pb.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/pyext/descriptor.h"
#include "google/protobuf/pyext/descriptor_database.h"
#include "google/protobuf/pyext/descriptor_pool.h"
#include "google/protobuf/pyext/message.h"
#include "google/protobuf/pyext/message_factory.h"
#include "google/protobuf/pyext/scoped_pyobject_ptr.h"
#include "absl/strings/string_view.h"
#include "absl/strings/str_replace.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
@ -76,19 +77,19 @@ class BuildFileErrorCollector : public DescriptorPool::ErrorCollector {
public:
BuildFileErrorCollector() : error_message(""), had_errors_(false) {}
void AddError(const std::string& filename, const std::string& element_name,
const Message* descriptor, ErrorLocation location,
const std::string& message) override {
void RecordError(absl::string_view filename, absl::string_view element_name,
const Message* descriptor, ErrorLocation location,
absl::string_view message) override {
// Replicates the logging behavior that happens in the C++ implementation
// when an error collector is not passed in.
if (!had_errors_) {
error_message +=
("Invalid proto descriptor for file \"" + filename + "\":\n");
absl::StrAppend(&error_message, "Invalid proto descriptor for file \"",
filename, "\":\n");
had_errors_ = true;
}
// As this only happens on failure and will result in the program not
// running at all, no effort is made to optimize this string manipulation.
error_message += (" " + element_name + ": " + message + "\n");
absl::StrAppend(&error_message, " ", element_name, ": ", message, "\n");
}
void Clear() {

@ -80,8 +80,8 @@ class MockErrorCollector : public MultiFileErrorCollector {
std::string text_;
// implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column,
const std::string& message) override {
void RecordError(absl::string_view filename, int line, int column,
absl::string_view message) override {
absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
message);
}

@ -98,8 +98,8 @@ class MockErrorCollector : public MultiFileErrorCollector {
std::string text_;
// implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column,
const std::string& message) override {
void RecordError(absl::string_view filename, int line, int column,
absl::string_view message) override {
absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
message);
}

@ -66,8 +66,8 @@ class MockErrorCollector : public MultiFileErrorCollector {
std::string text_;
// implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column,
const std::string& message) {
void RecordError(absl::string_view filename, int line, int column,
absl::string_view message) {
absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
message);
}

@ -161,7 +161,7 @@ class TestErrorCollector : public ErrorCollector {
std::string text_;
// implements ErrorCollector ---------------------------------------
void AddError(int line, int column, const std::string& message) {
void RecordError(int line, int column, absl::string_view message) override {
absl::SubstituteAndAppend(&text_, "$0:$1: $2\n", line, column, message);
}
};

Loading…
Cancel
Save