Add set operator to make the work with StringBuilder more list-like.
Make StringBuilder.set jvm-only. Move jvm-specific test.
This commit is contained in:
committed by
Ilya Gorbunov
parent
e155e426c2
commit
67229401c6
@@ -40,3 +40,9 @@ public fun StringBuilder.append(vararg value: Any?): StringBuilder {
|
||||
append(item)
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the character at the specified [index] to the specified [value].
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public operator fun StringBuilder.set(index: Int, value: Char): Unit = this.setCharAt(index, value)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package test.text
|
||||
|
||||
import kotlin.*
|
||||
import kotlin.test.*
|
||||
import org.junit.Test as test
|
||||
|
||||
class StringBuilderJVMTest() {
|
||||
@test fun getAndSetChar() {
|
||||
val sb = StringBuilder("abc")
|
||||
sb[1] = 'z'
|
||||
|
||||
assertEquals("azc", sb.toString())
|
||||
assertEquals('c', sb[2])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user