42 void write_hex(
T&& out,
const span<const std::uint8_t> src)
44 static constexpr
const char hex[] =
u8"0123456789abcdef";
45 static_assert(
sizeof(hex) == 17,
"bad string size");
57 T to_hex::convert(
const span<const std::uint8_t> src)
59 if (std::numeric_limits<std::size_t>::max() / 2 < src.size())
60 throw std::range_error(
"hex_view::to_string exceeded maximum size");
63 out.resize(src.size() * 2);
64 to_hex::buffer_unchecked((
char*)
out.data(), src);
73 write_hex(std::ostreambuf_iterator<char>{out}, src);
85 return write_hex(out, src);
91 auto include = [](
char input) {
97 auto count = std::count_if(src.begin(), src.end(), include);
101 throw std::length_error{
"Invalid hexadecimal input length" };
104 std::vector<uint8_t> result;
105 result.reserve(
count / 2);
108 auto data = src.data();
111 auto char_to_int = [](
const char *input) {
112 switch (std::tolower(*input)) {
129 default:
throw std::range_error{
"Invalid hexadecimal input" };
134 while (data[0] !=
'\0') {
136 if (!include(data[0])) {
142 auto high = char_to_int(data++);
143 auto low = char_to_int(data++);
145 result.push_back(high << 4 | low);
static epee::wipeable_string wipeable_string(const span< const std::uint8_t > src)
mdb_size_t count(MDB_cursor *cur)
static std::vector< uint8_t > vector(boost::string_ref src)
static void buffer(std::ostream &out, const span< const std::uint8_t > src)
Append src as hex to out.
static std::string string(const span< const std::uint8_t > src)
std::string hex(difficulty_type v)
static void formatted(std::ostream &out, const span< const std::uint8_t > src)
Append < + src + > as hex to out.