added urldecode()

This commit is contained in:
2021-07-15 17:04:27 +02:00
parent a504262f39
commit 98a78a708a
2 changed files with 36 additions and 0 deletions

View File

@ -1,5 +1,8 @@
#include "espstrutils.h"
// system includes
#include <cctype>
namespace espcpputils {
std::string toString(sntp_sync_mode_t val)
@ -13,4 +16,35 @@ std::string toString(sntp_sync_mode_t val)
return std::string{"Unknown sntp_sync_mode_t("} + std::to_string(int(val)) + ')';
}
void urldecode(char *dst, const char *src)
{
while (*src) {
char a, b;
if ((*src == '%') && ((a = src[1]) && (b = src[2])) && (std::isxdigit(a) && std::isxdigit(b))) {
if (a >= 'a')
a -= 'a'-'A';
if (a >= 'A')
a -= ('A' - 10);
else
a -= '0';
if (b >= 'a')
b -= 'a'-'A';
if (b >= 'A')
b -= ('A' - 10);
else
b -= '0';
*dst++ = 16*a+b;
src+=3;
} else if (*src == '+') {
*dst++ = ' ';
src++;
} else
*dst++ = *src++;
}
*dst++ = '\0';
}
} // namespace espcpputils

View File

@ -10,4 +10,6 @@ namespace espcpputils {
std::string toString(sntp_sync_mode_t val);
void urldecode(char *dst, const char *src);
} // namespace espcpputils