Fix range inclusivity in String.indices

This commit is contained in:
Alexander Udalov
2014-06-16 01:45:07 +04:00
parent 976d5df1eb
commit 607694c3c9
2 changed files with 9 additions and 3 deletions
+3 -3
View File
@@ -50,8 +50,8 @@ public val CharSequence.size: Int
public val String.size: Int
get() = length()
public val String.indices : IntRange
get() = 0..size
public val String.indices: IntRange
get() = 0..length() - 1
/**
* Returns a subsequence specified by given set of indices.
@@ -94,4 +94,4 @@ public fun Array<String>.join(separator: String = ", ", prefix: String = "", pos
*/
public fun Stream<String>.join(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
return joinToString(separator, prefix, postfix, limit, truncated)
}
}
+6
View File
@@ -62,4 +62,10 @@ class StringTest {
assertEquals("4321", "1234".reverse())
assertEquals("", "".reverse())
}
test fun indices() {
assertEquals(0..4, "abcde".indices)
assertEquals(0..0, "a".indices)
assertEquals(IntRange.EMPTY, "".indices)
}
}