From 36aee8f2b471692f5891aea7549940df537b1081 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Mon, 19 Apr 2021 18:32:10 +0300 Subject: [PATCH] Fix String.replace doc --- libraries/stdlib/js/src/kotlin/text/stringsCode.kt | 11 +++++++++++ libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/libraries/stdlib/js/src/kotlin/text/stringsCode.kt b/libraries/stdlib/js/src/kotlin/text/stringsCode.kt index 8575b85d35c..44e02eba577 100644 --- a/libraries/stdlib/js/src/kotlin/text/stringsCode.kt +++ b/libraries/stdlib/js/src/kotlin/text/stringsCode.kt @@ -131,10 +131,21 @@ public actual fun CharSequence.repeat(n: Int): String { } } +/** + * Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string + * with the specified [newValue] string. + * + * @sample samples.text.Strings.replace + */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String = nativeReplace(RegExp(Regex.escape(oldValue), if (ignoreCase) "gui" else "gu"), Regex.escapeReplacement(newValue)) +/** + * Returns a new string with all occurrences of [oldChar] replaced with [newChar]. + * + * @sample samples.text.Strings.replace + */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String = nativeReplace(RegExp(Regex.escape(oldChar.toString()), if (ignoreCase) "gui" else "gu"), newChar.toString()) diff --git a/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt index 3245ad2f35d..72cb0b13c5a 100644 --- a/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt @@ -58,6 +58,8 @@ public actual fun String?.equals(other: String?, ignoreCase: Boolean = false): B /** * Returns a new string with all occurrences of [oldChar] replaced with [newChar]. + * + * @sample samples.text.Strings.replace */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String { @@ -74,6 +76,8 @@ public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boole /** * Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string * with the specified [newValue] string. + * + * @sample samples.text.Strings.replace */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String {