aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast/AST.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-06-29 00:41:56 +0800
committerGitHub <noreply@github.com>2017-06-29 00:41:56 +0800
commit96fb3b4945557aaada84a1c802d24ff153e1fef7 (patch)
tree74b0946f9aee14092a38352010231aba8aed94ce /libsolidity/ast/AST.cpp
parent79d13366874c432c2f8f2adf3cd8cc00638c6a98 (diff)
parentc70d73809a6b36305f65e4ecb68acc3f63c7b304 (diff)
downloaddexon-solidity-96fb3b4945557aaada84a1c802d24ff153e1fef7.tar
dexon-solidity-96fb3b4945557aaada84a1c802d24ff153e1fef7.tar.gz
dexon-solidity-96fb3b4945557aaada84a1c802d24ff153e1fef7.tar.bz2
dexon-solidity-96fb3b4945557aaada84a1c802d24ff153e1fef7.tar.lz
dexon-solidity-96fb3b4945557aaada84a1c802d24ff153e1fef7.tar.xz
dexon-solidity-96fb3b4945557aaada84a1c802d24ff153e1fef7.tar.zst
dexon-solidity-96fb3b4945557aaada84a1c802d24ff153e1fef7.zip
Merge pull request #2471 from ethereum/ast-literal
Add hasHexPrefix() to AST::Literal
Diffstat (limited to 'libsolidity/ast/AST.cpp')
-rw-r--r--libsolidity/ast/AST.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp
index b929b6fe..403f4b79 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::isHexNumber() const
+{
+ if (token() != Token::Number)
+ return false;
+ return boost::starts_with(value(), "0x");
+}
+
bool Literal::looksLikeAddress() const
{
if (subDenomination() != SubDenomination::None)
return false;
- if (token() != Token::Number)
+
+ if (!isHexNumber())
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(isHexNumber(), "Expected hex number");
+ return dev::passesAddressChecksum(value(), true);
}