Internal change

PiperOrigin-RevId: 504341832
This commit is contained in:
Mike Kruskal 2023-01-24 12:11:35 -08:00 committed by Copybara-Service
parent 4e135ccdb9
commit 9cde57d830

View File

@ -330,7 +330,7 @@ class TemplateParser::Parser::ParserImpl {
return suc && LookingAtType(io::Tokenizer::TYPE_END); return suc && LookingAtType(io::Tokenizer::TYPE_END);
} }
void ReportError(int line, int col, const std::string& message) { void ReportError(int line, int col, absl::string_view message) {
had_errors_ = true; had_errors_ = true;
if (error_collector_ == NULL) { if (error_collector_ == NULL) {
if (line >= 0) { if (line >= 0) {
@ -342,11 +342,11 @@ class TemplateParser::Parser::ParserImpl {
<< root_message_type_->full_name() << ": " << message; << root_message_type_->full_name() << ": " << message;
} }
} else { } else {
error_collector_->AddError(line, col, message); error_collector_->AddError(line, col, std::string(message));
} }
} }
void ReportWarning(int line, int col, const std::string& message) { void ReportWarning(int line, int col, absl::string_view message) {
if (error_collector_ == NULL) { if (error_collector_ == NULL) {
if (line >= 0) { if (line >= 0) {
LOG(WARNING) << "Warning parsing text-format " LOG(WARNING) << "Warning parsing text-format "
@ -357,21 +357,21 @@ class TemplateParser::Parser::ParserImpl {
<< root_message_type_->full_name() << ": " << message; << root_message_type_->full_name() << ": " << message;
} }
} else { } else {
error_collector_->AddWarning(line, col, message); error_collector_->AddWarning(line, col, std::string(message));
} }
} }
protected: protected:
// Reports an error with the given message with information indicating // Reports an error with the given message with information indicating
// the position (as derived from the current token). // the position (as derived from the current token).
void ReportError(const std::string& message) { void ReportError(absl::string_view message) {
ReportError(tokenizer_.current().line, tokenizer_.current().column, ReportError(tokenizer_.current().line, tokenizer_.current().column,
message); message);
} }
// Reports a warning with the given message with information indicating // Reports a warning with the given message with information indicating
// the position (as derived from the current token). // the position (as derived from the current token).
void ReportWarning(const std::string& message) { void ReportWarning(absl::string_view message) {
ReportWarning(tokenizer_.current().line, tokenizer_.current().column, ReportWarning(tokenizer_.current().line, tokenizer_.current().column,
message); message);
} }
@ -379,7 +379,7 @@ class TemplateParser::Parser::ParserImpl {
// Consumes the specified message with the given starting delimiter. // Consumes the specified message with the given starting delimiter.
// This method checks to see that the end delimiter at the conclusion of // This method checks to see that the end delimiter at the conclusion of
// the consumption matches the starting delimiter passed in here. // the consumption matches the starting delimiter passed in here.
bool ConsumeMessage(Message* message, const std::string delimiter) { bool ConsumeMessage(Message* message, absl::string_view delimiter) {
while (!LookingAt(">") && !LookingAt("}")) { while (!LookingAt(">") && !LookingAt("}")) {
if (LookingAt("%")) { if (LookingAt("%")) {
DO(ConsumeFieldTemplate(message)); DO(ConsumeFieldTemplate(message));
@ -407,7 +407,7 @@ class TemplateParser::Parser::ParserImpl {
#ifndef PROTO2_OPENSOURCE #ifndef PROTO2_OPENSOURCE
// Consumes a string value and parses it as a packed repeated field into // Consumes a string value and parses it as a packed repeated field into
// the given field of the given message. // the given field of the given message.
bool ConsumePackedFieldAsString(const std::string& field_name, bool ConsumePackedFieldAsString(absl::string_view field_name,
const FieldDescriptor* field, const FieldDescriptor* field,
Message* message) { Message* message) {
std::string packed; std::string packed;
@ -431,8 +431,8 @@ class TemplateParser::Parser::ParserImpl {
io::ArrayInputStream array_input(tagged.data(), tagged.size()); io::ArrayInputStream array_input(tagged.data(), tagged.size());
io::CodedInputStream coded_input(&array_input); io::CodedInputStream coded_input(&array_input);
if (!message->MergePartialFromCodedStream(&coded_input)) { if (!message->MergePartialFromCodedStream(&coded_input)) {
ReportError("Could not parse packed field \"" + field_name + ReportError(absl::StrCat("Could not parse packed field \"", field_name,
"\" as wire-encoded string."); "\" as wire-encoded string."));
return false; return false;
} }
@ -1219,12 +1219,12 @@ class TemplateParser::Parser::ParserImpl {
// Consumes a token and confirms that it matches that specified in the // Consumes a token and confirms that it matches that specified in the
// value parameter. Returns false if the token found does not match that // value parameter. Returns false if the token found does not match that
// which was specified. // which was specified.
bool Consume(const std::string& value) { bool Consume(absl::string_view value) {
const std::string& current_value = tokenizer_.current().text; const std::string& current_value = tokenizer_.current().text;
if (current_value != value) { if (current_value != value) {
ReportError("Expected \"" + value + "\", found \"" + current_value + ReportError(absl::StrCat("Expected \"", value, "\", found \"",
"\"."); current_value, "\"."));
return false; return false;
} }