diff options
author | George Hazan <ghazan@miranda.im> | 2019-02-07 13:25:07 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-02-07 13:25:07 +0300 |
commit | e6edc1ba036f66f07878779d4d7a973c80d30efb (patch) | |
tree | c310656e2e9aaa4811e264ef2f811e79b5f582e4 /src/mir_core | |
parent | a9fbe9a81a6777b4b358d93116ee15f9f07dfb6e (diff) |
hopefully last custom UrlDecode implementation removed
Diffstat (limited to 'src/mir_core')
-rwxr-xr-x | src/mir_core/src/http.cpp | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/mir_core/src/http.cpp b/src/mir_core/src/http.cpp index 312647405e..64076968ed 100755 --- a/src/mir_core/src/http.cpp +++ b/src/mir_core/src/http.cpp @@ -19,25 +19,47 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /////////////////////////////////////////////////////////////////////////////////////////
-static const char szHexDigits[] = "0123456789ABCDEF";
+static int SingleHexToDecimal(char c)
+{
+ if (c >= '0' && c <= '9') return c - '0';
+ if (c >= 'a' && c <= 'f') return c - 'a' + 10;
+ if (c >= 'A' && c <= 'F') return c - 'A' + 10;
+ return -1;
+}
-MIR_CORE_DLL(CMStringA) mir_urlDecode(const char *szUrl)
+MIR_CORE_DLL(char*) mir_urlDecode(char *szUrl)
{
if (szUrl == nullptr)
- return CMStringA();
+ return nullptr;
- CMStringA ret(szUrl);
- ret.Replace("+", " ");
+ char *d = szUrl;
+ for (char *s = szUrl; *s; d++, s++) {
+ if (*s == '%') {
+ int digit1 = SingleHexToDecimal(s[1]);
+ if (digit1 != -1) {
+ int digit2 = SingleHexToDecimal(s[2]);
+ if (digit2 != -1) {
+ s += 2;
+ *d = (char)((digit1 << 4) | digit2);
+ continue;
+ }
+ }
+ }
- for (int i = ret.Find("%", 0); i != -1; i = ret.Find("%", i)) {
- int ii;
- sscanf(ret.c_str()+i+1, "%2x", &ii);
- ret.Delete(i, 3);
- ret.Insert(i, ii);
+ if (*s == '+')
+ *d = ' ';
+ else
+ *d = *s;
}
- return ret;
+ *d = 0;
+
+ return szUrl;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static const char szHexDigits[] = "0123456789ABCDEF";
+
MIR_CORE_DLL(CMStringA) mir_urlEncode(const char *szUrl)
{
if (szUrl == nullptr)
|