interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / url-decoding.wiki

65 lines · 1334 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text u1 "http%3A%2F%2Ffoo%20bar%2F"
8text u2 "google.com/search?q=%60Abdu%27l-Bah%C3%A1"
9text u3 "%25%32%35"
10note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11fn emit a view uchar * to void
12o = ulong 0
13while lt o len a bound 4096
14k = write 1 a o sub len a o
15if le k 0
16exit 1
17end
18o = add o ulong k
19end
20end
21note hexv gives the value of one hex digit, either case; anything else traps 9
22fn hexv c uchar to uchar
23if and ge c 48 le c 57
24ret sub c 48
25end
26if and ge c 65 le c 70
27ret sub c 55
28end
29if and ge c 97 le c 102
30ret sub c 87
31end
32trap 9
33end
34note dec turns every %XY into the byte 0xXY; the result bytes are written as they are (here UTF-8)
35fn dec a view uchar * to void
36o = new uchar 256 0
37p = ulong 0
38i = ulong 0
39while lt i len a bound 4096
40c = get a i
41if eq c 37
42c = or shl hexv get a add i 1 4 hexv get a add i 2
43i = add i 3
44else
45i = add i 1
46end
47put o p c
48p = add p 1
49end
50emit part o 0 p
51emit nl
52end
53fn main to int
54dec u1
55dec u2
56dec u3
57ret 0
58end
59</syntaxhighlight>
60{{out}}
61<pre>
62http://foo bar/
63google.com/search?q=`Abdu'l-Bahá
64%25
65</pre>