@@ -178,10 +178,13 @@ actual class StringBuilder private constructor (
178
178
179
179
/* *
180
180
* 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.
181
183
*/
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)
185
188
return this
186
189
}
187
190
@@ -338,13 +341,16 @@ actual class StringBuilder private constructor (
338
341
/* *
339
342
* Inserts the string [value] into this string builder at the specified [index] and returns this instance.
340
343
*
344
+ * If [value] is `null`, then the four characters `"null"` are inserted.
345
+ *
341
346
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
342
347
*/
343
- actual fun insert (index : Int , value : String ): StringBuilder {
348
+ actual fun insert (index : Int , value : String? ): StringBuilder {
349
+ val toInsert = value ? : " null"
344
350
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 )
348
354
return this
349
355
}
350
356
0 commit comments