Promote String <-> utf8 and CharArray conversions to stable

This commit is contained in:
Abduqodiri Qurbonzoda
2020-05-30 02:31:22 +03:00
parent f6a739bbc5
commit aba97033f0
6 changed files with 52 additions and 52 deletions
+16 -16
View File
@@ -92,8 +92,8 @@ public expect fun String(chars: CharArray, offset: Int, length: Int): String
/** /**
* Concatenates characters in this [CharArray] into a String. * Concatenates characters in this [CharArray] into a String.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public expect fun CharArray.concatToString(): String public expect fun CharArray.concatToString(): String
/** /**
@@ -105,15 +105,15 @@ public expect fun CharArray.concatToString(): String
* @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the size of this array. * @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public expect fun CharArray.concatToString(startIndex: Int = 0, endIndex: Int = this.size): String public expect fun CharArray.concatToString(startIndex: Int = 0, endIndex: Int = this.size): String
/** /**
* Returns a [CharArray] containing characters of this string. * Returns a [CharArray] containing characters of this string.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public expect fun String.toCharArray(): CharArray public expect fun String.toCharArray(): CharArray
/** /**
@@ -125,8 +125,8 @@ public expect fun String.toCharArray(): CharArray
* @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the length of this string. * @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the length of this string.
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public expect fun String.toCharArray(startIndex: Int = 0, endIndex: Int = this.length): CharArray public expect fun String.toCharArray(startIndex: Int = 0, endIndex: Int = this.length): CharArray
/** /**
@@ -134,8 +134,8 @@ public expect fun String.toCharArray(startIndex: Int = 0, endIndex: Int = this.l
* *
* Malformed byte sequences are replaced by the replacement char `\uFFFD`. * Malformed byte sequences are replaced by the replacement char `\uFFFD`.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public expect fun ByteArray.decodeToString(): String public expect fun ByteArray.decodeToString(): String
/** /**
@@ -149,8 +149,8 @@ public expect fun ByteArray.decodeToString(): String
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
* @throws CharacterCodingException if the byte array contains malformed UTF-8 byte sequence and [throwOnInvalidSequence] is true. * @throws CharacterCodingException if the byte array contains malformed UTF-8 byte sequence and [throwOnInvalidSequence] is true.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public expect fun ByteArray.decodeToString( public expect fun ByteArray.decodeToString(
startIndex: Int = 0, startIndex: Int = 0,
endIndex: Int = this.size, endIndex: Int = this.size,
@@ -162,8 +162,8 @@ public expect fun ByteArray.decodeToString(
* *
* Any malformed char sequence is replaced by the replacement byte sequence. * Any malformed char sequence is replaced by the replacement byte sequence.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public expect fun String.encodeToByteArray(): ByteArray public expect fun String.encodeToByteArray(): ByteArray
/** /**
@@ -177,8 +177,8 @@ public expect fun String.encodeToByteArray(): ByteArray
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
* @throws CharacterCodingException if this string contains malformed char sequence and [throwOnInvalidSequence] is true. * @throws CharacterCodingException if this string contains malformed char sequence and [throwOnInvalidSequence] is true.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public expect fun String.encodeToByteArray( public expect fun String.encodeToByteArray(
startIndex: Int = 0, startIndex: Int = 0,
endIndex: Int = this.length, endIndex: Int = this.length,
@@ -8,8 +8,8 @@ package kotlin.text
/** /**
* The exception thrown when a character encoding or decoding error occurs. * The exception thrown when a character encoding or decoding error occurs.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public actual open class CharacterCodingException(message: String?) : Exception(message) { public actual open class CharacterCodingException(message: String?) : Exception(message) {
actual constructor() : this(null) actual constructor() : this(null)
} }
+16 -16
View File
@@ -39,8 +39,8 @@ public actual fun String(chars: CharArray, offset: Int, length: Int): String {
/** /**
* Concatenates characters in this [CharArray] into a String. * Concatenates characters in this [CharArray] into a String.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public actual fun CharArray.concatToString(): String { public actual fun CharArray.concatToString(): String {
var result = "" var result = ""
for (char in this) { for (char in this) {
@@ -58,9 +58,9 @@ public actual fun CharArray.concatToString(): String {
* @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the size of this array. * @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
@ExperimentalStdlibApi
public actual fun CharArray.concatToString(startIndex: Int = 0, endIndex: Int = this.size): String { public actual fun CharArray.concatToString(startIndex: Int = 0, endIndex: Int = this.size): String {
AbstractList.checkBoundsIndexes(startIndex, endIndex, this.size) AbstractList.checkBoundsIndexes(startIndex, endIndex, this.size)
var result = "" var result = ""
@@ -73,8 +73,8 @@ public actual fun CharArray.concatToString(startIndex: Int = 0, endIndex: Int =
/** /**
* Returns a [CharArray] containing characters of this string. * Returns a [CharArray] containing characters of this string.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public actual fun String.toCharArray(): CharArray { public actual fun String.toCharArray(): CharArray {
return CharArray(length) { get(it) } return CharArray(length) { get(it) }
} }
@@ -88,9 +88,9 @@ public actual fun String.toCharArray(): CharArray {
* @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the length of this string. * @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the length of this string.
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
@ExperimentalStdlibApi
public actual fun String.toCharArray(startIndex: Int = 0, endIndex: Int = this.length): CharArray { public actual fun String.toCharArray(startIndex: Int = 0, endIndex: Int = this.length): CharArray {
AbstractList.checkBoundsIndexes(startIndex, endIndex, length) AbstractList.checkBoundsIndexes(startIndex, endIndex, length)
return CharArray(endIndex - startIndex) { get(startIndex + it) } return CharArray(endIndex - startIndex) { get(startIndex + it) }
@@ -101,8 +101,8 @@ public actual fun String.toCharArray(startIndex: Int = 0, endIndex: Int = this.l
* *
* Malformed byte sequences are replaced by the replacement char `\uFFFD`. * Malformed byte sequences are replaced by the replacement char `\uFFFD`.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public actual fun ByteArray.decodeToString(): String { public actual fun ByteArray.decodeToString(): String {
return decodeUtf8(this, 0, size, false) return decodeUtf8(this, 0, size, false)
} }
@@ -118,9 +118,9 @@ public actual fun ByteArray.decodeToString(): String {
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
* @throws CharacterCodingException if the byte array contains malformed UTF-8 byte sequence and [throwOnInvalidSequence] is true. * @throws CharacterCodingException if the byte array contains malformed UTF-8 byte sequence and [throwOnInvalidSequence] is true.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
@ExperimentalStdlibApi
public actual fun ByteArray.decodeToString( public actual fun ByteArray.decodeToString(
startIndex: Int = 0, startIndex: Int = 0,
endIndex: Int = this.size, endIndex: Int = this.size,
@@ -135,8 +135,8 @@ public actual fun ByteArray.decodeToString(
* *
* Any malformed char sequence is replaced by the replacement byte sequence. * Any malformed char sequence is replaced by the replacement byte sequence.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public actual fun String.encodeToByteArray(): ByteArray { public actual fun String.encodeToByteArray(): ByteArray {
return encodeUtf8(this, 0, length, false) return encodeUtf8(this, 0, length, false)
} }
@@ -152,9 +152,9 @@ public actual fun String.encodeToByteArray(): ByteArray {
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
* @throws CharacterCodingException if this string contains malformed char sequence and [throwOnInvalidSequence] is true. * @throws CharacterCodingException if this string contains malformed char sequence and [throwOnInvalidSequence] is true.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
@ExperimentalStdlibApi
public actual fun String.encodeToByteArray( public actual fun String.encodeToByteArray(
startIndex: Int = 0, startIndex: Int = 0,
endIndex: Int = this.length, endIndex: Int = this.length,
@@ -15,6 +15,6 @@ package kotlin.text
/** /**
* The exception thrown when a character encoding or decoding error occurs. * The exception thrown when a character encoding or decoding error occurs.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public actual typealias CharacterCodingException = java.nio.charset.CharacterCodingException public actual typealias CharacterCodingException = java.nio.charset.CharacterCodingException
@@ -114,8 +114,8 @@ public actual inline fun String.toLowerCase(): String = (this as java.lang.Strin
/** /**
* Concatenates characters in this [CharArray] into a String. * Concatenates characters in this [CharArray] into a String.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public actual fun CharArray.concatToString(): String { public actual fun CharArray.concatToString(): String {
return String(this) return String(this)
} }
@@ -129,9 +129,9 @@ public actual fun CharArray.concatToString(): String {
* @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the size of this array. * @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
@ExperimentalStdlibApi
public actual fun CharArray.concatToString(startIndex: Int = 0, endIndex: Int = this.size): String { public actual fun CharArray.concatToString(startIndex: Int = 0, endIndex: Int = this.size): String {
AbstractList.checkBoundsIndexes(startIndex, endIndex, this.size) AbstractList.checkBoundsIndexes(startIndex, endIndex, this.size)
return String(this, startIndex, endIndex - startIndex) return String(this, startIndex, endIndex - startIndex)
@@ -146,9 +146,9 @@ public actual fun CharArray.concatToString(startIndex: Int = 0, endIndex: Int =
* @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the length of this string. * @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the length of this string.
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
@ExperimentalStdlibApi
public actual fun String.toCharArray(startIndex: Int = 0, endIndex: Int = this.length): CharArray { public actual fun String.toCharArray(startIndex: Int = 0, endIndex: Int = this.length): CharArray {
AbstractList.checkBoundsIndexes(startIndex, endIndex, length) AbstractList.checkBoundsIndexes(startIndex, endIndex, length)
return toCharArray(CharArray(endIndex - startIndex), 0, startIndex, endIndex) return toCharArray(CharArray(endIndex - startIndex), 0, startIndex, endIndex)
@@ -159,8 +159,8 @@ public actual fun String.toCharArray(startIndex: Int = 0, endIndex: Int = this.l
* *
* Malformed byte sequences are replaced by the replacement char `\uFFFD`. * Malformed byte sequences are replaced by the replacement char `\uFFFD`.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public actual fun ByteArray.decodeToString(): String { public actual fun ByteArray.decodeToString(): String {
return String(this) return String(this)
} }
@@ -176,9 +176,9 @@ public actual fun ByteArray.decodeToString(): String {
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
* @throws CharacterCodingException if the byte array contains malformed UTF-8 byte sequence and [throwOnInvalidSequence] is true. * @throws CharacterCodingException if the byte array contains malformed UTF-8 byte sequence and [throwOnInvalidSequence] is true.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
@ExperimentalStdlibApi
public actual fun ByteArray.decodeToString( public actual fun ByteArray.decodeToString(
startIndex: Int = 0, startIndex: Int = 0,
endIndex: Int = this.size, endIndex: Int = this.size,
@@ -202,8 +202,8 @@ public actual fun ByteArray.decodeToString(
* *
* Any malformed char sequence is replaced by the replacement byte sequence. * Any malformed char sequence is replaced by the replacement byte sequence.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public actual fun String.encodeToByteArray(): ByteArray { public actual fun String.encodeToByteArray(): ByteArray {
return this.toByteArray(Charsets.UTF_8) return this.toByteArray(Charsets.UTF_8)
} }
@@ -219,9 +219,9 @@ public actual fun String.encodeToByteArray(): ByteArray {
* @throws IllegalArgumentException if [startIndex] is greater than [endIndex]. * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
* @throws CharacterCodingException if this string contains malformed char sequence and [throwOnInvalidSequence] is true. * @throws CharacterCodingException if this string contains malformed char sequence and [throwOnInvalidSequence] is true.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
@ExperimentalStdlibApi
public actual fun String.encodeToByteArray( public actual fun String.encodeToByteArray(
startIndex: Int = 0, startIndex: Int = 0,
endIndex: Int = this.length, endIndex: Int = this.length,
@@ -8,6 +8,6 @@ package kotlin.text
/** /**
* The exception thrown when a character encoding or decoding error occurs. * The exception thrown when a character encoding or decoding error occurs.
*/ */
@SinceKotlin("1.3") @SinceKotlin("1.4")
@ExperimentalStdlibApi @WasExperimental(ExperimentalStdlibApi::class)
public expect open class CharacterCodingException() : Exception public expect open class CharacterCodingException() : Exception