diff options
author | chriseth <chris@ethereum.org> | 2018-12-20 01:06:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-20 01:06:13 +0800 |
commit | 1df8f40cd2fd7b47698d847907b8ca7b47eb488d (patch) | |
tree | 5ed5816fe2d1a8a207e750d39884aca7957c8289 /libdevcore/CommonData.cpp | |
parent | c8a2cb62832afb2dc09ccee6fd42c1516dfdb981 (diff) | |
parent | ddf54b21d1d002903624f61173ab4af197f50053 (diff) | |
download | dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.gz dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.bz2 dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.lz dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.xz dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.zst dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.zip |
Merge pull request #5697 from ethereum/develop
Merge develop into release for 0.5.2
Diffstat (limited to 'libdevcore/CommonData.cpp')
-rw-r--r-- | libdevcore/CommonData.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 8d2639c9..1b0e9720 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -29,6 +29,28 @@ using namespace std; using namespace dev; +string dev::toHex(bytes const& _data, HexPrefix _prefix, HexCase _case) +{ + std::ostringstream ret; + if (_prefix == HexPrefix::Add) + ret << "0x"; + + 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(2) << size_t(c); + } + + return ret.str(); +} + int dev::fromHex(char _i, WhenError _throw) { if (_i >= '0' && _i <= '9') |