22 #ifndef NDN_UTIL_STRING_HELPER_HPP 23 #define NDN_UTIL_STRING_HELPER_HPP 32 using std::invalid_argument::invalid_argument;
45 printHex(std::ostream& os, uint64_t num,
bool wantUpperCase =
false);
67 printHex(std::ostream& os,
const uint8_t* buffer,
size_t length,
bool wantUpperCase =
true);
79 return printHex(os, buffer.data(), buffer.size(), wantUpperCase);
106 printHex(os, hex.m_value, os.flags() & std::ostream::uppercase);
133 toHex(
const uint8_t* buffer,
size_t length,
bool wantUpperCase =
true);
144 return toHex(buffer.data(), buffer.size(), wantUpperCase);
154 fromHex(
const std::string& hexString);
160 toHexChar(
unsigned int n,
bool wantUpperCase =
true) noexcept
162 return wantUpperCase ?
163 "0123456789ABCDEF"[n & 0xf] :
164 "0123456789abcdef"[n & 0xf];
173 return (c >=
'0' && c <=
'9') ? int(c -
'0') :
174 (c >=
'A' && c <=
'F') ?
int(c -
'A' + 10) :
175 (c >=
'a' && c <=
'f') ?
int(c -
'a' + 10) :
196 escape(
const std::string& str);
199 escape(std::ostream& os,
const char* str,
size_t len);
218 unescape(std::ostream& os,
const char* str,
size_t len);
222 #endif // NDN_UTIL_STRING_HELPER_HPP
std::string toHex(const uint8_t *buffer, size_t length, 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...
shared_ptr< Buffer > fromHex(const std::string &hexString)
Convert the hex string to buffer.
#define NDN_CXX_NODISCARD
std::string unescape(const std::string &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.
std::string escape(const std::string &str)
Percent-encode a string.
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.
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
General-purpose automatically managed/resized buffer.
constexpr AsHex(uint64_t val) noexcept