URL decoding: Difference between revisions

→‎{{header|AutoHotkey}}: old version didn't properly decode all UTF-8 characters
(→‎{{header|AutoHotkey}}: old version didn't properly decode all UTF-8 characters)
Line 260:
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">encURL := "http%3A%2F%2Ffoo%20bar%2F"
UrlDecode(url) {
SetFormat, Integer, hex
needle := "i)(?:%[0-9a-f]{2})+"
Loop Parse, encURL
If A_LoopFieldposition := `%1
Loop {
reading := 2, read := ""
position := RegExMatch(url, needle, code, position)
else if reading
If (position = 0) {
{
read .= A_LoopField, --reading Break
if not reading}
VarSetCapacity(binary, out .= ChrStrLen("0x"code) // .3, read0)
Loop, Parse, % SubStr(code, 2), % "%"
}
else out .= A_LoopField {
NumPut("0x" . A_LoopField, binary, A_Index - 1, "UChar")
MsgBox % out ; http://foo bar/
}
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>
 
5

edits