aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore/CommonData.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-06 03:35:45 +0800
committerchriseth <chris@ethereum.org>2018-12-06 05:37:05 +0800
commite8455c2a6d33abbebfe678fdaa1728311838e21a (patch)
tree93b4d89200f468189920f69ee218a5dbd59e1cfb /libdevcore/CommonData.cpp
parent3a378eae1a57683d0f31ab54c122b2a5c6a7c8bb (diff)
downloaddexon-solidity-e8455c2a6d33abbebfe678fdaa1728311838e21a.tar.gz
dexon-solidity-e8455c2a6d33abbebfe678fdaa1728311838e21a.tar.zst
dexon-solidity-e8455c2a6d33abbebfe678fdaa1728311838e21a.zip
Move toHex implementation to cpp file.
Diffstat (limited to 'libdevcore/CommonData.cpp')
-rw-r--r--libdevcore/CommonData.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp
index 8d2639c9..2c22fd9a 100644
--- a/libdevcore/CommonData.cpp
+++ b/libdevcore/CommonData.cpp
@@ -29,6 +29,26 @@
using namespace std;
using namespace dev;
+string dev::toHex(bytes const& _data, int, HexPrefix _prefix, HexCase _case)
+{
+ std::ostringstream ret;
+ int rix = _data.size() - 1;
+ for (uint8_t c: _data)
+ {
+ // switch hex case every four hexchars
+ auto hexcase = std::nouppercase;
+ if (_case == HexCase::Upper)
+ hexcase = std::uppercase;
+ else if (_case == HexCase::Mixed)
+ hexcase = (rix-- & 2) == 0 ? std::nouppercase : std::uppercase;
+
+ ret << std::hex << hexcase << std::setfill('0') << std::setw(_w)
+ << size_t(c);
+ }
+
+ return (_prefix == HexPrefix::Add) ? "0x" + ret.str() : ret.str();
+}
+
int dev::fromHex(char _i, WhenError _throw)
{
if (_i >= '0' && _i <= '9')