22 #ifndef NDN_CXX_UTIL_STRING_HELPER_HPP 23 #define NDN_CXX_UTIL_STRING_HELPER_HPP 33 using std::invalid_argument::invalid_argument;
46 printHex(std::ostream& os, uint64_t num,
bool wantUpperCase =
false);
59 printHex(std::ostream& os, span<const uint8_t> buffer,
bool wantUpperCase =
true);
80 [[deprecated(
"use the overload that takes a span<>")]]
82 printHex(std::ostream& os,
const uint8_t* buffer,
size_t length,
bool wantUpperCase =
true)
84 printHex(os, {buffer, length}, wantUpperCase);
111 printHex(os, hex.m_value, os.flags() & std::ostream::uppercase);
129 toHex(span<const uint8_t> buffer,
bool wantUpperCase =
true);
149 [[deprecated(
"use the overload that takes a span<>")]]
151 toHex(
const uint8_t* buffer,
size_t length,
bool wantUpperCase =
true)
153 return toHex({buffer, length}, wantUpperCase);
163 fromHex(
const std::string& hexString);
169 toHexChar(
unsigned int n,
bool wantUpperCase =
true) noexcept
171 return wantUpperCase ?
172 "0123456789ABCDEF"[n & 0xf] :
173 "0123456789abcdef"[n & 0xf];
182 return (c >=
'0' && c <=
'9') ? int(c -
'0') :
183 (c >=
'A' && c <=
'F') ?
int(c -
'A' + 10) :
184 (c >=
'a' && c <=
'f') ?
int(c -
'a' + 10) :
205 escape(
const std::string& str);
208 escape(std::ostream& os,
const char* str,
size_t len);
227 unescape(std::ostream& os,
const char* str,
size_t len);
231 #endif // NDN_CXX_UTIL_STRING_HELPER_HPP
Copyright (c) 2011-2015 Regents of the University of California.
std::string toHex(span< const uint8_t > buffer, bool wantUpperCase)
Return a string containing the hex representation of the bytes in buffer.
std::ostream & operator<<(std::ostream &os, const Data &data)
Helper class to convert a number to hexadecimal format, for use with stream insertion operators...
NDN_CXX_NODISCARD constexpr char toHexChar(unsigned int n, bool wantUpperCase=true) noexcept
Convert (the least significant nibble of) n to the corresponding hex character.
NDN_CXX_NODISCARD 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.
shared_ptr< Buffer > fromHex(const std::string &hexString)
Convert the hex string to buffer.
#define NDN_CXX_NODISCARD
std::string escape(const std::string &str)
Percent-encode a string.
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
std::string unescape(const std::string &str)
Decode a percent-encoded string.
constexpr AsHex(uint64_t val) noexcept