Merge pull request #7538 from ghallak/7198-remove-padded-zeros

Remove trailing zeros from the output of BytesUtils::formatBytes
This commit is contained in:
chriseth 2019-10-16 15:55:02 +02:00 committed by GitHub
commit e626437d77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -263,7 +263,7 @@ string BytesUtils::formatBytes(
os << formatHexString(_bytes);
break;
case ABIType::String:
os << formatString(_bytes);
os << formatString(_bytes, _bytes.size() - countRightPaddedZeros(_bytes));
break;
case ABIType::Failure:
break;
@ -311,3 +311,12 @@ string BytesUtils::formatBytesRange(
return os.str();
}
size_t BytesUtils::countRightPaddedZeros(bytes const& _bytes)
{
return find_if(
_bytes.rbegin(),
_bytes.rend(),
[](uint8_t b) { return b != '\0'; }
) - _bytes.rbegin();
}

View File

@ -122,6 +122,10 @@ public:
ParameterList const& _parameters,
bool _highlight
);
/// Count the number of zeros between the last non-zero byte and the end of
/// \param _bytes.
static size_t countRightPaddedZeros(bytes const& _bytes);
};
}

View File

@ -50,7 +50,7 @@ public:
TestFunctionCall(FunctionCall _call): m_call(std::move(_call)) {}
/// Formats this function call test and applies the format that was detected during parsing.
/// If _renderResult is false, the expected result of the call will is used, if it's false
/// If _renderResult is false, the expected result of the call will be used, if it's true
/// the actual result is used.
/// If _highlight is false, it's formatted without colorized highlighting. If it's true, AnsiColorized is
/// used to apply a colorized highlighting.