mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move toHex implementation to cpp file.
This commit is contained in:
parent
3a378eae1a
commit
e8455c2a6d
@ -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')
|
||||
|
@ -61,25 +61,7 @@ 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"
|
||||
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 (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();
|
||||
}
|
||||
std::string toHex(bytes const& _data, int _w = 2, HexPrefix _prefix = HexPrefix::DontAdd, HexCase _case = HexCase::Lower);
|
||||
|
||||
/// Converts a (printable) ASCII hex character into the correspnding integer value.
|
||||
/// @example fromHex('A') == 10 && fromHex('f') == 15 && fromHex('5') == 5
|
||||
|
Loading…
Reference in New Issue
Block a user