Joel Denke
02/28/2024, 9:57 AM"FooBarBaz".lowercase().capitalize()
When I use this I ofc get the known capitalize() being deprecated.
And it offers me to be replaced with:
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() })
My question is, why doesnt capitalize doing this under the hood instead and stop deprecating it? Feels wrong adding my own capitalize extension for this, which would interfere with this one.
I know I have capitalize(Locale) but I would like to avoid that variant because of Kotlin multiplatform reasons.Vampire
02/28/2024, 10:05 AMJoel Denke
02/28/2024, 10:08 AMJoel Denke
02/28/2024, 10:09 AMVampire
02/28/2024, 10:15 AMSam
02/28/2024, 10:16 AMJoel Denke
02/28/2024, 10:20 AM// in all targets
String.capitalize() -> String.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it }
String.decapitalize() -> String.replaceFirstChar { it.lowercase() }
// in JVM
String.capitalize() -> String.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it }
String.capitalize(locale) -> String.replaceFirstChar { if (it.isLowerCase()) it.titlecase(locale) else it }
String.decapitalize() -> String.replaceFirstChar { it.lowercase(Locale.getDefault()) }
String.decapitalize(locale) -> String.replaceFirstChar { it.lowercase(locale) }
Hmm yeah this make my head spin π So for non jVM variants you want to use without Locale even for titlecase?
Not entirely sure now when to use what.
When do I want to use this,
String.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it }
and when should I use:
capitalize(Locale.Root) or capitalize(Locale.getDefault())
?Joel Denke
02/28/2024, 10:21 AMSam
02/28/2024, 10:22 AMJoel Denke
02/28/2024, 10:22 AMJoel Denke
02/28/2024, 10:23 AMSam
02/28/2024, 10:25 AMSam
02/28/2024, 10:27 AMJoel Denke
02/28/2024, 10:27 AMString.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it }
?Joel Denke
02/28/2024, 10:29 AMJoel Denke
02/28/2024, 10:29 AMSam
02/28/2024, 10:30 AMJoel Denke
02/28/2024, 10:30 AMJoel Denke
02/28/2024, 10:31 AMJoel Denke
02/28/2024, 10:31 AMJoel Denke
02/28/2024, 10:32 AMJoel Denke
02/28/2024, 10:32 AMSam
02/28/2024, 10:38 AMSam
02/28/2024, 10:39 AMJoel Denke
02/28/2024, 10:57 AMKlitos Kyriacou
02/28/2024, 12:25 PMHonestly it's amazing how good a job the Unicode project has done at imposing some sort of structure on the insanity that is human communicationIt bugs me that today's ultra-modern computing carries a lot of baggage from the past, from even before computers existed. Unicode is one example of this. There are many ways to indicate a new line: LF, CR, CR+LF, NEL (U+0085), LS (U+2028) and probably a few others I haven't thought of. Qwerty keyboards are another example, with key positions optimized for mechanical typewriters. I wish we could just start afresh, but I know that's unfortunately unrealistic.