aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore/CommonData.h
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-06 03:34:27 +0800
committerchriseth <chris@ethereum.org>2018-12-06 05:37:05 +0800
commit3a378eae1a57683d0f31ab54c122b2a5c6a7c8bb (patch)
tree0d69fe0cf64211a9faad76b9dd87573826f1de2c /libdevcore/CommonData.h
parent15e28fa444843d6b8e5bef81ae9fc73a41ae97f6 (diff)
downloaddexon-solidity-3a378eae1a57683d0f31ab54c122b2a5c6a7c8bb.tar.gz
dexon-solidity-3a378eae1a57683d0f31ab54c122b2a5c6a7c8bb.tar.zst
dexon-solidity-3a378eae1a57683d0f31ab54c122b2a5c6a7c8bb.zip
Restrict toHex to `bytes`.
Diffstat (limited to 'libdevcore/CommonData.h')
-rw-r--r--libdevcore/CommonData.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h
index 4118907c..0a8c37d2 100644
--- a/libdevcore/CommonData.h
+++ b/libdevcore/CommonData.h
@@ -61,12 +61,11 @@ enum class HexCase
/// Convert a series of bytes to the corresponding string of hex duplets.
/// @param _w specifies the width of the first of the elements. Defaults to two - enough to represent a byte.
/// @example toHex("A\x69") == "4169"
-template <class T>
-std::string toHex(T const& _data, int _w = 2, HexPrefix _prefix = HexPrefix::DontAdd, HexCase _case = HexCase::Lower)
+inline std::string toHex(bytes const& _data, int _w = 2, HexPrefix _prefix = HexPrefix::DontAdd, HexCase _case = HexCase::Lower)
{
std::ostringstream ret;
int rix = _data.size() - 1;
- for (auto datum: _data)
+ for (uint8_t c: _data)
{
// switch hex case every four hexchars
auto hexcase = std::nouppercase;
@@ -76,7 +75,7 @@ std::string toHex(T const& _data, int _w = 2, HexPrefix _prefix = HexPrefix::Don
hexcase = (rix-- & 2) == 0 ? std::nouppercase : std::uppercase;
ret << std::hex << hexcase << std::setfill('0') << std::setw(_w)
- << +static_cast<typename std::make_unsigned<decltype(datum)>::type>(datum);
+ << size_t(c);
}
return (_prefix == HexPrefix::Add) ? "0x" + ret.str() : ret.str();