interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / substring.wiki

59 lines · 1198 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text str "abcdefgh"
8text cd "cd"
9note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10fn emit a view uchar * to void
11o = ulong 0
12while lt o len a bound 4096
13k = write 1 a o sub len a o
14if le k 0
15exit 1
16end
17o = add o ulong k
18end
19end
20note find returns the first index where t occurs in s; a missing t traps 9
21fn find s view uchar * t view uchar * to ulong
22for i ulong add sub len s len t 1
23m = true
24for j ulong len t
25if ne get s add i j get t j
26m = false
27end
28end
29if m
30ret i
31end
32end
33trap 9
34end
35fn line a view uchar * to void
36emit a
37emit nl
38end
39fn main to int
40n = ulong 2
41m = ulong 3
42note n characters in, m long; from n to the end; all but the last; from d, m long; from cd, m long
43line part str n m
44line part str n sub len str n
45line part str 0 sub len str 1
46c = new uchar 1 100
47line part str find str c m
48line part str find str cd m
49ret 0
50end
51</syntaxhighlight>
52{{out}}
53<pre>
54cde
55cdefgh
56abcdefg
57def
58cde
59</pre>