omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / tasks / rot-13 / rot-13.om
| 1 | note Rosetta Code task "Rot-13": https://rosettacode.org/wiki/Rot-13 |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | om2 |
| 4 | text nl "\n" |
| 5 | text s1 "Hello, World!" |
| 6 | text s2 "The Quick Brown Fox Jumps Over The Lazy Dog." |
| 7 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 8 | fn emit a view uchar * to void |
| 9 | o = ulong 0 |
| 10 | while lt o len a bound 4096 |
| 11 | k = write 1 a o sub len a o |
| 12 | if le k 0 |
| 13 | exit 1 |
| 14 | end |
| 15 | o = add o ulong k |
| 16 | end |
| 17 | end |
| 18 | fn rot13 a view uchar * to void |
| 19 | r = new uchar 256 0 |
| 20 | for i ulong len a |
| 21 | c = get a i |
| 22 | if and ge c 65 le c 90 |
| 23 | c = add rem add sub c 65 13 26 65 |
| 24 | else |
| 25 | if and ge c 97 le c 122 |
| 26 | c = add rem add sub c 97 13 26 97 |
| 27 | end |
| 28 | end |
| 29 | put r i c |
| 30 | end |
| 31 | emit part r 0 len a |
| 32 | emit nl |
| 33 | end |
| 34 | fn main to int |
| 35 | rot13 s1 |
| 36 | rot13 s2 |
| 37 | ret 0 |
| 38 | end |