[Wasm] Improve string constructor in stdlib
This commit is contained in:
@@ -252,7 +252,15 @@ public actual fun Char.isWhitespace(): Boolean = TODO("Wasm stdlib: Text")
|
||||
* Converts the characters in the specified array to a string.
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public actual fun String(chars: CharArray): String = TODO("Wasm stdlib: Text")
|
||||
@Deprecated("Use CharArray.concatToString() instead", ReplaceWith("chars.concatToString()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.5")
|
||||
public actual fun String(chars: CharArray): String {
|
||||
var result = ""
|
||||
for (char in chars) {
|
||||
result += char
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the characters from a portion of the specified array to a string.
|
||||
@@ -261,7 +269,17 @@ public actual fun String(chars: CharArray): String = TODO("Wasm stdlib: Text")
|
||||
* or `offset + length` is out of [chars] array bounds.
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public actual fun String(chars: CharArray, offset: Int, length: Int): String = TODO("Wasm stdlib: Text")
|
||||
@Deprecated("Use CharArray.concatToString(startIndex, endIndex) instead", ReplaceWith("chars.concatToString(offset, offset + length)"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.5")
|
||||
public actual fun String(chars: CharArray, offset: Int, length: Int): String {
|
||||
if (offset < 0 || length < 0 || chars.size - offset < length)
|
||||
throw IndexOutOfBoundsException("size: ${chars.size}; offset: $offset; length: $length")
|
||||
var result = ""
|
||||
for (index in offset until offset + length) {
|
||||
result += chars[index]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates characters in this [CharArray] into a String.
|
||||
|
||||
@@ -15,7 +15,7 @@ internal fun insertString(array: CharArray, distIndex: Int, value: String, sourc
|
||||
}
|
||||
|
||||
internal fun unsafeStringFromCharArray(array: CharArray, start: Int, size: Int): String =
|
||||
kotlin.String(array.copyOfRange(start, start + size))
|
||||
String.unsafeFromCharArray(array.copyOfRange(start, start + size))
|
||||
|
||||
internal fun insertInt(array: CharArray, start: Int, value: Int): Int {
|
||||
val valueString = value.toString()
|
||||
|
||||
Reference in New Issue
Block a user