Specific wording in exception message for String methods.
This commit is contained in:
@@ -292,7 +292,7 @@ public fun <T> List<T>.dropLast(n: Int): List<T> {
|
|||||||
* Returns a string with the last [n] characters removed.
|
* Returns a string with the last [n] characters removed.
|
||||||
*/
|
*/
|
||||||
public fun String.dropLast(n: Int): String {
|
public fun String.dropLast(n: Int): String {
|
||||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||||
return take((length() - n).coerceAtLeast(0))
|
return take((length() - n).coerceAtLeast(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1384,7 +1384,7 @@ public fun <T> Stream<T>.take(n: Int): Stream<T> {
|
|||||||
* Returns a string containing the first [n] characters from this string, or the entire string if this string is shorter.
|
* Returns a string containing the first [n] characters from this string, or the entire string if this string is shorter.
|
||||||
*/
|
*/
|
||||||
public fun String.take(n: Int): String {
|
public fun String.take(n: Int): String {
|
||||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||||
return substring(0, Math.min(n, length()))
|
return substring(0, Math.min(n, length()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1532,7 +1532,7 @@ public fun <T> List<T>.takeLast(n: Int): List<T> {
|
|||||||
* Returns a string containing the last [n] characters from this string, or the entire string if this string is shorter.
|
* Returns a string containing the last [n] characters from this string, or the entire string if this string is shorter.
|
||||||
*/
|
*/
|
||||||
public fun String.takeLast(n: Int): String {
|
public fun String.takeLast(n: Int): String {
|
||||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||||
val length = length()
|
val length = length()
|
||||||
return substring(length - Math.min(n, length), length)
|
return substring(length - Math.min(n, length), length)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ fun filtering(): List<GenericFunction> {
|
|||||||
doc(Strings) { "Returns a string containing the first [n] characters from this string, or the entire string if this string is shorter."}
|
doc(Strings) { "Returns a string containing the first [n] characters from this string, or the entire string if this string is shorter."}
|
||||||
body(Strings) {
|
body(Strings) {
|
||||||
"""
|
"""
|
||||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||||
return substring(0, Math.min(n, length()))
|
return substring(0, Math.min(n, length()))
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ fun filtering(): List<GenericFunction> {
|
|||||||
returns("String", Strings)
|
returns("String", Strings)
|
||||||
body(Strings) {
|
body(Strings) {
|
||||||
"""
|
"""
|
||||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||||
return take((length() - n).coerceAtLeast(0))
|
return take((length() - n).coerceAtLeast(0))
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ fun filtering(): List<GenericFunction> {
|
|||||||
doc(Strings) { "Returns a string containing the last [n] characters from this string, or the entire string if this string is shorter."}
|
doc(Strings) { "Returns a string containing the last [n] characters from this string, or the entire string if this string is shorter."}
|
||||||
body(Strings) {
|
body(Strings) {
|
||||||
"""
|
"""
|
||||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||||
val length = length()
|
val length = length()
|
||||||
return substring(length - Math.min(n, length), length)
|
return substring(length - Math.min(n, length), length)
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user