mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove trailing zeros from the output of BytesUtils::formatBytes
This commit is contained in:
parent
02ae43aad4
commit
8a8f553e4d
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user