24 #ifndef STATICLIB_IO_HEX_SOURCE_HPP
25 #define STATICLIB_IO_HEX_SOURCE_HPP
32 #include "staticlib/config.hpp"
45 template<
typename Source>
54 std::array<char, 3> hbuf;
91 src(std::move(other.src)),
92 hbuf(std::move(other.hbuf)) { }
101 src = std::move(other.src);
102 hbuf = std::move(other.hbuf);
114 while (idx < span.
size()) {
119 char byte =
static_cast<char> (strtol(hbuf.data(), std::addressof(end), 16));
120 if (errno == ERANGE || end != hbuf.data() + 2) {
121 throw io_exception(TRACEMSG(
"Error parsing byte from HEX-pair: [" + std::string(hbuf.data(), 2) +
"]"));
123 span.
data()[idx] = byte;
125 }
else if (1 ==
read) {
126 throw io_exception(TRACEMSG(
"Invalid non-even number of bytes available in HEX source"));
127 }
else if (0 ==
read) {
130 throw io_exception(TRACEMSG(
"Invalid hex decoder state"));
134 return static_cast<std::streamsize
>(idx);
136 return std::char_traits<char>::eof();
157 template <
typename Source,
158 class =
typename std::enable_if<!std::is_lvalue_reference<Source>::value>::type>
170 template <
typename Source>