diff --git a/libraries/stdlib/src/generated/_Strings.kt b/libraries/stdlib/src/generated/_Strings.kt index fdec0449afb..7807803f6f5 100644 --- a/libraries/stdlib/src/generated/_Strings.kt +++ b/libraries/stdlib/src/generated/_Strings.kt @@ -7,221 +7,67 @@ package kotlin import java.util.* -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun Array.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun BooleanArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun ByteArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun CharArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun DoubleArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun FloatArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun IntArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun LongArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun ShortArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun Iterable.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } -/** - * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinTo() instead") public fun Stream.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { - buffer.append(prefix) - var count = 0 - for (element in this) { - if (++count > 1) buffer.append(separator) - if (limit < 0 || count <= limit) { - val text = if (element == null) "null" else element.toString() - buffer.append(text) - } else break - } - if (limit >= 0 && count > limit) buffer.append(truncated) - buffer.append(postfix) + joinTo(buffer, separator, prefix, postfix, limit, truncated) } /** * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." + * a special *truncated* separator (which defaults to "...") */ -public fun String.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { +public fun Array.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { buffer.append(prefix) var count = 0 for (element in this) { @@ -233,6 +79,207 @@ public fun String.appendString(buffer: Appendable, separator: String = ", ", pre } if (limit >= 0 && count > limit) buffer.append(truncated) buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun BooleanArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun ByteArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun CharArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun DoubleArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun FloatArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun IntArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun LongArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun ShortArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun Iterable.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = if (element == null) "null" else element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer +} + +/** + * Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun Stream.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): A { + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = if (element == null) "null" else element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer } /** @@ -240,130 +287,152 @@ public fun String.appendString(buffer: Appendable, separator: String = ", ", pre * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will * a special *truncated* separator (which defaults to "..." */ +public fun Array.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun BooleanArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun ByteArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun CharArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun DoubleArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun FloatArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun IntArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun LongArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun ShortArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun Iterable.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "..." + */ +public fun Stream.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() +} + +deprecated("Use joinToString() instead") public fun Array.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun BooleanArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun ByteArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun CharArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun DoubleArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun FloatArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun IntArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun LongArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun ShortArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun Iterable.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ +deprecated("Use joinToString() instead") public fun Stream.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() -} - -/** - * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. - * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - * a special *truncated* separator (which defaults to "..." - */ -public fun String.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinToString(separator, prefix, postfix, limit, truncated) } diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index 5b6f6b1c2b9..3aa6067ce77 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -68,3 +68,30 @@ public fun CharSequence.slice(indices: Iterable): CharSequence { * Returns a substring specified by given range */ public fun String.substring(range: IntRange): String = substring(range.start, range.end + 1) + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun Iterable.join(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinToString(separator, prefix, postfix, limit, truncated) +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If an array could be huge you can specify a non-negative value of *limit* which will only show a subset of the array then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun Array.join(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinToString(separator, prefix, postfix, limit, truncated) +} + +/** + * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. + * If a stream could be huge you can specify a non-negative value of *limit* which will only show a subset of the stream then it will + * a special *truncated* separator (which defaults to "...") + */ +public fun Stream.join(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { + return joinToString(separator, prefix, postfix, limit, truncated) +} \ No newline at end of file diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Strings.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Strings.kt index e05c7dff092..4c918d4359d 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Strings.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Strings.kt @@ -6,15 +6,27 @@ fun strings(): List { val templates = arrayListOf() templates add f("appendString(buffer: Appendable, separator: String = \", \", prefix: String = \"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\")") { + deprecate{"Use joinTo() instead"} + returns { "Unit" } + exclude(Strings) + body { + """ + joinTo(buffer, separator, prefix, postfix, limit, truncated) + """ + } + } + + templates add f("joinTo(buffer: A, separator: String = \", \", prefix: String = \"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\")") { doc { """ Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will - a special *truncated* separator (which defaults to "..." + a special *truncated* separator (which defaults to "...") """ } - returns { "Unit" } + typeParam("A : Appendable") + returns { "A" } body { """ buffer.append(prefix) @@ -28,11 +40,40 @@ fun strings(): List { } if (limit >= 0 && count > limit) buffer.append(truncated) buffer.append(postfix) + return buffer + """ + } + exclude(Strings) + body(ArraysOfPrimitives) { + """ + buffer.append(prefix) + var count = 0 + for (element in this) { + if (++count > 1) buffer.append(separator) + if (limit < 0 || count <= limit) { + val text = element.toString() + buffer.append(text) + } else break + } + if (limit >= 0 && count > limit) buffer.append(truncated) + buffer.append(postfix) + return buffer """ } } templates add f("makeString(separator: String = \", \", prefix: String = \"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\")") { + deprecate{"Use joinToString() instead"} + exclude(Strings) + returns("String") + body { + """ + return joinToString(separator, prefix, postfix, limit, truncated) + """ + } + } + + templates add f("joinToString(separator: String = \", \", prefix: String = \"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\")") { doc { """ Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied. @@ -42,12 +83,11 @@ fun strings(): List { """ } + exclude(Strings) returns("String") body { """ - val buffer = StringBuilder() - appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString() + return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated).toString() """ } }