ITADN
c3lang/c3c/Issues

`@str_*case` issues

#3287Opencmann1 创建于 2026-06-01
Enhancement Request
C
cmann1commented
1. Pascal and camel return the same values - camel case should _uncapitilise_ the first latter. 2. Pascal/camel case incorrectly lower case "inner" words, while snake case correctly inserts an underscore. e.g. `helloWorld` currently becomes `Helloworld` instead of `HelloWorld`. 3. Constant and snake case don't handle spaces. 4. Snake case incorrectly inserts an extra underscore if an uppercase letter is preceded by an underscore, e.g. `Hello_World` becomes `hello__world`. ```c3 const String[] NAMES = { "helloWorld", "helloworld", "Hello_World", "hello_world", "HELLO WORLD", "HELLO WORLD", }; $for var $i = 0; $i < NAMES.len; $i++: var $name = NAMES[$i]; io::printfn("%s > p:%s c:%s s:%s cc:%s", $name, @str_pascalcase($name), @str_camelcase($name), @str_snakecase($name), @str_constantcase($name), ); $endfor ``` Output: ``` helloWorld > p:Helloworld c:Helloworld s:hello_world cc:HELLO_WORLD helloworld > p:Helloworld c:Helloworld s:helloworld cc:HELLOWORLD Hello_World > p:HelloWorld c:HelloWorld s:hello__world cc:HELLO__WORLD hello_world > p:HelloWorld c:HelloWorld s:hello_world cc:HELLO_WORLD HELLO WORLD > p:HelloWorld c:HelloWorld s:hello world cc:HELLO WORLD HELLO WORLD > p:HelloWorld c:HelloWorld s:hello world cc:HELLO WORLD ``` --- This should probably be a separate issue, but just putting it here since it's related. But a "human/nice" and "title" case could also be useful: - **@str_humanise**: Strips all non-alphanumeric characters and replaces them with a space - `hello__world` becomes `hello world` - **@str_titlecase**: Uppercase the first letter of each word - `hello world` becomes `Hello World`
5 条评论