Remove trailing zeros from the output of BytesUtils::formatBytes

This commit is contained in:
Gaith Hallak 2019-10-15 13:49:28 +03:00
parent 02ae43aad4
commit 8a8f553e4d
2 changed files with 14 additions and 1 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);
};
}