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-comparison.wiki

97 lines · 1705 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 a1 "alpha"
9text b1 "beta"
10text a2 "Hello"
11text b2 "hello"
12text a3 "abc"
13text b3 "abcd"
14text teq " eq="
15text tlt " lt="
16text tgt " gt="
17text tci " equal-ignoring-case="
18text tyes "yes"
19text tno "no"
20note emit writes every byte of a to stdout; a short write is retried, an error exits 1
21fn emit a view uchar * to void
22o = ulong 0
23while lt o len a bound 4096
24k = write 1 a o sub len a o
25if le k 0
26exit 1
27end
28o = add o ulong k
29end
30end
31fn emitb b bool to void
32if b
33emit tyes
34else
35emit tno
36end
37end
38note cmp is byte order: -1, 0 or 1; a proper prefix sorts first; ci folds ASCII case first
39fn cmp a view uchar * b view uchar * ci bool to int
40n = len a
41if lt len b n
42n = len b
43end
44for i ulong n
45x = get a i
46y = get b i
47if and ci and ge x 65 le x 90
48x = add x 32
49end
50if and ci and ge y 65 le y 90
51y = add y 32
52end
53if lt x y
54ret -1
55end
56if gt x y
57ret 1
58end
59end
60if lt len a len b
61ret -1
62end
63if gt len a len b
64ret 1
65end
66ret 0
67end
68fn show a view uchar * b view uchar * to void
69c = cmp a b false
70emit a
71emit sp
72emit b
73emit teq
74emitb eq c 0
75emit tlt
76emitb lt c 0
77emit tgt
78emitb gt c 0
79emit tci
80emitb eq cmp a b true 0
81emit nl
82end
83fn main to int
84show a1 b1
85show a2 b2
86show a3 b3
87show b3 a3
88ret 0
89end
90</syntaxhighlight>
91{{out}}
92<pre>
93alpha beta eq=no lt=yes gt=no equal-ignoring-case=no
94Hello hello eq=no lt=yes gt=no equal-ignoring-case=yes
95abc abcd eq=no lt=yes gt=no equal-ignoring-case=no
96abcd abc eq=no lt=no gt=yes equal-ignoring-case=no
97</pre>