diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-06-03 09:37:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-03 09:37:57 +0200 |
commit | 60f66958dcf7c0e5c7df0302959e432d6b002aad (patch) | |
tree | e44e410ba985d10416fc8e63f50faa2447585f63 /core/string | |
parent | 45cf0ac3d8ffd2998d5a7ae943996714a42d67b7 (diff) | |
parent | 83990c2161f1e2f4235c0775fa276e26bf3ecae9 (diff) |
Merge pull request #61656 from timothyqiu/uri-encode-mingw
Fix `String.uri_encode` on Windows
Diffstat (limited to 'core/string')
-rw-r--r-- | core/string/ustring.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 44df349613..d189f3224b 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -3712,18 +3712,15 @@ String String::uri_encode() const { const CharString temp = utf8(); String res; for (int i = 0; i < temp.length(); ++i) { - char ord = temp[i]; + uint8_t ord = temp[i]; if (ord == '.' || ord == '-' || ord == '~' || is_ascii_identifier_char(ord)) { res += ord; } else { - char h_Val[3]; -#if defined(__GNUC__) || defined(_MSC_VER) - snprintf(h_Val, 3, "%02hhX", ord); -#else - sprintf(h_Val, "%02hhX", ord); -#endif - res += "%"; - res += h_Val; + char p[4] = { '%', 0, 0, 0 }; + static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + p[1] = hex[ord >> 4]; + p[2] = hex[ord & 0xF]; + res += p; } } return res; |