From ebc2dc64b207b95b646db8c7536854b4b7d4cad1 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Fri, 29 May 2020 01:42:09 +0300 Subject: [PATCH] Make consistent parameter nullability with appendLine (cherry picked from commit f4bddc0552dd2bd0bf59c6b305112488f90b69d7) --- .../main/kotlin/kotlin/text/StringBuilder.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/runtime/src/main/kotlin/kotlin/text/StringBuilder.kt b/runtime/src/main/kotlin/kotlin/text/StringBuilder.kt index 9339053fcda..1fb54adfd32 100644 --- a/runtime/src/main/kotlin/kotlin/text/StringBuilder.kt +++ b/runtime/src/main/kotlin/kotlin/text/StringBuilder.kt @@ -178,10 +178,13 @@ actual class StringBuilder private constructor ( /** * Appends the specified string [value] to this string builder and returns this instance. + * + * If [value] is `null`, then the four characters `"null"` are appended. */ - actual fun append(value: String): StringBuilder { - ensureExtraCapacity(value.length) - _length += insertString(array, _length, value) + actual fun append(value: String?): StringBuilder { + val toAppend = value ?: "null" + ensureExtraCapacity(toAppend.length) + _length += insertString(array, _length, toAppend) return this } @@ -338,13 +341,16 @@ actual class StringBuilder private constructor ( /** * Inserts the string [value] into this string builder at the specified [index] and returns this instance. * + * If [value] is `null`, then the four characters `"null"` are inserted. + * * @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder. */ - actual fun insert(index: Int, value: String): StringBuilder { + actual fun insert(index: Int, value: String?): StringBuilder { + val toInsert = value ?: "null" checkInsertIndex(index) - ensureExtraCapacity(value.length) - array.copyInto(array, startIndex = index, endIndex = _length, destinationOffset = index + value.length) - _length += insertString(array, index, value) + ensureExtraCapacity(toInsert.length) + array.copyInto(array, startIndex = index, endIndex = _length, destinationOffset = index + toInsert.length) + _length += insertString(array, index, toInsert) return this }