interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / tokenize-a-string / tokenize-a-string.om

40 lines · 853 bytes Raw Blame History
1note Rosetta Code task "Tokenize a string": https://rosettacode.org/wiki/Tokenize_a_string
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text dot "."
6text msg "Hello,How,Are,You,Today"
7note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note splits at every comma, keeps the pieces as (start, length) pairs, then joins them with periods
19fn main to int
20st = new ulong 64 0
21ln = new ulong 64 0
22k = ulong 0
23s = ulong 0
24for i ulong add len msg 1
25if or eq i len msg eq get msg rem i len msg 44
26put st k s
27put ln k sub i s
28k = add k 1
29s = add i 1
30end
31end
32for j ulong k
33if gt j 0
34emit dot
35end
36emit part msg get st j get ln j
37end
38emit nl
39ret 0
40end