interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / strip-comments-from-a-string / strip-comments-from-a-string.om

55 lines · 1066 bytes Raw Blame History
1note Rosetta Code task "Strip comments from a string": https://rosettacode.org/wiki/Strip_comments_from_a_string
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text lq "<<<"
6text rq ">>>"
7text s1 "apples, pears # and bananas"
8text s2 "apples, pears ; and bananas"
9text s3 " no comment here "
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 cut at the first '#' or ';', then drop whitespace (space, tab) at both ends of what is left
22fn strip a view uchar * to void
23e = len a
24for i ulong len a
25c = get a i
26if and eq e len a or eq c 35 eq c 59
27e = i
28end
29end
30s = ulong 0
31while lt s e bound 4096
32c = get a s
33if and ne c 32 ne c 9
34break
35end
36s = add s 1
37end
38while gt e s bound 4096
39c = get a sub e 1
40if and ne c 32 ne c 9
41break
42end
43e = sub e 1
44end
45emit lq
46emit part a s sub e s
47emit rq
48emit nl
49end
50fn main to int
51strip s1
52strip s2
53strip s3
54ret 0
55end