6#include <evmc/filter_iterator.hpp>
15using bytes = std::basic_string<uint8_t>;
18using bytes_view = std::basic_string_view<uint8_t>;
22inline std::string
hex(uint8_t b)
noexcept
24 static constexpr auto hex_digits =
"0123456789abcdef";
25 return {hex_digits[b >> 4], hex_digits[b & 0xf]};
32 str.reserve(bs.size() * 2);
33 for (
const auto b : bs)
42inline constexpr int from_hex_digit(
char h)
noexcept
44 if (h >=
'0' && h <=
'9')
46 else if (h >=
'a' && h <=
'f')
48 else if (h >=
'A' && h <=
'F')
63template <
typename InputIt,
typename OutputIt>
64inline constexpr bool from_hex(InputIt begin, InputIt end, OutputIt out)
noexcept
68 for (
auto it = begin; it != end; ++it, ++i)
71 const int v = evmc::internal::from_hex_digit(h);
74 if (i == 1 && hi_nibble == 0 && h ==
'x')
82 *out++ =
static_cast<uint8_t
>(hi_nibble | v);
93 struct noop_output_iterator
96 uint8_t& operator*()
noexcept {
return sink; }
97 noop_output_iterator operator++(
int)
noexcept {
return *
this; }
110 bs.reserve(
hex.size() / 2);
122constexpr std::optional<T>
from_hex(std::string_view s)
noexcept
125 if (s.size() >= 2 && s[0] ==
'0' && s[1] ==
'x')
129 constexpr auto num_out_bytes = std::size(r.bytes);
130 const auto num_in_bytes = s.length() / 2;
131 if (num_in_bytes > num_out_bytes)
133 if (!
from_hex(s.begin(), s.end(), &r.bytes[num_out_bytes - num_in_bytes]))
143template <
typename InputIterator>
148 std::back_inserter(bs)))
EVMC C++ API - wrappers and bindings for C++.
std::basic_string< uint8_t > bytes
String of uint8_t chars.
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< uint8_t > bytes_view
String view of uint8_t chars.
std::optional< bytes > from_spaced_hex(InputIterator begin, InputIterator end) noexcept
Decodes hex encoded string to bytes.
The input filter iterator which skips whitespace characters from the base input iterator.