Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/url-decoding.wiki
# omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
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}}
3 Omega has no imports, so the small output helpers (emit and friends) are part of the program.
4
5 om2
6 text nl "\n"
7 text u1 "http%3A%2F%2Ffoo%20bar%2F"
8 text u2 "google.com/search?q=%60Abdu%27l-Bah%C3%A1"
9 text u3 "%25%32%35"
10 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11 fn emit a view uchar * to void
12 o = ulong 0
13 while lt o len a bound 4096
14 k = write 1 a o sub len a o
15 if le k 0
16 exit 1
17 end
18 o = add o ulong k
19 end
20 end
21 note hexv gives the value of one hex digit, either case; anything else traps 9
22 fn hexv c uchar to uchar
23 if and ge c 48 le c 57
24 ret sub c 48
25 end
26 if and ge c 65 le c 70
27 ret sub c 55
28 end
29 if and ge c 97 le c 102
30 ret sub c 87
31 end
32 trap 9
33 end
34 note dec turns every %XY into the byte 0xXY; the result bytes are written as they are (here UTF-8)
35 fn dec a view uchar * to void
36 o = new uchar 256 0
37 p = ulong 0
38 i = ulong 0
39 while lt i len a bound 4096
40 c = get a i
41 if eq c 37
42 c = or shl hexv get a add i 1 4 hexv get a add i 2
43 i = add i 3
44 else
45 i = add i 1
46 end
47 put o p c
48 p = add p 1
49 end
50 emit part o 0 p
51 emit nl
52 end
53 fn main to int
54 dec u1
55 dec u2
56 dec u3
57 ret 0
58 end
59
60 {{out}}
61
62 http://foo bar/
63 google.com/search?q=`Abdu'l-Bahá
64 %25
65