#KT-1675 Fixed, renaming join() -> makeString() and adding an appendString() which reduces the possible number of appendables being created

This commit is contained in:
James Strachan
2012-04-02 20:01:24 +01:00
parent fc683e8141
commit 1d342978d0
17 changed files with 76 additions and 100 deletions
@@ -61,19 +61,3 @@ public inline fun <T> Array<T>.take(n: Int): List<T> {
* @includeFunctionBody ../../test/CollectionTest.kt takeWhile
*/
public inline fun <T> Array<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate)
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
*
* @includeFunctionBody ../../test/CollectionTest.kt join
*/
public inline fun <T> Array<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
val buffer = StringBuilder(prefix)
var first = true
for (element in this) {
if (first) first = false else buffer.append(separator)
buffer.append(element)
}
buffer.append(postfix)
return buffer.toString().sure()
}
@@ -61,19 +61,3 @@ public inline fun <T> Iterable<T>.take(n: Int): List<T> {
* @includeFunctionBody ../../test/CollectionTest.kt takeWhile
*/
public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate)
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
*
* @includeFunctionBody ../../test/CollectionTest.kt join
*/
public inline fun <T> Iterable<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
val buffer = StringBuilder(prefix)
var first = true
for (element in this) {
if (first) first = false else buffer.append(separator)
buffer.append(element)
}
buffer.append(postfix)
return buffer.toString().sure()
}