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:
Daniel Rothmaler
2015-10-14 14:59:56 +03:00
committed by Ilya Gorbunov
parent e155e426c2
commit 67229401c6
2 changed files with 21 additions and 0 deletions
@@ -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])
}
}