mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Simplify fromHex by passing the throw flag around
This commit is contained in:
parent
dc351ae5fa
commit
e2627e2232
@ -99,22 +99,18 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw)
|
||||
|
||||
if (_s.size() % 2)
|
||||
{
|
||||
int h = fromHex(_s[s++], WhenError::DontThrow);
|
||||
int h = fromHex(_s[s++], _throw);
|
||||
if (h != -1)
|
||||
ret.push_back(h);
|
||||
else if (_throw == WhenError::Throw)
|
||||
assertThrow(false, BadHexCharacter, "");
|
||||
else
|
||||
return bytes();
|
||||
}
|
||||
for (unsigned i = s; i < _s.size(); i += 2)
|
||||
{
|
||||
int h = fromHex(_s[i], WhenError::DontThrow);
|
||||
int l = fromHex(_s[i + 1], WhenError::DontThrow);
|
||||
int h = fromHex(_s[i], _throw);
|
||||
int l = fromHex(_s[i + 1], _throw);
|
||||
if (h != -1 && l != -1)
|
||||
ret.push_back((uint8_t)(h * 16 + l));
|
||||
else if (_throw == WhenError::Throw)
|
||||
assertThrow(false, BadHexCharacter, "");
|
||||
else
|
||||
return bytes();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user