stdlib: Return this from StringBuilder.append
This commit is contained in:
@@ -58,19 +58,19 @@ class StringBuilder private constructor (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Of Appenable.
|
// Of Appenable.
|
||||||
override fun append(c: Char) : Appendable {
|
override fun append(c: Char) : StringBuilder {
|
||||||
ensureExtraCapacity(1)
|
ensureExtraCapacity(1)
|
||||||
array[length++] = c
|
array[length++] = c
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun append(csq: CharSequence?): Appendable {
|
override fun append(csq: CharSequence?): StringBuilder {
|
||||||
// TODO: how to treat nulls properly?
|
// TODO: how to treat nulls properly?
|
||||||
if (csq == null) return this
|
if (csq == null) return this
|
||||||
return append(csq, 0, csq.length)
|
return append(csq, 0, csq.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun append(csq: CharSequence?, start: Int, end: Int): Appendable {
|
override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder {
|
||||||
// TODO: how to treat nulls properly?
|
// TODO: how to treat nulls properly?
|
||||||
if (csq == null) return this
|
if (csq == null) return this
|
||||||
ensureExtraCapacity(end - start)
|
ensureExtraCapacity(end - start)
|
||||||
@@ -80,16 +80,18 @@ class StringBuilder private constructor (
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun append(it: CharArray) {
|
fun append(it: CharArray): StringBuilder {
|
||||||
ensureExtraCapacity(it.size)
|
ensureExtraCapacity(it.size)
|
||||||
for (c in it)
|
for (c in it)
|
||||||
array[length++] = c
|
array[length++] = c
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun append(it: String) {
|
fun append(it: String): StringBuilder {
|
||||||
ensureExtraCapacity(it.length)
|
ensureExtraCapacity(it.length)
|
||||||
for (c in toCharArray(it))
|
for (c in toCharArray(it))
|
||||||
array[length++] = c
|
array[length++] = c
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun append(it: Boolean) = append(it.toString())
|
fun append(it: Boolean) = append(it.toString())
|
||||||
|
|||||||
Reference in New Issue
Block a user