Improve docs for substring/subsequence.

This commit is contained in:
Ilya Gorbunov
2016-02-18 15:29:38 +03:00
parent c946d283ff
commit 77f148bec6
3 changed files with 15 additions and 8 deletions
+3 -2
View File
@@ -26,12 +26,13 @@ public interface CharSequence {
public val length: Int public val length: Int
/** /**
* Returns the character at the specified [index] in the sequence. * Returns the character at the specified [index] in this character sequence.
*/ */
public operator fun get(index: Int): Char public operator fun get(index: Int): Char
/** /**
* Returns a subsequence of this sequence. * Returns a new character sequence that is a subsequence of this character sequence,
* starting at the specified [startIndex] and ending right before the specified [endIndex].
* *
* @param startIndex the start index (inclusive). * @param startIndex the start index (inclusive).
* @param endIndex the end index (exclusive). * @param endIndex the end index (exclusive).
+7 -4
View File
@@ -277,23 +277,26 @@ public fun CharSequence.hasSurrogatePairAt(index: Int): Boolean {
} }
/** /**
* Returns a substring specified by the given [range]. * Returns a substring specified by the given [range] of indices.
*/ */
public fun String.substring(range: IntRange): String = substring(range.start, range.endInclusive + 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]. * Returns a subsequence of this char sequence specified by the given [range] of indices.
*/ */
public fun CharSequence.subSequence(range: IntRange): CharSequence = subSequence(range.start, range.endInclusive + 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 [startIndex] and [endIndex] indices. * Returns a substring of chars from a range of this char sequence starting at the [startIndex] and ending right before the [endIndex].
*
* @param startIndex the start index (inclusive).
* @param endIndex the end index (exclusive). If not specified, the length of the char sequence is used.
*/ */
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public inline fun CharSequence.substring(startIndex: Int, endIndex: Int = length): String = subSequence(startIndex, endIndex).toString() public inline fun CharSequence.substring(startIndex: Int, endIndex: Int = length): String = subSequence(startIndex, endIndex).toString()
/** /**
* Returns a substring of chars from a [range] of this char sequence. * Returns a substring of chars at indices from the specified [range] of this char sequence.
*/ */
public fun CharSequence.substring(range: IntRange): String = subSequence(range.start, range.endInclusive + 1).toString() public fun CharSequence.substring(range: IntRange): String = subSequence(range.start, range.endInclusive + 1).toString()
@@ -156,13 +156,16 @@ public fun CharSequence.split(regex: Pattern, limit: Int = 0): List<String>
} }
/** /**
* Returns a substring of this string starting with the specified index. * Returns a substring of this string that starts at the specified [startIndex] and continues to the end of the string.
*/ */
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public inline fun String.substring(startIndex: Int): String = (this as java.lang.String).substring(startIndex) public inline fun String.substring(startIndex: Int): String = (this as java.lang.String).substring(startIndex)
/** /**
* Returns the substring of this string starting and ending at the specified indices. * Returns the substring of this string starting at the [startIndex] and ending right before the [endIndex].
*
* @param startIndex the start index (inclusive).
* @param endIndex the end index (exclusive).
*/ */
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public inline fun String.substring(startIndex: Int, endIndex: Int): String = (this as java.lang.String).substring(startIndex, endIndex) public inline fun String.substring(startIndex: Int, endIndex: Int): String = (this as java.lang.String).substring(startIndex, endIndex)