Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/substring/substring.om # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / substring / substring.om` 48 lines ยท 1029 bytes Raw Blame History 1 note Rosetta Code task "Substring": https://rosettacode.org/wiki/Substring 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text str "abcdefgh" 6 text cd "cd" 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 note find returns the first index where t occurs in s; a missing t traps 9 19 fn find s view uchar * t view uchar * to ulong 20 for i ulong add sub len s len t 1 21 m = true 22 for j ulong len t 23 if ne get s add i j get t j 24 m = false 25 end 26 end 27 if m 28 ret i 29 end 30 end 31 trap 9 32 end 33 fn line a view uchar * to void 34 emit a 35 emit nl 36 end 37 fn main to int 38 n = ulong 2 39 m = ulong 3 40 note n characters in, m long; from n to the end; all but the last; from d, m long; from cd, m long 41 line part str n m 42 line part str n sub len str n 43 line part str 0 sub len str 1 44 c = new uchar 1 100 45 line part str find str c m 46 line part str find str cd m 47 ret 0 48 end