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-comments-from-a-string.wiki

64 lines · 1259 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 lq "<<<"
8text rq ">>>"
9text s1 "apples, pears # and bananas"
10text s2 "apples, pears ; and bananas"
11text s3 " no comment here "
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note cut at the first '#' or ';', then drop whitespace (space, tab) at both ends of what is left
24fn strip a view uchar * to void
25e = len a
26for i ulong len a
27c = get a i
28if and eq e len a or eq c 35 eq c 59
29e = i
30end
31end
32s = ulong 0
33while lt s e bound 4096
34c = get a s
35if and ne c 32 ne c 9
36break
37end
38s = add s 1
39end
40while gt e s bound 4096
41c = get a sub e 1
42if and ne c 32 ne c 9
43break
44end
45e = sub e 1
46end
47emit lq
48emit part a s sub e s
49emit rq
50emit nl
51end
52fn main to int
53strip s1
54strip s2
55strip s3
56ret 0
57end
58</syntaxhighlight>
59{{out}}
60<pre>
61&lt;&lt;&lt;apples, pears>>>
62&lt;&lt;&lt;apples, pears>>>
63&lt;&lt;&lt;no comment here>>>
64</pre>