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 / string-matching.wiki

83 lines · 1472 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 sp " "
8text hay "tacoloco"
9text nd "co"
10text tst "starts with: "
11text tct "found at:"
12text ten "ends with: "
13text tyes "yes"
14text tno "no"
15note emit writes every byte of a to stdout; a short write is retried, an error exits 1
16fn emit a view uchar * to void
17o = ulong 0
18while lt o len a bound 4096
19k = write 1 a o sub len a o
20if le k 0
21exit 1
22end
23o = add o ulong k
24end
25end
26note emitu writes n in decimal; 20 digits hold every ulong
27fn emitu n ulong to void
28d = new uchar 20 0
29i = ulong 20
30v = n
31while true bound 20
32i = sub i 1
33put d i uchar add rem v 10 48
34v = div v 10
35if eq v 0
36break
37end
38end
39emit part d i sub 20 i
40end
41fn emitb b bool to void
42if b
43emit tyes
44else
45emit tno
46end
47end
48note at tells whether t occurs in s at offset i (false when it would run past the end)
49fn at2 s view uchar * t view uchar * i ulong to bool
50if gt add i len t len s
51ret false
52end
53for j ulong len t
54if ne get s add i j get t j
55ret false
56end
57end
58ret true
59end
60fn main to int
61emit tst
62emitb at2 hay nd 0
63emit nl
64emit tct
65for i ulong len hay
66if at2 hay nd i
67emit sp
68emitu i
69end
70end
71emit nl
72emit ten
73emitb at2 hay nd sub len hay len nd
74emit nl
75ret 0
76end
77</syntaxhighlight>
78{{out}}
79<pre>
80starts with: no
81found at: 2 6
82ends with: yes
83</pre>