vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.5k stars 2.15k forks source link

builtin: fix `snake_to_camel` when passing a `SCREAMING_SNAKE_CASE` string #21722

Closed ttytm closed 4 days ago

ttytm commented 4 days ago

Ref.: https://github.com/vlang/v/pull/21691#issuecomment-2184905360

ttytm commented 4 days ago

Related to this and potential simplifications, would a .is_upper / .is_lower method for chars make it as a builtin?

spytheman commented 4 days ago

We have u8.is_capital/0 already, which does c >= A && c <= Z, but I could not find a separate implementation for u8.is_lower/0 .

kbkpbot commented 3 days ago

Bug in code:

assert '_ISspace'.camel_to_snake() == '_i_sspace' but got '__sspace' lost the first char I

ttytm commented 3 days ago

Good catch. Thanks a lot for the test cases @kbkpbot

spytheman commented 3 days ago

Why assert '_ISspace'.camel_to_snake() == '_i_sspace' ?

I would have expected _ISspace to become _is_space 🤔 .

ttytm commented 3 days ago

Good question. From the short research I did before, the initial implementation (without extracting handling of the first characters to reduce the load in the loop) was very similar to the implementation at https://github.com/iancoleman/strcase. So the initial impl and Go's strcase gives _i_sspace :thinking: .