36 printHex(std::ostream& os, uint64_t num,
bool wantUpperCase)
38 auto oldFlags = os.flags();
39 auto restoreFlags = make_scope_exit([&] {
44 os <<
"0x" << std::noshowbase << std::noshowpos
45 << (wantUpperCase ? std::uppercase : std::nouppercase)
50 printHex(std::ostream& os, span<const uint8_t> buffer,
bool wantUpperCase)
52 namespace tr = security::transform;
57 toHex(span<const uint8_t> buffer,
bool wantUpperCase)
59 std::ostringstream result;
60 printHex(result, buffer, wantUpperCase);
67 namespace tr = security::transform;
73 catch (
const tr::Error& e) {
83 std::ostringstream os;
89 escape(std::ostream& os, std::string_view str)
93 if ((c >=
'a' && c <=
'z') ||
94 (c >=
'A' && c <=
'Z') ||
95 (c >=
'0' && c <=
'9') ||
96 c ==
'-' || c ==
'.' ||
97 c ==
'_' || c ==
'~') {
111 std::ostringstream os;
119 for (
size_t i = 0; i < str.size(); ++i) {
120 if (str[i] ==
'%' && i + 2 < str.size()) {
124 if (hi < 0 || lo < 0)
126 os << str[i] << str[i + 1] << str[i + 2];
128 os << static_cast<char>((hi << 4) | lo);
An output stream that writes to a Buffer.
std::shared_ptr< Buffer > buf()
Return a shared pointer to the underlying buffer.
#define NDN_THROW_NESTED(e)
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
std::string escape(std::string_view str)
Percent-encode a string.
std::string toHex(span< const uint8_t > buffer, bool wantUpperCase)
Return a string containing the hex representation of the bytes in buffer.
shared_ptr< Buffer > fromHex(std::string_view hexString)
Convert a hex string to a raw byte buffer.
constexpr int fromHexChar(char c) noexcept
Convert the hex character c to an integer in [0, 15], or -1 if it's not a hex character.
std::string unescape(std::string_view str)
Decode a percent-encoded string.
constexpr char toHexChar(unsigned int n, bool wantUpperCase=true) noexcept
Convert (the least significant nibble of) n to the corresponding hex character.