MCPcopy Create free account
hub / github.com/apache/trafficserver / unhex

Function unhex

include/tsutil/StringConvert.h:74–95  ·  view source on GitHub ↗

* Convert input hex string into a string * * The input string must have even size and be comprised of hex digits [0-f]. Each two-digit pair is converted from hex to a * character in the resulting output string. * * @param input Input string view * @return The unhexified result string * * @note this is a specialization of boost::algorithms::unhex */

Source from the content-addressed store, hash-verified

72 * @note this is a specialization of boost::algorithms::unhex
73 */
74inline std::string
75unhex(const std::string_view input)
76{
77 std::string result;
78
79 if (input.size() % 2 != 0) {
80 throw std::invalid_argument("input to unhex needs to be an even size");
81 }
82
83 result.resize(input.size() / 2);
84
85 const char *p = input.data();
86 for (auto &x : result) {
87 if (auto [ptr, err] = std::from_chars(p, p + 2, reinterpret_cast<unsigned char &>(x), 16); err == std::errc()) {
88 p = ptr;
89 } else {
90 throw std::runtime_error(std::make_error_code(err).message().c_str());
91 }
92 }
93
94 return result;
95}
96
97} // namespace ts

Callers 2

UnHexMethod · 0.85

Calls 6

make_error_codeFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
c_strMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected