omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / strip-a-set-of-characters-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 msg "She was a soul stripper. She took my heart!" |
| 8 | text set1 "aei" |
| 9 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 10 | fn emit a view uchar * to void |
| 11 | o = ulong 0 |
| 12 | while lt o len a bound 4096 |
| 13 | k = write 1 a o sub len a o |
| 14 | if le k 0 |
| 15 | exit 1 |
| 16 | end |
| 17 | o = add o ulong k |
| 18 | end |
| 19 | end |
| 20 | note emitc writes one byte |
| 21 | fn emitc c uchar to void |
| 22 | b = new uchar 1 0 |
| 23 | put b 0 c |
| 24 | emit b |
| 25 | end |
| 26 | note stripchars writes the bytes of a that are not in set s |
| 27 | fn strip a view uchar * s view uchar * to void |
| 28 | for i ulong len a |
| 29 | c = get a i |
| 30 | k = true |
| 31 | for j ulong len s |
| 32 | if eq c get s j |
| 33 | k = false |
| 34 | end |
| 35 | end |
| 36 | if k |
| 37 | emitc c |
| 38 | end |
| 39 | end |
| 40 | emit nl |
| 41 | end |
| 42 | fn main to int |
| 43 | strip msg set1 |
| 44 | ret 0 |
| 45 | end |
| 46 | </syntaxhighlight> |
| 47 | {{out}} |
| 48 | <pre> |
| 49 | Sh ws soul strppr. Sh took my hrt! |
| 50 | </pre> |