Simplify fromHex by passing the throw flag around

This commit is contained in:
Alex Beregszaszi 2019-11-22 16:59:06 +00:00
parent dc351ae5fa
commit e2627e2232

View File

@ -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();
}