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