From 19be6cd818e4bb1a49325d8bfea7f7727d85c933 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 16 Oct 2018 17:58:17 +0200 Subject: Some well-formedness checks for the Yul AST. --- libdevcore/CommonData.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libdevcore/CommonData.cpp') diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 6d7c74d7..fa1a5353 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -110,3 +110,26 @@ string dev::getChecksummedAddress(string const& _addr) } return ret; } + +bool dev::isValidHex(string const& _string) +{ + if (_string.substr(0, 2) != "0x") + return false; + if (_string.find_first_not_of("0123456789abcdefABCDEF", 2) != string::npos) + return false; + return true; +} + +bool dev::isValidDecimal(string const& _string) +{ + if (_string.empty()) + return false; + if (_string == "0") + return true; + // No leading zeros + if (_string.front() == '0') + return false; + if (_string.find_first_not_of("0123456789") != string::npos) + return false; + return true; +} -- cgit v1.2.3