8 #ifndef NDN_STRING_HELPER_HPP
9 #define NDN_STRING_HELPER_HPP
24 toHex(
const uint8_t* array,
size_t arraySize)
26 if (array == 0 || arraySize == 0)
29 std::ostringstream result;
30 result.flags(std::ios::hex | std::ios::uppercase);
31 for (
size_t i = 0; i < arraySize; ++i) {
35 result << (
unsigned int)x;
49 if (found != std::string::npos) {
66 if (found != std::string::npos) {
67 if (found + 1 < str.size())
94 if (c >=
'0' && c <=
'9')
95 return (
int)c - (int)
'0';
96 else if (c >=
'A' && c <=
'F')
97 return (
int)c - (int)
'A' + 10;
98 else if (c >=
'a' && c <=
'f')
99 return (
int)c - (int)
'a' + 10;
111 std::ostringstream result;
113 for (
size_t i = 0; i < str.size(); ++i) {
114 if (str[i] ==
'%' && i + 2 < str.size()) {
118 if (hi < 0 || lo < 0)
120 result << str[i] << str[i + 1] << str[i + 2];
122 result << (uint8_t)(16 * hi + lo);
137 #endif // NDN_STRING_HELPER_HPP
static const char * WHITESPACE_CHARS
std::string unescape(const std::string &str)
Return a copy of str, converting each escaped "%XX" to the char value.
void trimRight(std::string &str)
Modify str in place to erase whitespace on the right.
std::string toHex(const uint8_t *array, size_t arraySize)
Return the hex representation of the bytes in array.
void trim(std::string &str)
Modify str in place to erase whitespace on the left and right.
void trimLeft(std::string &str)
Modify str in place to erase whitespace on the left.
int fromHexChar(uint8_t c)
Convert the hex character to an integer from 0 to 15, or -1 if not a hex character.