diff --git a/libraries/stdlib/common/src/kotlin/TextH.kt b/libraries/stdlib/common/src/kotlin/TextH.kt index c7d8ffc0ab4..5a20077168d 100644 --- a/libraries/stdlib/common/src/kotlin/TextH.kt +++ b/libraries/stdlib/common/src/kotlin/TextH.kt @@ -111,8 +111,18 @@ internal expect fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int public expect fun String.substring(startIndex: Int): String public expect fun String.substring(startIndex: Int, endIndex: Int): String - +/** + * Returns a copy of this string converted to upper case using the rules of the default locale. + * + * @sample samples.text.Strings.toUpperCase + */ public expect fun String.toUpperCase(): String + +/** + * Returns a copy of this string converted to lower case using the rules of the default locale. + * + * @sample samples.text.Strings.toLowerCase + */ public expect fun String.toLowerCase(): String public expect fun String.capitalize(): String public expect fun String.decapitalize(): String diff --git a/libraries/stdlib/js/src/kotlin/string.kt b/libraries/stdlib/js/src/kotlin/string.kt index 3da9cda83ea..bd184ba1840 100644 --- a/libraries/stdlib/js/src/kotlin/string.kt +++ b/libraries/stdlib/js/src/kotlin/string.kt @@ -24,10 +24,19 @@ public actual fun String(chars: CharArray, offset: Int, length: Int): String { return String(chars.copyOfRange(offset, offset + length)) } - +/** + * Returns a copy of this string converted to upper case using the rules of the default locale. + * + * @sample samples.text.Strings.toUpperCase + */ @kotlin.internal.InlineOnly public actual inline fun String.toUpperCase(): String = asDynamic().toUpperCase() +/** + * Returns a copy of this string converted to lower case using the rules of the default locale. + * + * @sample samples.text.Strings.toLowerCase + */ @kotlin.internal.InlineOnly public actual inline fun String.toLowerCase(): String = asDynamic().toLowerCase() diff --git a/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt index ba001a0e4ca..cf69a4c264b 100644 --- a/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt @@ -94,12 +94,16 @@ public actual fun String.replaceFirst(oldValue: String, newValue: String, ignore /** * Returns a copy of this string converted to upper case using the rules of the default locale. + * + * @sample samples.text.Strings.toUpperCase */ @kotlin.internal.InlineOnly public actual inline fun String.toUpperCase(): String = (this as java.lang.String).toUpperCase() /** * Returns a copy of this string converted to lower case using the rules of the default locale. + * + * @sample samples.text.Strings.toLowerCase */ @kotlin.internal.InlineOnly public actual inline fun String.toLowerCase(): String = (this as java.lang.String).toLowerCase() diff --git a/libraries/stdlib/samples/test/samples/text/strings.kt b/libraries/stdlib/samples/test/samples/text/strings.kt index 79675c04e93..77d9f708d3d 100644 --- a/libraries/stdlib/samples/test/samples/text/strings.kt +++ b/libraries/stdlib/samples/test/samples/text/strings.kt @@ -94,4 +94,14 @@ class Strings { assertPrints(byteArray.toString(charset), "Hello") } + @Sample + fun toLowerCase() { + assertPrints("Iced frappé!".toLowerCase(), "iced frappé!") + } + + @Sample + fun toUpperCase() { + assertPrints("Iced frappé!".toUpperCase(), "ICED FRAPPÉ!") + } + }