URL decoding: Difference between revisions
→{{header|AutoHotkey}}: old version didn't properly decode all UTF-8 characters
Langurmonkey (talk | contribs) |
(→{{header|AutoHotkey}}: old version didn't properly decode all UTF-8 characters) |
||
Line 260:
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">
UrlDecode(url) {
needle := "i)(?:%[0-9a-f]{2})+"
Loop {
position := RegExMatch(url, needle, code, position)
If (position = 0) {
{▼
VarSetCapacity(binary,
Loop, Parse, % SubStr(code, 2), % "%"
}▼
NumPut("0x" . A_LoopField, binary, A_Index - 1, "UChar")
▲ }
replacement := StrGet(&binary, "UTF-8")
url := RegExReplace(url, needle, replacement, , 1, position)
position := position + StrLen(replacement)
Return url
}
MsgBox % UrlDecode("http%3A%2F%2Ffoo%20bar%2F")
MsgBox % UrlDecode("google.com/search?q=%60Abdu%27l-Bah%C3%A1")
MsgBox % UrlDecode("%25%32%35")
</syntaxhighlight>
|