diff --git a/core/builtins/native/kotlin/CharSequence.kt b/core/builtins/native/kotlin/CharSequence.kt index d7040f7950e..32f3ac1ac79 100644 --- a/core/builtins/native/kotlin/CharSequence.kt +++ b/core/builtins/native/kotlin/CharSequence.kt @@ -26,12 +26,13 @@ public interface CharSequence { 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 /** - * 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 endIndex the end index (exclusive). diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index 84bce83f29b..a31035ceaa0 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -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) /** - * 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) /** - * 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 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() diff --git a/libraries/stdlib/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/src/kotlin/text/StringsJVM.kt index 9ef02aa110f..e4b2809a525 100644 --- a/libraries/stdlib/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringsJVM.kt @@ -156,13 +156,16 @@ public fun CharSequence.split(regex: Pattern, limit: Int = 0): List } /** - * 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 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 public inline fun String.substring(startIndex: Int, endIndex: Int): String = (this as java.lang.String).substring(startIndex, endIndex)