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

Function hex

include/tsutil/StringConvert.h:40–61  ·  view source on GitHub ↗

* Convert input string into a hex string * * Each character in input is interpreted as an unsigned char and represented as a two-digit hex value [0-255] in the returned * string. * * @param input Input string view * @return The hex representation of the input string * * @note this is a specialization of boost::algorithms::hex */

Source from the content-addressed store, hash-verified

38 * @note this is a specialization of boost::algorithms::hex
39 */
40inline std::string
41hex(const std::string_view input)
42{
43 std::string result;
44
45 result.resize(input.size() * 2);
46
47 char *p = result.data();
48 char *end = p + result.size();
49 for (unsigned char x : input) {
50 if (x < 0x10) {
51 *p++ = '0';
52 }
53 if (auto [ptr, err] = std::to_chars(p, end, x, 16); err == std::errc()) {
54 p = ptr;
55 } else {
56 throw std::runtime_error(std::make_error_code(err).message().c_str());
57 }
58 }
59
60 return result;
61}
62
63/**
64 * Convert input hex string into a string

Callers 6

encode_streamFunction · 0.85
HexMethod · 0.85
int_to_hex_stringFunction · 0.85
HexMethod · 0.85
HexMethod · 0.85

Calls 6

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

Tested by 2

encode_streamFunction · 0.68
int_to_hex_stringFunction · 0.68