mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Do not enclose string literal within double quotes before conversion to u256
This commit is contained in:
parent
c9e2d388b5
commit
f57439035a
@ -55,36 +55,30 @@ string ProtoConverter::createAlphaNum(string const& _strBytes) const
|
|||||||
|
|
||||||
bool ProtoConverter::isCaseLiteralUnique(Literal const& _x)
|
bool ProtoConverter::isCaseLiteralUnique(Literal const& _x)
|
||||||
{
|
{
|
||||||
std::string tmp;
|
dev::u256 mpCaseLiteralValue;
|
||||||
bool isUnique = false;
|
bool isUnique = false;
|
||||||
bool isEmptyString = false;
|
|
||||||
switch (_x.literal_oneof_case())
|
switch (_x.literal_oneof_case())
|
||||||
{
|
{
|
||||||
case Literal::kIntval:
|
case Literal::kIntval:
|
||||||
tmp = std::to_string(_x.intval());
|
mpCaseLiteralValue = dev::u256(_x.intval());
|
||||||
break;
|
break;
|
||||||
case Literal::kHexval:
|
case Literal::kHexval:
|
||||||
tmp = "0x" + createHex(_x.hexval());
|
// We need to ask boost mp library to treat this
|
||||||
|
// as a hex value. Hence the "0x" prefix.
|
||||||
|
mpCaseLiteralValue = dev::u256("0x" + createHex(_x.hexval()));
|
||||||
break;
|
break;
|
||||||
case Literal::kStrval:
|
case Literal::kStrval:
|
||||||
tmp = createAlphaNum(_x.strval());
|
mpCaseLiteralValue = dev::u256(dev::h256(createAlphaNum(_x.strval()), dev::h256::FromBinary, dev::h256::AlignLeft));
|
||||||
if (tmp.empty())
|
|
||||||
{
|
|
||||||
isEmptyString = true;
|
|
||||||
tmp = std::to_string(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
tmp = "\"" + tmp + "\"";
|
|
||||||
break;
|
break;
|
||||||
case Literal::LITERAL_ONEOF_NOT_SET:
|
case Literal::LITERAL_ONEOF_NOT_SET:
|
||||||
tmp = std::to_string(1);
|
// If the proto generator does not generate a valid Literal
|
||||||
|
// we generate a case 1:
|
||||||
|
mpCaseLiteralValue = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!_x.has_strval() || isEmptyString)
|
|
||||||
isUnique = m_switchLiteralSetPerScope.top().insert(dev::u256(tmp)).second;
|
isUnique = m_switchLiteralSetPerScope.top().insert(mpCaseLiteralValue).second;
|
||||||
else
|
|
||||||
isUnique = m_switchLiteralSetPerScope.top().insert(
|
|
||||||
dev::u256(dev::h256(tmp, dev::h256::FromBinary, dev::h256::AlignLeft))).second;
|
|
||||||
return isUnique;
|
return isUnique;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user