22 #ifndef NDN_UTIL_STRING_HELPER_HPP 23 #define NDN_UTIL_STRING_HELPER_HPP 36 : std::invalid_argument(what)
68 operator<<(std::ostream& os,
const AsHex& hex);
80 printHex(std::ostream& os, uint64_t num,
bool wantUpperCase =
false);
102 printHex(std::ostream& os,
const uint8_t* buffer,
size_t length,
bool wantUpperCase =
true);
112 printHex(std::ostream& os,
const Buffer& buffer,
bool wantUpperCase =
true);
133 toHex(
const uint8_t* buffer,
size_t length,
bool wantUpperCase =
true);
142 toHex(
const Buffer& buffer,
bool wantUpperCase =
true);
151 fromHex(
const std::string& hexString);
157 toHexChar(
unsigned int n,
bool wantUpperCase =
true) noexcept
159 return wantUpperCase ?
160 "0123456789ABCDEF"[n & 0xf] :
161 "0123456789abcdef"[n & 0xf];
170 return (c >=
'0' && c <=
'9') ? int(c -
'0') :
171 (c >=
'A' && c <=
'F') ?
int(c -
'A' + 10) :
172 (c >=
'a' && c <=
'f') ?
int(c -
'a' + 10) :
193 escape(
const std::string& str);
196 escape(std::ostream& os,
const char* str,
size_t len);
215 unescape(std::ostream& os,
const char* str,
size_t len);
219 #endif // NDN_UTIL_STRING_HELPER_HPP
Copyright (c) 2011-2015 Regents of the University of California.
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.
StringHelperError(const std::string &what)
friend std::ostream & operator<<(std::ostream &, const AsHex &)
import common constructs for ndn-cxx library internal use
shared_ptr< Buffer > fromHex(const std::string &hexString)
Convert the hex string to buffer.
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.
constexpr AsHex(uint64_t val) noexcept