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 / strip-whitespace-from-a-string.wiki

65 lines · 1218 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 lb "["
8text rb "]"
9text msg " \t hello world \t\n "
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 white: space, tab, newline, vertical tab, form feed, carriage return
22fn white c uchar to bool
23ret or eq c 32 and ge c 9 le c 13
24end
25fn lead a view uchar * to ulong
26for i ulong len a
27if not white get a i
28ret i
29end
30end
31ret len a
32end
33fn trail a view uchar * to ulong
34for i ulong len a
35if not white get a sub sub len a 1 i
36ret sub len a i
37end
38end
39ret 0
40end
41fn show a view uchar * to void
42emit lb
43emit a
44emit rb
45emit nl
46end
47fn main to int
48l = lead msg
49t = trail msg
50show msg
51show part msg l sub len msg l
52show part msg 0 t
53show part msg l sub t l
54ret 0
55end
56</syntaxhighlight>
57{{out}}
58<pre>
59[ hello world
60 ]
61[hello world
62 ]
63[ hello world]
64[hello world]
65</pre>