Remix.run Logo
jillesvangurp 7 hours ago

Interesting one. That and and relying on system character encodings is a source of subtle bugs. I've been bitten by that many times with e.g. XML parsing in the past. Modern Kotlin thankfully has very few (if any) places left where this can happen. Kotlin has parameters with default values. So anything that relies on a character encoding usually has a parameter of encoding set to UTF-8.

The bug here was the default Java implementation that Kotlin uses on JVM. On kotlin-js both toLowerCase() and lowercase() do exactly the same thing. Also, the deprecation mechanism in Kotlin is kind of cool. The deprecated implementation is still there and you could use it with a compiler flag to disable the error.

  @Deprecated("Use lowercase() instead.", ReplaceWith("lowercase(Locale.getDefault())", "java.util.Locale"))
  @DeprecatedSinceKotlin(warningSince = "1.5", errorSince = "2.1")
  @kotlin.internal.InlineOnly
  public actual inline fun String.toLowerCase(): String = (this as java.lang.String).toLowerCase()

  /**
   * Returns a copy of this string converted to lower case using Unicode mapping rules of the invariant locale.
   *
   * This function supports one-to-many and many-to-one character mapping,
   * thus the length of the returned string can be different from the length of the original string.
   *
   * @sample samples.text.Strings.lowercase
   */
  @SinceKotlin("1.5")
  @kotlin.internal.InlineOnly
  public actual inline fun String.lowercase(): String = (this as java.lang.String).toLowerCase(Locale.ROOT)