From 838109c302afa71ac8b48beb9dd26d81d15e9cfa Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Sat, 14 Nov 2015 06:01:15 +0300 Subject: [PATCH] StdLib cleanup, deprecated symbol usage: replace end with endInclusive --- libraries/stdlib/src/generated/_Arrays.kt | 36 +++++++++---------- .../stdlib/src/generated/_Collections.kt | 2 +- libraries/stdlib/src/kotlin/text/Strings.kt | 14 ++++---- .../stdlib/src/kotlin/text/regex/RegexJVM.kt | 2 +- .../stdlib/test/collections/CollectionTest.kt | 2 +- .../src/templates/Filtering.kt | 8 ++--- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index 4cf39d82425..218b64512a4 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -3428,7 +3428,7 @@ public inline fun > ShortArray.filterTo(destinat */ public fun Array.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() } /** @@ -3436,7 +3436,7 @@ public fun Array.slice(indices: IntRange): List { */ public fun BooleanArray.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() } /** @@ -3444,7 +3444,7 @@ public fun BooleanArray.slice(indices: IntRange): List { */ public fun ByteArray.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() } /** @@ -3452,7 +3452,7 @@ public fun ByteArray.slice(indices: IntRange): List { */ public fun CharArray.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() } /** @@ -3460,7 +3460,7 @@ public fun CharArray.slice(indices: IntRange): List { */ public fun DoubleArray.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() } /** @@ -3468,7 +3468,7 @@ public fun DoubleArray.slice(indices: IntRange): List { */ public fun FloatArray.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() } /** @@ -3476,7 +3476,7 @@ public fun FloatArray.slice(indices: IntRange): List { */ public fun IntArray.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() } /** @@ -3484,7 +3484,7 @@ public fun IntArray.slice(indices: IntRange): List { */ public fun LongArray.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() } /** @@ -3492,7 +3492,7 @@ public fun LongArray.slice(indices: IntRange): List { */ public fun ShortArray.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() } /** @@ -3725,7 +3725,7 @@ public fun ShortArray.sliceArray(indices: Collection): ShortArray { */ public fun Array.sliceArray(indices: IntRange): Array { if (indices.isEmpty()) return copyOfRange(0, 0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) } /** @@ -3733,7 +3733,7 @@ public fun Array.sliceArray(indices: IntRange): Array { */ public fun BooleanArray.sliceArray(indices: IntRange): BooleanArray { if (indices.isEmpty()) return BooleanArray(0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) } /** @@ -3741,7 +3741,7 @@ public fun BooleanArray.sliceArray(indices: IntRange): BooleanArray { */ public fun ByteArray.sliceArray(indices: IntRange): ByteArray { if (indices.isEmpty()) return ByteArray(0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) } /** @@ -3749,7 +3749,7 @@ public fun ByteArray.sliceArray(indices: IntRange): ByteArray { */ public fun CharArray.sliceArray(indices: IntRange): CharArray { if (indices.isEmpty()) return CharArray(0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) } /** @@ -3757,7 +3757,7 @@ public fun CharArray.sliceArray(indices: IntRange): CharArray { */ public fun DoubleArray.sliceArray(indices: IntRange): DoubleArray { if (indices.isEmpty()) return DoubleArray(0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) } /** @@ -3765,7 +3765,7 @@ public fun DoubleArray.sliceArray(indices: IntRange): DoubleArray { */ public fun FloatArray.sliceArray(indices: IntRange): FloatArray { if (indices.isEmpty()) return FloatArray(0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) } /** @@ -3773,7 +3773,7 @@ public fun FloatArray.sliceArray(indices: IntRange): FloatArray { */ public fun IntArray.sliceArray(indices: IntRange): IntArray { if (indices.isEmpty()) return IntArray(0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) } /** @@ -3781,7 +3781,7 @@ public fun IntArray.sliceArray(indices: IntRange): IntArray { */ public fun LongArray.sliceArray(indices: IntRange): LongArray { if (indices.isEmpty()) return LongArray(0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) } /** @@ -3789,7 +3789,7 @@ public fun LongArray.sliceArray(indices: IntRange): LongArray { */ public fun ShortArray.sliceArray(indices: IntRange): ShortArray { if (indices.isEmpty()) return ShortArray(0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) } /** diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index dab84510ec0..5affd445a41 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -734,7 +734,7 @@ public inline fun > Iterable.filterTo(destinat */ public fun List.slice(indices: IntRange): List { if (indices.isEmpty()) return listOf() - return this.subList(indices.start, indices.end + 1).toList() + return this.subList(indices.start, indices.endInclusive + 1).toList() } /** diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index 950954842cb..76e81e7f184 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -279,12 +279,12 @@ public fun CharSequence.hasSurrogatePairAt(index: Int): Boolean { /** * Returns a substring specified by the given [range]. */ -public fun String.substring(range: IntRange): String = substring(range.start, range.end + 1) +public fun String.substring(range: IntRange): String = substring(range.start, range.endInclusive + 1) /** * Returns a subsequence of this char sequence specified by the given [range]. */ -public fun CharSequence.subSequence(range: IntRange): CharSequence = subSequence(range.start, range.end + 1) +public fun CharSequence.subSequence(range: IntRange): CharSequence = subSequence(range.start, range.endInclusive + 1) /** * Returns a substring of chars from a range of this char sequence specified by [start] and [end] indices. @@ -294,7 +294,7 @@ public fun CharSequence.substring(start: Int, end: Int = length): String = subSe /** * Returns a substring of chars from a [range] of this char sequence. */ -public fun CharSequence.substring(range: IntRange): String = subSequence(range.start, range.end + 1).toString() +public fun CharSequence.substring(range: IntRange): String = subSequence(range.start, range.endInclusive + 1).toString() /** * Returns a substring before the first occurrence of [delimiter]. @@ -399,7 +399,7 @@ public fun String.replaceRange(firstIndex: Int, lastIndex: Int, replacement: Cha * The end index of the [range] is included in the part to be replaced. */ public fun CharSequence.replaceRange(range: IntRange, replacement: CharSequence): CharSequence - = replaceRange(range.start, range.end + 1, replacement) + = replaceRange(range.start, range.endInclusive + 1, replacement) /** * Replace the part of string at the given [range] with the [replacement] string. @@ -407,7 +407,7 @@ public fun CharSequence.replaceRange(range: IntRange, replacement: CharSequence) * The end index of the [range] is included in the part to be replaced. */ public fun String.replaceRange(range: IntRange, replacement: CharSequence): String - = replaceRange(range.start, range.end + 1, replacement) + = replaceRange(range.start, range.endInclusive + 1, replacement) /** * Returns a char sequence with content of this char sequence where its part at the given range is removed. @@ -445,14 +445,14 @@ public fun String.removeRange(firstIndex: Int, lastIndex: Int): String * * The end index of the [range] is included in the removed part. */ -public fun CharSequence.removeRange(range: IntRange): CharSequence = removeRange(range.start, range.end + 1) +public fun CharSequence.removeRange(range: IntRange): CharSequence = removeRange(range.start, range.endInclusive + 1) /** * Removes the part of a string at the given [range]. * * The end index of the [range] is included in the removed part. */ -public fun String.removeRange(range: IntRange): String = removeRange(range.start, range.end + 1) +public fun String.removeRange(range: IntRange): String = removeRange(range.start, range.endInclusive + 1) /** * If this char sequence starts with the given [prefix], returns a new char sequence diff --git a/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt b/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt index 97f5679c13d..a179d69af4e 100644 --- a/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt +++ b/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt @@ -168,7 +168,7 @@ public class Regex internal constructor(private val nativePattern: Pattern) { val foundMatch = match!! sb.append(input, lastStart, foundMatch.range.start) sb.append(transform(foundMatch)) - lastStart = foundMatch.range.end + 1 + lastStart = foundMatch.range.endInclusive + 1 match = foundMatch.next() } while (lastStart < length && match != null) diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index 53e7b99ee55..3084c67392b 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -462,7 +462,7 @@ class CollectionTest { val data = listOf("foo", "bar") val indices = data.indices assertEquals(0, indices.start) - assertEquals(1, indices.end) + assertEquals(1, indices.endInclusive) assertEquals(0..data.size - 1, indices) } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt index 04fae2f0982..ddc5530254c 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt @@ -567,13 +567,13 @@ fun filtering(): List { body(Lists) { """ if (indices.isEmpty()) return listOf() - return this.subList(indices.start, indices.end + 1).toList() + return this.subList(indices.start, indices.endInclusive + 1).toList() """ } body(ArraysOfPrimitives, ArraysOfObjects) { """ if (indices.isEmpty()) return listOf() - return copyOfRange(indices.start, indices.end + 1).asList() + return copyOfRange(indices.start, indices.endInclusive + 1).asList() """ } @@ -620,13 +620,13 @@ fun filtering(): List { body(ArraysOfObjects) { """ if (indices.isEmpty()) return copyOfRange(0, 0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) """ } body(ArraysOfPrimitives) { """ if (indices.isEmpty()) return SELF(0) - return copyOfRange(indices.start, indices.end + 1) + return copyOfRange(indices.start, indices.endInclusive + 1) """ } }