KT-20357: Add samples for commonPrefixWith and commonSuffixWith
This commit is contained in:
@@ -176,4 +176,19 @@ class Strings {
|
|||||||
val sameString = nonBlank.ifBlank { "def" }
|
val sameString = nonBlank.ifBlank { "def" }
|
||||||
assertTrue(nonBlank === sameString)
|
assertTrue(nonBlank === sameString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sample
|
||||||
|
fun commonPrefixWith() {
|
||||||
|
assertPrints("Hot_Coffee".commonPrefixWith("Hot_cocoa"), "Hot_")
|
||||||
|
assertPrints("Hot_Coffee".commonPrefixWith("Hot_cocoa", true), "Hot_Co")
|
||||||
|
assertPrints("Hot_Coffee".commonPrefixWith("Iced_Coffee"), "")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Sample
|
||||||
|
fun commonSuffixWith() {
|
||||||
|
assertPrints("Hot_Tea".commonSuffixWith("iced_tea"), "ea")
|
||||||
|
assertPrints("Hot_Tea".commonSuffixWith("iced_tea", true), "_Tea")
|
||||||
|
assertPrints("Hot_Tea".commonSuffixWith("Hot_Coffee"), "")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -772,6 +772,7 @@ public fun CharSequence.endsWith(suffix: CharSequence, ignoreCase: Boolean = fal
|
|||||||
* If this and [other] have no common prefix, returns the empty string.
|
* If this and [other] have no common prefix, returns the empty string.
|
||||||
|
|
||||||
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
||||||
|
* @sample samples.text.Strings.commonPrefixWith
|
||||||
*/
|
*/
|
||||||
public fun CharSequence.commonPrefixWith(other: CharSequence, ignoreCase: Boolean = false): String {
|
public fun CharSequence.commonPrefixWith(other: CharSequence, ignoreCase: Boolean = false): String {
|
||||||
val shortestLength = minOf(this.length, other.length)
|
val shortestLength = minOf(this.length, other.length)
|
||||||
@@ -792,6 +793,7 @@ public fun CharSequence.commonPrefixWith(other: CharSequence, ignoreCase: Boolea
|
|||||||
* If this and [other] have no common suffix, returns the empty string.
|
* If this and [other] have no common suffix, returns the empty string.
|
||||||
|
|
||||||
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
||||||
|
* @sample samples.text.Strings.commonSuffixWith
|
||||||
*/
|
*/
|
||||||
public fun CharSequence.commonSuffixWith(other: CharSequence, ignoreCase: Boolean = false): String {
|
public fun CharSequence.commonSuffixWith(other: CharSequence, ignoreCase: Boolean = false): String {
|
||||||
val thisLength = this.length
|
val thisLength = this.length
|
||||||
|
|||||||
Reference in New Issue
Block a user