URL encoding: Difference between revisions

→‎{{header|AutoHotkey}}: updated code to remove the need to use SetFormat
(→‎{{header|AutoHotkey}}: updated code to remove the need to use SetFormat)
Line 273:
 
; Modified from http://goo.gl/0a0iJq
UriEncode(Uri, Reserved:="!#$&'()*+,/:;=?@[]") {
Unreserved := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~"
{
VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0)
StrPut(Uri, &Var, "UTF-8")
While (Code := NumGet(Var, A_Index - 1, "UChar")) {
f := A_FormatInteger
If InStr(Unreserved . Reserved, Chr(Code)) {
SetFormat, IntegerFast, H
ResEncoded .= Chr(Code)
While Code := NumGet(Var, A_Index - 1, "UChar")
}
If (Code >= 0x30 && Code <= 0x39 ; 0-9
Else {
|| Code >= 0x41 && Code <= 0x5A ; A-Z
||Encoded Code >.= 0x61 &&Format("%{:02X}", Code <= 0x7A) ; a-z
}
Res .= Chr(Code)
}
Else
Return, ResEncoded
Res .= "%" . SubStr(Code + 0x100, -1)
SetFormat, IntegerFast, %f%
Return, Res
}</syntaxhighlight>
 
5

edits