is it possible to create new keyword like in Kotli...
# announcements
m
is it possible to create new keyword like in Kotlin for example I have a dyanmic string and want to map it to one of possible values .. so I think
when
is the right choice .. what I need to achieve something like this
Copy code
when ( lang ) {
equalIgnoreCase "AR" -> "Arabic"
equalIgnoreCase "EN" -> "English"
equalIgnoreCase "RU" -> "Russian"
}
m
Copy code
when {
  lang.equals("AR", true) -> "Arabic"
}
w
Not sure, but you could use an extension? Something like
Copy code
private fun String.expandName(): String =
            when {
                this.equals("AR", true) -> "Arabic"
                this.equals("EN", true) -> "English"
                this.equals("RU", true) -> "Russian"
                else -> this
            }

    @Test
    fun asas() {
        val value: String = "AR"
        assertEquals("Arabic", value.expandName())
    }
m
I used this ``infix fun String?.equalIgnoreCase(other: String) = this.equals(other, true) ``
g
Copy code
when(lang.toUpperCase()) {
  "AR" -> "Arabic"
}
☝️ 4
r
lang.toUpperCase(<http://Locale.US|Locale.US>)
unless you enjoy surprising behavior in other locales 🙂
g
Yes, or even better Locale.ROOT