Moved JVM-specific String.repeat method to StringsJVM.kt
This commit is contained in:
@@ -63,18 +63,3 @@ public inline fun String.count(predicate: (Char) -> Boolean): Int {
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a given string n times.
|
||||
* When n < 0, IllegalArgumentException is thrown.
|
||||
* @includeFunctionBody ../../test/StringTest.kt repeat
|
||||
*/
|
||||
public inline fun String.repeat(n: Int): String {
|
||||
require(n >= 0, { "Cannot repeat string $n times" })
|
||||
|
||||
var sb = StringBuilder()
|
||||
for (i in 1..n) {
|
||||
sb.append(this)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
@@ -192,3 +192,17 @@ public inline fun String.decapitalize(): String {
|
||||
return if (notEmpty() && charAt(0).isUpperCase()) substring(0, 1).toLowerCase() + substring(1) else this
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a given string n times.
|
||||
* When n < 0, IllegalArgumentException is thrown.
|
||||
* @includeFunctionBody ../../test/StringTest.kt repeat
|
||||
*/
|
||||
public inline fun String.repeat(n: Int): String {
|
||||
require(n >= 0, { "Cannot repeat string $n times" })
|
||||
|
||||
var sb = StringBuilder()
|
||||
for (i in 1..n) {
|
||||
sb.append(this)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
@@ -65,5 +65,11 @@ class StringJVMTest {
|
||||
assertEquals(s, list[0])
|
||||
}
|
||||
|
||||
|
||||
test fun repeat() {
|
||||
fails{ "foo".repeat(-1) }
|
||||
assertEquals("", "foo".repeat(0))
|
||||
assertEquals("foo", "foo".repeat(1))
|
||||
assertEquals("foofoo", "foo".repeat(2))
|
||||
assertEquals("foofoofoo", "foo".repeat(3))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,4 @@ class StringTest {
|
||||
assertEquals("uRL", "URL".decapitalize())
|
||||
}
|
||||
|
||||
test fun repeat() {
|
||||
fails{ "foo".repeat(-1) }
|
||||
assertEquals("", "foo".repeat(0))
|
||||
assertEquals("foo", "foo".repeat(1))
|
||||
assertEquals("foofoo", "foo".repeat(2))
|
||||
assertEquals("foofoofoo", "foo".repeat(3))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user