CollectionsKt.windowed throws IllegalArgumentException

This commit is contained in:
Abduqodiri Qurbonzoda
2019-09-16 20:34:13 +03:00
parent a7b984bcbf
commit d66f07a84e
6 changed files with 51 additions and 8 deletions
@@ -1374,7 +1374,8 @@ public fun CharSequence.windowed(size: Int, step: Int = 1, partialWindows: Boole
public fun <R> CharSequence.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false, transform: (CharSequence) -> R): List<R> {
checkWindowSizeStep(size, step)
val thisSize = this.length
val result = ArrayList<R>((thisSize + step - 1) / step)
val resultCapacity = thisSize / step + if (thisSize % step == 0) 0 else 1
val result = ArrayList<R>(resultCapacity)
var index = 0
while (index < thisSize) {
val end = index + size