6#include <evmc/bytes.hpp>
7#include <evmc/filter_iterator.hpp>
16inline std::string
hex(uint8_t b)
noexcept
18 static constexpr auto hex_digits =
"0123456789abcdef";
19 return {hex_digits[b >> 4], hex_digits[b & 0xf]};
26 str.reserve(bs.size() * 2);
27 for (
const auto b : bs)
36inline constexpr int from_hex_digit(
char h)
noexcept
38 if (h >=
'0' && h <=
'9')
40 else if (h >=
'a' && h <=
'f')
42 else if (h >=
'A' && h <=
'F')
57template <
typename InputIt,
typename OutputIt>
58inline constexpr bool from_hex(InputIt begin, InputIt end, OutputIt out)
noexcept
62 for (
auto it = begin; it != end; ++it, ++i)
65 const int v = evmc::internal::from_hex_digit(h);
68 if (i == 1 && hi_nibble == 0 && h ==
'x')
76 *out++ =
static_cast<uint8_t
>(hi_nibble | v);
87 struct noop_output_iterator
90 uint8_t& operator*()
noexcept {
return sink; }
91 noop_output_iterator operator++(
int)
noexcept {
return *
this; }
104 bs.reserve(
hex.size() / 2);
116constexpr std::optional<T>
from_hex(std::string_view s)
noexcept
119 if (s.size() >= 2 && s[0] ==
'0' && s[1] ==
'x')
123 constexpr auto num_out_bytes = std::size(r.bytes);
124 const auto num_in_bytes = s.length() / 2;
125 if (num_in_bytes > num_out_bytes)
127 if (!
from_hex(s.begin(), s.end(), &r.bytes[num_out_bytes - num_in_bytes]))
137template <
typename InputIterator>
142 std::back_inserter(bs)))
EVMC C++ API - wrappers and bindings for C++.
std::string hex(uint8_t b) noexcept
Encode a byte to a hex string.
bool validate_hex(std::string_view hex) noexcept
Validates hex encoded string.
constexpr bool from_hex(InputIt begin, InputIt end, OutputIt out) noexcept
Decodes hex-encoded sequence of characters.
std::basic_string_view< unsigned char, byte_traits< unsigned char > > bytes_view
String view of unsigned chars representing bytes.
std::optional< bytes > from_spaced_hex(InputIterator begin, InputIterator end) noexcept
Decodes hex encoded string to bytes.
std::basic_string< unsigned char, byte_traits< unsigned char > > bytes
String of unsigned chars representing bytes.
The input filter iterator which skips whitespace characters from the base input iterator.