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-mv/blob/main/si/rosetta/tasks/camel-case-and-snake-case/camel-case-and-snake-case.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / camel-case-and-snake-case / camel-case-and-snake-case.om` 115 lines ยท 2067 bytes Raw Blame History 1 note Rosetta Code task "Camel case and snake case": https://rosettacode.org/wiki/Camel_case_and_snake_case 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text tsn " -> snake: " 6 text tcm " -> camel: " 7 text c0 "snakeCase" 8 text c1 "snake_case" 9 text c2 "variable_10_case" 10 text c3 "variable10Case" 11 text c4 "hurry-up-joe!" 12 text c5 "c://my-docs/happy_Flag-Day/12.doc" 13 text c6 " spaces " 14 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 15 fn emit a view uchar * to void 16 o = ulong 0 17 while lt o len a bound 4096 18 k = write 1 a o sub len a o 19 if le k 0 20 exit 1 21 end 22 o = add o ulong k 23 end 24 end 25 note emitc writes one byte 26 fn emitc c uchar to void 27 b = new uchar 1 0 28 put b 0 c 29 emit b 30 end 31 note leading and trailing spaces are kept as they are; inside the text, space and '-' count as 32 note separators like '_' 33 fn issep c uchar to bool 34 ret or or eq c 95 eq c 45 eq c 32 35 end 36 fn lead a view uchar * to ulong 37 for i ulong len a 38 if ne get a i 32 39 ret i 40 end 41 end 42 ret len a 43 end 44 fn trail a view uchar * to ulong 45 for i ulong len a 46 if ne get a sub sub len a 1 i 32 47 ret sub len a i 48 end 49 end 50 ret 0 51 end 52 note snake: a separator becomes '_', an upper-case letter becomes '_' and its lower case (no '_' first 53 note when it is at the start or follows a separator) 54 fn snake a view uchar * to void 55 l = lead a 56 t = trail a 57 emit part a 0 l 58 for i ulong sub t l 59 k = add l i 60 c = get a k 61 if issep c 62 emitc 95 63 else 64 if and ge c 65 le c 90 65 if gt i 0 66 if not issep get a sub k 1 67 emitc 95 68 end 69 end 70 emitc add c 32 71 else 72 emitc c 73 end 74 end 75 end 76 emit part a t sub len a t 77 end 78 note camel: separators are dropped and the letter after one is upper-cased 79 fn camel a view uchar * to void 80 l = lead a 81 t = trail a 82 emit part a 0 l 83 up = false 84 for i ulong sub t l 85 c = get a add l i 86 if issep c 87 up = true 88 else 89 if and up and ge c 97 le c 122 90 c = sub c 32 91 end 92 emitc c 93 up = false 94 end 95 end 96 emit part a t sub len a t 97 end 98 fn show a view uchar * to void 99 emit a 100 emit tsn 101 snake a 102 emit tcm 103 camel a 104 emit nl 105 end 106 fn main to int 107 show c0 108 show c1 109 show c2 110 show c3 111 show c4 112 show c5 113 show c6 114 ret 0 115 end