1- diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc
2- index 594c8eac6..c7ef9437b 100644
3- --- a/src/google/protobuf/stubs/strutil.cc
4- +++ b/src/google/protobuf/stubs/strutil.cc
5- @@ -592,7 +592,7 @@ void CEscapeAndAppend(StringPiece src, std::string *dest) {
6- }
7- }
8-
9- - std::string CEscape(const std::string &src) {
10- + std::string CEscape(StringPiece src) {
11- std::string dest;
12- CEscapeAndAppend(src, &dest);
13- return dest;
14- diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h
15- index 9658abf90..9cf9cae83 100644
16- --- a/src/google/protobuf/stubs/strutil.h
17- +++ b/src/google/protobuf/stubs/strutil.h
18- @@ -328,7 +328,7 @@ PROTOBUF_EXPORT std::string UnescapeCEscapeString(const std::string& src);
19- //
20- // Escaped chars: \n, \r, \t, ", ', \, and !isprint().
21- // ----------------------------------------------------------------------
22- - PROTOBUF_EXPORT std::string CEscape(const std::string& src);
23- + PROTOBUF_EXPORT std::string CEscape(StringPiece src);
24-
25- // ----------------------------------------------------------------------
26- // CEscapeAndAppend()
271diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc
28- index 19110499d..0d116ee7e 100644
2+ index 2c0a95d..1234567 100644
293--- a/src/google/protobuf/text_format.cc
304+++ b/src/google/protobuf/text_format.cc
31- @@ -81 ,6 +81 ,18 @@ inline bool IsOctNumber(const std::string& str) {
5+ @@ -82 ,6 +82 ,18 @@ inline bool IsOctNumber(const std::string& str) {
326 (str[1] >= '0' && str[1] < '8'));
337 }
34-
35- + // Returns true if truncatation occurred.
36- + bool TruncateString(int64_t max_length, StringPiece * s) {
8+
9+ + // Returns true if truncation occurred.
10+ + bool TruncateString(int64_t max_length, absl::string_view * s) {
3711+ if (max_length > 0) {
3812+ int64_t excess = static_cast<int64_t>(s->size()) - max_length;
3913+ if (excess > 0) {
@@ -44,10 +18,10 @@ index 19110499d..0d116ee7e 100644
4418+ return false;
4519+ }
4620+
47- } // namespace
48-
49- namespace internal {
50- @@ -2555 ,20 +2567 ,22 @@ void TextFormat::Printer::PrintFieldValue(const Message& message,
21+ // The number of fields that are redacted in AbslStringify.
22+ std::atomic<int64_t> num_redacted_field{0};
23+
24+ @@ -2738 ,20 +2750 ,22 @@ void TextFormat::Printer::PrintFieldValue(const Message& message,
5125 ? reflection->GetRepeatedStringReference(message, field, index,
5226 &scratch)
5327 : reflection->GetStringReference(message, field, &scratch);
@@ -60,39 +34,39 @@ index 19110499d..0d116ee7e 100644
6034- "...<truncated>...";
6135- value_to_print = &truncated_value;
6236- }
63- + StringPiece value_to_print(value);
37+ + absl::string_view value_to_print(value);
6438+ bool truncated = TruncateString(truncate_string_field_longer_than_, &value_to_print);
6539+
6640 if (field->type() == FieldDescriptor::TYPE_STRING) {
6741- printer->PrintString(*value_to_print, generator);
6842+ if (truncated) {
69- + printer->PrintString(StrCat(value_to_print, "...<truncated>..."), generator);
43+ + printer->PrintString(absl:: StrCat(value_to_print, "...<truncated>..."), generator);
7044+ } else {
7145+ printer->PrintString(value, generator);
7246+ }
7347 } else {
74- GOOGLE_DCHECK_EQ (field->type(), FieldDescriptor::TYPE_BYTES);
48+ ABSL_DCHECK_EQ (field->type(), FieldDescriptor::TYPE_BYTES);
7549- printer->PrintBytes(*value_to_print, generator);
7650+ if (truncated) {
77- + printer->PrintBytes(StrCat(value_to_print, "...<truncated>..."), generator);
51+ + printer->PrintBytes(absl:: StrCat(value_to_print, "...<truncated>..."), generator);
7852+ } else {
7953+ printer->PrintBytes(value, generator);
8054+ }
8155 }
8256 break;
8357 }
84- @@ -2708 ,7 +2722 ,14 @@ void TextFormat::Printer::PrintUnknownFields(
85- // This field is not parseable as a Message (or we ran out of
86- // recursion budget). So it is probably just a plain string.
87- generator->PrintMaybeWithMarker(": ", "\"");
88- - generator->PrintString(CEscape(value));
89- + StringPiece value_to_print(value);
58+ @@ -2937 ,7 +2951 ,14 @@ void TextFormat::Printer::PrintUnknownFields(
59+ break;
60+ }
61+ generator->PrintMaybeWithMarker(MarkerToken(), ": ", "\"");
62+ - generator->PrintString(absl:: CEscape(value));
63+ + absl::string_view value_to_print(value);
9064+ bool truncated = TruncateString(truncate_string_field_longer_than_, &value_to_print);
9165+
9266+ if (truncated) {
93- + generator->PrintString(CEscape(value_to_print) + "...<truncated>...");
67+ + generator->PrintString(absl::StrCat(absl:: CEscape(value_to_print), "...<truncated>...") );
9468+ } else {
95- + generator->PrintString(CEscape(value));
69+ + generator->PrintString(absl:: CEscape(value));
9670+ }
9771 if (single_line_mode_) {
9872 generator->PrintLiteral("\" ");
0 commit comments