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/string-length/string-length.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 / string-length / string-length.om` 56 lines · 1062 bytes Raw Blame History 1 note Rosetta Code task "String length": https://rosettacode.org/wiki/String_length 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text tb " bytes " 6 text tc " characters\n" 7 text s1 "møøse" 8 text s2 "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" 9 text s3 "J̲o̲s̲é̲" 10 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 11 fn emit a view uchar * to void 12 o = ulong 0 13 while lt o len a bound 4096 14 k = write 1 a o sub len a o 15 if le k 0 16 exit 1 17 end 18 o = add o ulong k 19 end 20 end 21 note emitu writes n in decimal; 20 digits hold every ulong 22 fn emitu n ulong to void 23 d = new uchar 20 0 24 i = ulong 20 25 v = n 26 while true bound 20 27 i = sub i 1 28 put d i uchar add rem v 10 48 29 v = div v 10 30 if eq v 0 31 break 32 end 33 end 34 emit part d i sub 20 i 35 end 36 note a UTF-8 code point starts at every byte that is not a continuation byte 10xxxxxx 37 fn show a view uchar * to void 38 n = ulong 0 39 for i ulong len a 40 if ne and get a i 192 128 41 n = add n 1 42 end 43 end 44 emit a 45 emit nl 46 emitu len a 47 emit tb 48 emitu n 49 emit tc 50 end 51 fn main to int 52 show s1 53 show s2 54 show s3 55 ret 0 56 end