aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-10-16 23:58:17 +0800
committerchriseth <chris@ethereum.org>2018-10-22 21:52:26 +0800
commit19be6cd818e4bb1a49325d8bfea7f7727d85c933 (patch)
treefae4f0c8bb4ca4c32ede677466a6a8cfc2965fee /libdevcore
parentc13b5280c1b44f18a2a1fb61ef5556e91c5678e7 (diff)
downloaddexon-solidity-19be6cd818e4bb1a49325d8bfea7f7727d85c933.tar
dexon-solidity-19be6cd818e4bb1a49325d8bfea7f7727d85c933.tar.gz
dexon-solidity-19be6cd818e4bb1a49325d8bfea7f7727d85c933.tar.bz2
dexon-solidity-19be6cd818e4bb1a49325d8bfea7f7727d85c933.tar.lz
dexon-solidity-19be6cd818e4bb1a49325d8bfea7f7727d85c933.tar.xz
dexon-solidity-19be6cd818e4bb1a49325d8bfea7f7727d85c933.tar.zst
dexon-solidity-19be6cd818e4bb1a49325d8bfea7f7727d85c933.zip
Some well-formedness checks for the Yul AST.
Diffstat (limited to 'libdevcore')
-rw-r--r--libdevcore/CommonData.cpp23
-rw-r--r--libdevcore/CommonData.h3
2 files changed, 26 insertions, 0 deletions
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;
+}
diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h
index f208c425..0782fabc 100644
--- a/libdevcore/CommonData.h
+++ b/libdevcore/CommonData.h
@@ -272,4 +272,7 @@ bool passesAddressChecksum(std::string const& _str, bool _strict);
/// @param hex strings that look like an address
std::string getChecksummedAddress(std::string const& _addr);
+bool isValidHex(std::string const& _string);
+bool isValidDecimal(std::string const& _string);
+
}