From c2f6a2cb9666856a2e3435ab2489ef999ca0ad50 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Fri, 5 Mar 2021 03:48:30 +0300 Subject: [PATCH] [K/N] Commonize and generalize JVM-only String.contentEquals #KT-42840 --- .../src/main/kotlin/kotlin/text/Strings.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/Strings.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/Strings.kt index c3ac426e23e..8f69adf4e19 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/Strings.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/Strings.kt @@ -426,6 +426,30 @@ public actual fun String.compareTo(other: String, ignoreCase: Boolean): Int { else compareToIgnoreCase(this, other) } +/** + * Returns `true` if the contents of this char sequence are equal to the contents of the specified [other], + * i.e. both char sequences contain the same number of the same characters in the same order. + * + * @sample samples.text.Strings.contentEquals + */ +@SinceKotlin("1.5") +public actual infix fun CharSequence?.contentEquals(other: CharSequence?): Boolean = contentEqualsImpl(other) + +/** + * Returns `true` if the contents of this char sequence are equal to the contents of the specified [other], optionally ignoring case difference. + * + * @param ignoreCase `true` to ignore character case when comparing contents. + * + * @sample samples.text.Strings.contentEquals + */ +@SinceKotlin("1.5") +public actual fun CharSequence?.contentEquals(other: CharSequence?, ignoreCase: Boolean): Boolean { + return if (ignoreCase) + this.contentEqualsIgnoreCaseImpl(other) + else + this.contentEqualsImpl(other) +} + @SharedImmutable private val STRING_CASE_INSENSITIVE_ORDER = Comparator { a, b -> a.compareTo(b, ignoreCase = true) }