26#ifndef ROUTER_SRC_REST_MRS_SRC_HELPER_STRING_HEX_H_ 
   27#define ROUTER_SRC_REST_MRS_SRC_HELPER_STRING_HEX_H_ 
   42    os << std::setfill(
'0') << std::setw(2) << 
std::hex;
 
   45  template <
typename ValueType>
 
   54    os << std::setfill(
'0') << std::setw(2) << 
std::hex;
 
   57  int operator()(
const char &v) { 
return (
int)
static_cast<uint8_t
>(v); }
 
   60template <
typename Container, 
typename Transform = DefaultHex>
 
   61std::string 
hex(
const Container &c) {
 
   64  auto end = std::end(c);
 
   66  static_assert(
sizeof(
decltype(*it)) == 1);
 
   68  for (; it != end; ++it) {
 
   76  static_assert(
'0' < 
'A');
 
   77  static_assert(
'A' < 
'a');
 
   78  static_assert(
'0' < 
'9');
 
   80  if (c > 
'f') 
return false;
 
   87  if (c > 
'F') 
return false;
 
   94  if (c > 
'9') 
return false;
 
  107  throw std::runtime_error(
"Invalid character in hexadecimal value.");
 
  117    throw std::runtime_error(
"Invalid character in hexadecimal value.");
 
  121template <HexConverter converter, 
typename IT1, 
typename IT2>
 
  125    if (it == end) 
return false;
 
  126    result = converter(*it, out);
 
  132template <
typename Container,
 
  134Container 
unhex(
const std::string &h) {
 
  138  for (
auto i = h.begin(); i != h.end();) {
 
  139    if (!get_hex_skip<converter>(i, h.end(), &v2)) 
break;
 
  140    if (!get_hex_skip<converter>(i, h.end(), &v1)) 
break;
 
  141    uint8_t v = v2 * 16 + v1;
 
void operator()(std::ostringstream &os)
Definition: hex.h:53
 
int operator()(const char &v)
Definition: hex.h:57
 
void operator()(std::ostringstream &os)
Definition: hex.h:41
 
int operator()(const ValueType &v)
Definition: hex.h:46
 
uint8_t unhex_character(const char c)
Definition: hex.h:114
 
std::string hex(const Container &c)
Definition: hex.h:61
 
Container unhex(const std::string &h)
Definition: hex.h:134
 
bool(*)(const char c, uint8_t *out) HexConverter
Definition: hex.h:112
 
bool get_unhex_character_or_throw(const char c, uint8_t *out)
Definition: hex.h:104
 
bool get_unhex_character(const char c, uint8_t *out)
Definition: hex.h:75
 
bool get_hex_skip(IT1 &it, const IT2 &end, uint8_t *out)
Definition: hex.h:122
 
const char * begin(const char *const c)
Definition: base64.h:44
 
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2876
 
struct result result
Definition: result.h:34