Migrate stdlib, tests and samples to new case conversion api
This commit is contained in:
@@ -717,6 +717,7 @@ public inline fun String.toPattern(flags: Int = 0): java.util.regex.Pattern {
|
||||
@Deprecated("Use replaceFirstChar instead.", ReplaceWith("replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }", "java.util.Locale"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public actual fun String.capitalize(): String {
|
||||
@Suppress("DEPRECATION")
|
||||
return capitalize(Locale.getDefault())
|
||||
}
|
||||
|
||||
@@ -759,6 +760,7 @@ public fun String.capitalize(locale: Locale): String {
|
||||
@Deprecated("Use replaceFirstChar instead.", ReplaceWith("replaceFirstChar { it.lowercase(Locale.getDefault()) }", "java.util.Locale"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public actual fun String.decapitalize(): String {
|
||||
@Suppress("DEPRECATION")
|
||||
return if (isNotEmpty() && !this[0].isLowerCase()) substring(0, 1).toLowerCase() + substring(1) else this
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ class StringJVMTest {
|
||||
assertEquals("UTF-32BE", Charsets.UTF_32BE.name())
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@Test fun capitalize() {
|
||||
fun testCapitalize(expected: String, string: String) {
|
||||
assertEquals(expected, string.capitalize())
|
||||
@@ -90,6 +91,7 @@ class StringJVMTest {
|
||||
|
||||
@Test fun decapitalize() {
|
||||
fun testDecapitalize(expected: String, string: String) {
|
||||
@Suppress("DEPRECATION")
|
||||
assertEquals(expected, string.decapitalize())
|
||||
assertEquals(expected, string.replaceFirstChar { it.lowercase(Locale.getDefault()) })
|
||||
}
|
||||
@@ -98,6 +100,7 @@ class StringJVMTest {
|
||||
testDecapitalize("dzdzdz", "Dzdzdz")
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@Test fun capitalizeLocale() {
|
||||
fun testCapitalizeLocale(expected: String, string: String, locale: Locale) {
|
||||
assertEquals(expected, string.capitalize(locale))
|
||||
@@ -122,6 +125,7 @@ class StringJVMTest {
|
||||
|
||||
@Test fun decapitalizeLocale() {
|
||||
fun testDecapitalizeLocale(expected: String, string: String, locale: Locale) {
|
||||
@Suppress("DEPRECATION")
|
||||
assertEquals(expected, string.decapitalize(locale))
|
||||
assertEquals(expected, string.replaceFirstChar { it.lowercase(locale) })
|
||||
}
|
||||
|
||||
@@ -475,7 +475,7 @@ class Collections {
|
||||
fun distinctAndDistinctBy() {
|
||||
val list = listOf('a', 'A', 'b', 'B', 'A', 'a')
|
||||
assertPrints(list.distinct(), "[a, A, b, B]")
|
||||
assertPrints(list.distinctBy { it.toUpperCase() }, "[a, b]")
|
||||
assertPrints(list.distinctBy { it.uppercaseChar() }, "[a, b]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
@@ -523,7 +523,7 @@ class Collections {
|
||||
assertPrints(numbers.joinToString(prefix = "<", postfix = ">", separator = "•"), "<1•2•3•4•5•6>")
|
||||
|
||||
val chars = charArrayOf('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q')
|
||||
assertPrints(chars.joinToString(limit = 5, truncated = "...!") { it.toUpperCase().toString() }, "A, B, C, D, E, ...!")
|
||||
assertPrints(chars.joinToString(limit = 5, truncated = "...!") { it.uppercaseChar().toString() }, "A, B, C, D, E, ...!")
|
||||
}
|
||||
|
||||
@Sample
|
||||
|
||||
@@ -40,7 +40,7 @@ class Preconditions {
|
||||
val requiredParam: String? = params["required"]
|
||||
requireNotNull(requiredParam) { "Required value must be non-null" }
|
||||
// now requiredParam is smartcast to String so that it is unnecessary to use the safe call(?.)
|
||||
println(requiredParam.toUpperCase())
|
||||
println(requiredParam.uppercase())
|
||||
}
|
||||
|
||||
val params: MutableMap<String, String?> = mutableMapOf("required" to null)
|
||||
|
||||
@@ -6,12 +6,14 @@ import kotlin.test.*
|
||||
|
||||
class Strings {
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@Sample
|
||||
fun capitalize() {
|
||||
assertPrints("abcd".capitalize(), "Abcd")
|
||||
assertPrints("Abcd".capitalize(), "Abcd")
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@Sample
|
||||
fun decapitalize() {
|
||||
assertPrints("abcd".decapitalize(), "abcd")
|
||||
|
||||
@@ -82,7 +82,7 @@ class CharTest {
|
||||
|
||||
for (char in 'A'..'Z') {
|
||||
val digit = 10 + (char - 'A')
|
||||
val lower = char.toLowerCase()
|
||||
val lower = char.lowercaseChar()
|
||||
|
||||
for (radix in digit + 1..36) {
|
||||
testEquals(digit, char, radix)
|
||||
|
||||
@@ -290,6 +290,7 @@ class StringTest {
|
||||
|
||||
@Test fun capitalize() {
|
||||
fun testCapitalize(expected: String, string: String) {
|
||||
@Suppress("DEPRECATION")
|
||||
assertEquals(expected, string.capitalize())
|
||||
assertEquals(expected, string.replaceFirstChar { it.uppercase() })
|
||||
}
|
||||
@@ -301,6 +302,7 @@ class StringTest {
|
||||
|
||||
@Test fun decapitalize() {
|
||||
fun testDecapitalize(expected: String, string: String) {
|
||||
@Suppress("DEPRECATION")
|
||||
assertEquals(expected, string.decapitalize())
|
||||
assertEquals(expected, string.replaceFirstChar { it.lowercase() })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user