Move Appendable to its own file
This commit is contained in:
@@ -5,12 +5,6 @@
|
|||||||
|
|
||||||
package kotlin.text
|
package kotlin.text
|
||||||
|
|
||||||
expect interface Appendable {
|
|
||||||
fun append(c: Char): Appendable
|
|
||||||
fun append(csq: CharSequence?): Appendable
|
|
||||||
fun append(csq: CharSequence?, start: Int, end: Int): Appendable
|
|
||||||
}
|
|
||||||
|
|
||||||
expect class StringBuilder : Appendable, CharSequence {
|
expect class StringBuilder : Appendable, CharSequence {
|
||||||
constructor()
|
constructor()
|
||||||
constructor(capacity: Int)
|
constructor(capacity: Int)
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kotlin.text
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object to which char sequences and values can be appended.
|
||||||
|
*/
|
||||||
|
public actual interface Appendable {
|
||||||
|
/**
|
||||||
|
* Appends the specified character [c] to this Appendable and returns this instance.
|
||||||
|
*
|
||||||
|
* @param c the character to append.
|
||||||
|
*/
|
||||||
|
public actual fun append(c: Char): Appendable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends the specified character sequence [csq] to this Appendable and returns this instance.
|
||||||
|
*
|
||||||
|
* @param csq the character sequence to append. If [csq] is `null`, then the four characters `"null"` are appended to this Appendable.
|
||||||
|
*/
|
||||||
|
public actual fun append(csq: CharSequence?): Appendable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a subsequence of the specified character sequence [csq] to this Appendable and returns this instance.
|
||||||
|
*
|
||||||
|
* @param csq the character sequence from which a subsequence is appended. If [csq] is `null`,
|
||||||
|
* then characters are appended as if [csq] contained the four characters `"null"`.
|
||||||
|
* @param start the beginning (inclusive) of the subsequence to append.
|
||||||
|
* @param end the end (exclusive) of the subsequence to append.
|
||||||
|
*
|
||||||
|
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [start] or [end] is out of range of the [csq] character sequence indices or when `start > end`.
|
||||||
|
*/
|
||||||
|
public actual fun append(csq: CharSequence?, start: Int, end: Int): Appendable
|
||||||
|
}
|
||||||
@@ -5,13 +5,6 @@
|
|||||||
|
|
||||||
package kotlin.text
|
package kotlin.text
|
||||||
|
|
||||||
|
|
||||||
public actual interface Appendable {
|
|
||||||
public actual fun append(csq: CharSequence?): Appendable
|
|
||||||
public actual fun append(csq: CharSequence?, start: Int, end: Int): Appendable
|
|
||||||
public actual fun append(c: Char): Appendable
|
|
||||||
}
|
|
||||||
|
|
||||||
public actual class StringBuilder(content: String = "") : Appendable, CharSequence {
|
public actual class StringBuilder(content: String = "") : Appendable, CharSequence {
|
||||||
actual constructor(capacity: Int) : this() {}
|
actual constructor(capacity: Int) : this() {}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:kotlin.jvm.JvmMultifileClass
|
||||||
|
@file:kotlin.jvm.JvmName("StringsKt")
|
||||||
|
|
||||||
|
package kotlin.text
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object to which char sequences and values can be appended.
|
||||||
|
*/
|
||||||
|
expect interface Appendable {
|
||||||
|
/**
|
||||||
|
* Appends the specified character [c] to this Appendable and returns this instance.
|
||||||
|
*
|
||||||
|
* @param c the character to append.
|
||||||
|
*/
|
||||||
|
fun append(c: Char): Appendable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends the specified character sequence [csq] to this Appendable and returns this instance.
|
||||||
|
*
|
||||||
|
* @param csq the character sequence to append. If [csq] is `null`, then the four characters `"null"` are appended to this Appendable.
|
||||||
|
*/
|
||||||
|
fun append(csq: CharSequence?): Appendable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a subsequence of the specified character sequence [csq] to this Appendable and returns this instance.
|
||||||
|
*
|
||||||
|
* @param csq the character sequence from which a subsequence is appended. If [csq] is `null`,
|
||||||
|
* then characters are appended as if [csq] contained the four characters `"null"`.
|
||||||
|
* @param start the beginning (inclusive) of the subsequence to append.
|
||||||
|
* @param end the end (exclusive) of the subsequence to append.
|
||||||
|
*
|
||||||
|
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [start] or [end] is out of range of the [csq] character sequence indices or when `start > end`.
|
||||||
|
*/
|
||||||
|
fun append(csq: CharSequence?, start: Int, end: Int): Appendable
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends all arguments to the given [Appendable].
|
||||||
|
*/
|
||||||
|
public fun <T : Appendable> T.append(vararg value: CharSequence?): T {
|
||||||
|
for (item in value)
|
||||||
|
append(item)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
||||||
|
when {
|
||||||
|
transform != null -> append(transform(element))
|
||||||
|
element is CharSequence? -> append(element)
|
||||||
|
element is Char -> append(element)
|
||||||
|
else -> append(element.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,15 +25,6 @@ public inline fun buildString(builderAction: StringBuilder.() -> Unit): String =
|
|||||||
public inline fun buildString(capacity: Int, builderAction: StringBuilder.() -> Unit): String =
|
public inline fun buildString(capacity: Int, builderAction: StringBuilder.() -> Unit): String =
|
||||||
StringBuilder(capacity).apply(builderAction).toString()
|
StringBuilder(capacity).apply(builderAction).toString()
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends all arguments to the given [Appendable].
|
|
||||||
*/
|
|
||||||
public fun <T : Appendable> T.append(vararg value: CharSequence?): T {
|
|
||||||
for (item in value)
|
|
||||||
append(item)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends all arguments to the given StringBuilder.
|
* Appends all arguments to the given StringBuilder.
|
||||||
*/
|
*/
|
||||||
@@ -51,13 +42,3 @@ public fun StringBuilder.append(vararg value: Any?): StringBuilder {
|
|||||||
append(item)
|
append(item)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
|
||||||
when {
|
|
||||||
transform != null -> append(transform(element))
|
|
||||||
element is CharSequence? -> append(element)
|
|
||||||
element is Char -> append(element)
|
|
||||||
else -> append(element.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user