diff options
Diffstat (limited to 'src/google/protobuf/text_format.cc')
-rw-r--r-- | src/google/protobuf/text_format.cc | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 1ed74391..c0dfd53f 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -1785,14 +1785,12 @@ void TextFormat::Printer::PrintFieldValue( ? reflection->GetRepeatedStringReference( message, field, index, &scratch) : reflection->GetStringReference(message, field, &scratch); - int64 size = value.size(); - if (truncate_string_field_longer_than_ > 0) { - size = std::min(truncate_string_field_longer_than_, - static_cast<int64>(value.size())); - } - string truncated_value(value.substr(0, size) + "...<truncated>..."); const string* value_to_print = &value; - if (size < value.size()) { + string truncated_value; + if (truncate_string_field_longer_than_ > 0 && + truncate_string_field_longer_than_ < value.size()) { + truncated_value = value.substr(0, truncate_string_field_longer_than_) + + "...<truncated>..."; value_to_print = &truncated_value; } if (field->type() == FieldDescriptor::TYPE_STRING) { |