-
Notifications
You must be signed in to change notification settings - Fork 0
/
URI.ahk
59 lines (51 loc) · 1.63 KB
/
URI.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
URI Encoding/Decoding Functions
(c) 2023-2024 Ken Verdadero
2023-10-05
*/
/**
* Encodes or decodes a URI string.
*
* Uses htmlfile COM object to encode/decode a URI string.
* @param {string} str - The string to encode/decode
* @param {number} encode
* @param {number} component
* @returns {void|number}
*/
EncodeDecodeURI(str, encode := true, component := true) {
static doc := 0, js := 0
if !doc {
doc := ComObject("htmlfile")
doc.write('<meta http-equiv="X-UA-Compatible" content="IE=edge">')
js := doc.parentWindow
(doc.documentMode < 9 && js.execScript())
}
command := (encode ? "en" : "de") . "codeURI" . (component ? "Component" : "")
switch command {
case "encodeURI": return js.encodeURI(str)
case "decodeURI": return js.decodeURI(str)
case "encodeURIComponent": return js.encodeURIComponent(str)
case "decodeURIComponent": return js.decodeURIComponent(str)
default:
MsgBox("Invalid command")
return 0
}
}
/**
* Shorthand encode URI function
* @param str - The string to encode
* @param {number} component - Whether to encode the entire URI or just the component
* @returns {void|number} - The encoded string
*/
EncodeURI(str, component := true) {
return EncodeDecodeURI(str, true, component)
}
/**
* Shorthand decode URI function
* @param str - The string to decode
* @param {number} component - Whether to decode the entire URI or just the component
* @returns {void|number} - The decoded string
*/
DecodeURI(str, component := true) {
return EncodeDecodeURI(str, false, component)
}