igor.wojda
07/05/2019, 1:31 PM"apiBaseUrl" -> "api_base_url"
pardom
07/05/2019, 1:34 PMigor.wojda
07/05/2019, 1:35 PMRobert Jaros
07/05/2019, 1:35 PMpardom
07/05/2019, 1:35 PMkarelpeeters
07/05/2019, 1:38 PMstr.split("(?=[A-Z])".toRegex()).joinToString("_") { it.toLowerCase() }
pardom
07/05/2019, 1:40 PMfun String.pascalToSnakeCase() = map { char ->
if (char.isUpperCase()) "_${char.toLowerCase()}" else char
}.joinToString("")
Shawn
07/05/2019, 1:42 PM"camelCase".split(Regex("(?=[A-Z])")).joinToString(separator = "_", transform = String::toLowerCase)
Jonathan Mew
07/05/2019, 1:43 PMval capitalRegex = "([A-Z])".toRegex()
fun String.snakify() = this.replace(capitalRegex) {
'_' + it.value.toLowerCase()
}.trim('_')
@Test
fun `test pascalToSnake`() {
"".snakify() shouldBe ""
"abc".snakify() shouldBe "abc"
"aBc".snakify() shouldBe "a_bc"
"someThingElse".snakify() shouldBe "some_thing_else"
}
karelpeeters
07/05/2019, 1:47 PMstr.split(Regex("(?=[A-Z])")).joinToString("_", String::toLowerCase)
compiles with the new type inference but not the old one, that's great!igor.wojda
07/05/2019, 1:56 PMstr.split(Regex("(?=[A-Z])")).joinToString("_") { it.toLowerCase() }
old/new type inference
? What is the state - is it currently released, experimental?karelpeeters
07/05/2019, 2:01 PM