diff --git a/src/espstrutils.cpp b/src/espstrutils.cpp index 2980659..95c9cf5 100644 --- a/src/espstrutils.cpp +++ b/src/espstrutils.cpp @@ -1,5 +1,8 @@ #include "espstrutils.h" +// system includes +#include + 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 diff --git a/src/espstrutils.h b/src/espstrutils.h index 9c4ca5a..8694162 100644 --- a/src/espstrutils.h +++ b/src/espstrutils.h @@ -10,4 +10,6 @@ namespace espcpputils { std::string toString(sntp_sync_mode_t val); +void urldecode(char *dst, const char *src); + } // namespace espcpputils