omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / tokenize-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 dot "." |
| 8 | text msg "Hello,How,Are,You,Today" |
| 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 splits at every comma, keeps the pieces as (start, length) pairs, then joins them with periods |
| 21 | fn main to int |
| 22 | st = new ulong 64 0 |
| 23 | ln = new ulong 64 0 |
| 24 | k = ulong 0 |
| 25 | s = ulong 0 |
| 26 | for i ulong add len msg 1 |
| 27 | if or eq i len msg eq get msg rem i len msg 44 |
| 28 | put st k s |
| 29 | put ln k sub i s |
| 30 | k = add k 1 |
| 31 | s = add i 1 |
| 32 | end |
| 33 | end |
| 34 | for j ulong k |
| 35 | if gt j 0 |
| 36 | emit dot |
| 37 | end |
| 38 | emit part msg get st j get ln j |
| 39 | end |
| 40 | emit nl |
| 41 | ret 0 |
| 42 | end |
| 43 | </syntaxhighlight> |
| 44 | {{out}} |
| 45 | <pre> |
| 46 | Hello.How.Are.You.Today |
| 47 | </pre> |