Skip to content

Commit ebc2dc6

Browse files
Abduqodiri Qurbonzodaminamoto79
Abduqodiri Qurbonzoda
authored andcommitted
Make consistent parameter nullability with appendLine
(cherry picked from commit f4bddc0552dd2bd0bf59c6b305112488f90b69d7)
1 parent bb397b6 commit ebc2dc6

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

runtime/src/main/kotlin/kotlin/text/StringBuilder.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,13 @@ actual class StringBuilder private constructor (
178178

179179
/**
180180
* Appends the specified string [value] to this string builder and returns this instance.
181+
*
182+
* If [value] is `null`, then the four characters `"null"` are appended.
181183
*/
182-
actual fun append(value: String): StringBuilder {
183-
ensureExtraCapacity(value.length)
184-
_length += insertString(array, _length, value)
184+
actual fun append(value: String?): StringBuilder {
185+
val toAppend = value ?: "null"
186+
ensureExtraCapacity(toAppend.length)
187+
_length += insertString(array, _length, toAppend)
185188
return this
186189
}
187190

@@ -338,13 +341,16 @@ actual class StringBuilder private constructor (
338341
/**
339342
* Inserts the string [value] into this string builder at the specified [index] and returns this instance.
340343
*
344+
* If [value] is `null`, then the four characters `"null"` are inserted.
345+
*
341346
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
342347
*/
343-
actual fun insert(index: Int, value: String): StringBuilder {
348+
actual fun insert(index: Int, value: String?): StringBuilder {
349+
val toInsert = value ?: "null"
344350
checkInsertIndex(index)
345-
ensureExtraCapacity(value.length)
346-
array.copyInto(array, startIndex = index, endIndex = _length, destinationOffset = index + value.length)
347-
_length += insertString(array, index, value)
351+
ensureExtraCapacity(toInsert.length)
352+
array.copyInto(array, startIndex = index, endIndex = _length, destinationOffset = index + toInsert.length)
353+
_length += insertString(array, index, toInsert)
348354
return this
349355
}
350356

0 commit comments

Comments
 (0)