diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-26 19:49:05 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-28 23:57:32 +0800 |
commit | 8b0c866f025f3b48db36b0e48451062806a1ab06 (patch) | |
tree | b6dd46f48b66478feefc7e1c1810535c6bd1f700 /libsolidity/ast/AST.cpp | |
parent | 79d13366874c432c2f8f2adf3cd8cc00638c6a98 (diff) | |
download | dexon-solidity-8b0c866f025f3b48db36b0e48451062806a1ab06.tar.gz dexon-solidity-8b0c866f025f3b48db36b0e48451062806a1ab06.tar.zst dexon-solidity-8b0c866f025f3b48db36b0e48451062806a1ab06.zip |
Add hasHexPrefix() to AST::Literal
Diffstat (limited to 'libsolidity/ast/AST.cpp')
-rw-r--r-- | libsolidity/ast/AST.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index b929b6fe..54ded609 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -530,20 +530,26 @@ IdentifierAnnotation& Identifier::annotation() const return dynamic_cast<IdentifierAnnotation&>(*m_annotation); } +bool Literal::hasHexPrefix() const +{ + if (token() != Token::Number) + return false; + return value().substr(0, 2) == "0x"; +} + bool Literal::looksLikeAddress() const { if (subDenomination() != SubDenomination::None) return false; - if (token() != Token::Number) + + if (!hasHexPrefix()) return false; - string lit = value(); - return lit.substr(0, 2) == "0x" && abs(int(lit.length()) - 42) <= 1; + return abs(int(value().length()) - 42) <= 1; } bool Literal::passesAddressChecksum() const { - string lit = value(); - solAssert(lit.substr(0, 2) == "0x", "Expected hex prefix"); - return dev::passesAddressChecksum(lit, true); + solAssert(hasHexPrefix(), "Expected hex prefix"); + return dev::passesAddressChecksum(value(), true); } |