Restore dropped hidden declarations for binary compatibility until RC.
This commit is contained in:
@@ -2,13 +2,24 @@
|
||||
// CHECK_BOX
|
||||
// SEARCH_TEXT: joinToString
|
||||
// REF: (for Array<out T> in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((T) -> CharSequence)?)
|
||||
// REF: (for Array<out T> in kotlin).joinToString(String, String, String, Int, String, ((T) -> String)?)
|
||||
// REF: (for BooleanArray in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((Boolean) -> CharSequence)?)
|
||||
// REF: (for BooleanArray in kotlin).joinToString(String, String, String, Int, String, ((Boolean) -> String)?)
|
||||
// REF: (for ByteArray in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((Byte) -> CharSequence)?)
|
||||
// REF: (for ByteArray in kotlin).joinToString(String, String, String, Int, String, ((Byte) -> String)?)
|
||||
// REF: (for CharArray in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((Char) -> CharSequence)?)
|
||||
// REF: (for CharArray in kotlin).joinToString(String, String, String, Int, String, ((Char) -> String)?)
|
||||
// REF: (for DoubleArray in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((Double) -> CharSequence)?)
|
||||
// REF: (for DoubleArray in kotlin).joinToString(String, String, String, Int, String, ((Double) -> String)?)
|
||||
// REF: (for FloatArray in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((Float) -> CharSequence)?)
|
||||
// REF: (for FloatArray in kotlin).joinToString(String, String, String, Int, String, ((Float) -> String)?)
|
||||
// REF: (for IntArray in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((Int) -> CharSequence)?)
|
||||
// REF: (for IntArray in kotlin).joinToString(String, String, String, Int, String, ((Int) -> String)?)
|
||||
// REF: (for Iterable<T> in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((T) -> CharSequence)?)
|
||||
// REF: (for Iterable<T> in kotlin).joinToString(String, String, String, Int, String, ((T) -> String)?)
|
||||
// REF: (for LongArray in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((Long) -> CharSequence)?)
|
||||
// REF: (for LongArray in kotlin).joinToString(String, String, String, Int, String, ((Long) -> String)?)
|
||||
// REF: (for Sequence<T> in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((T) -> CharSequence)?)
|
||||
// REF: (for Sequence<T> in kotlin).joinToString(String, String, String, Int, String, ((T) -> String)?)
|
||||
// REF: (for ShortArray in kotlin).joinToString(CharSequence, CharSequence, CharSequence, Int, CharSequence, ((Short) -> CharSequence)?)
|
||||
// REF: (for ShortArray in kotlin).joinToString(String, String, String, Int, String, ((Short) -> String)?)
|
||||
@@ -10253,6 +10253,51 @@ public fun <A : Appendable> ShortArray.joinTo(buffer: A, separator: CharSequence
|
||||
return buffer
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <T, A : Appendable> Array<out T>.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((T) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <A : Appendable> BooleanArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Boolean) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <A : Appendable> ByteArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Byte) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <A : Appendable> CharArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Char) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <A : Appendable> DoubleArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Double) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <A : Appendable> FloatArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Float) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <A : Appendable> IntArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Int) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <A : Appendable> LongArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Long) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <A : Appendable> ShortArray.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Short) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
|
||||
* If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit]
|
||||
@@ -10334,6 +10379,51 @@ public fun ShortArray.joinToString(separator: CharSequence = ", ", prefix: CharS
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <T> Array<out T>.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((T) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun BooleanArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Boolean) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun ByteArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Byte) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun CharArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Char) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun DoubleArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Double) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun FloatArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Float) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun IntArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Int) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun LongArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Long) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun ShortArray.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((Short) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sequence from the given collection.
|
||||
*/
|
||||
|
||||
@@ -1734,6 +1734,11 @@ public fun <T, A : Appendable> Iterable<T>.joinTo(buffer: A, separator: CharSequ
|
||||
return buffer
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <T, A : Appendable> Iterable<T>.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((T) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
|
||||
* If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit]
|
||||
@@ -1743,6 +1748,11 @@ public fun <T> Iterable<T>.joinToString(separator: CharSequence = ", ", prefix:
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <T> Iterable<T>.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((T) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sequence from the given collection.
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,60 @@ import java.util.*
|
||||
|
||||
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]
|
||||
public fun Byte.`-downTo`(to: Byte): ByteProgression {
|
||||
return ByteProgression.fromClosedRange(this, to, -1)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]
|
||||
public fun Short.`-downTo`(to: Byte): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(this, to.toShort(), -1)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]
|
||||
public fun Byte.`-downTo`(to: Short): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(this.toShort(), to, -1)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]
|
||||
public fun Short.`-downTo`(to: Short): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(this, to, -1)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]
|
||||
public fun Byte.`-until`(to: Byte): ByteRange {
|
||||
val to_ = (to - 1).toByte()
|
||||
if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.")
|
||||
return ByteRange(this, to_)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]
|
||||
public fun Short.`-until`(to: Byte): ShortRange {
|
||||
return ShortRange(this, (to.toShort() - 1).toShort())
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]
|
||||
public fun Byte.`-until`(to: Short): ShortRange {
|
||||
val to_ = (to - 1).toShort()
|
||||
if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.")
|
||||
return ShortRange(this.toShort(), to_)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]
|
||||
public fun Short.`-until`(to: Short): ShortRange {
|
||||
val to_ = (to - 1).toShort()
|
||||
if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.")
|
||||
return ShortRange(this, to_)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
@@ -679,6 +733,30 @@ public fun LongProgression.reversed(): LongProgression {
|
||||
return LongProgression.fromClosedRange(last, first, -increment)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range in reverse direction.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun CharRange.reversed(): CharProgression {
|
||||
return CharProgression.fromClosedRange(last, first, -1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range in reverse direction.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun IntRange.reversed(): IntProgression {
|
||||
return IntProgression.fromClosedRange(last, first, -1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range in reverse direction.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun LongRange.reversed(): LongProgression {
|
||||
return LongProgression.fromClosedRange(last, first, -1L)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range in the opposite direction with the same step.
|
||||
*/
|
||||
@@ -697,6 +775,24 @@ public fun ShortProgression.reversed(): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(last, first, -increment)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range in reverse direction.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public fun ByteRange.reversed(): ByteProgression {
|
||||
return ByteProgression.fromClosedRange(last, first, -1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range in reverse direction.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public fun ShortRange.reversed(): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(last, first, -1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*/
|
||||
@@ -721,6 +817,33 @@ public infix fun LongProgression.step(step: Long): LongProgression {
|
||||
return LongProgression.fromClosedRange(first, last, if (increment > 0) step else -step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range with given step.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public infix fun CharRange.step(step: Int): CharProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return CharProgression.fromClosedRange(first, last, step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range with given step.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public infix fun IntRange.step(step: Int): IntProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return IntProgression.fromClosedRange(first, last, step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range with given step.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public infix fun LongRange.step(step: Long): LongProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return LongProgression.fromClosedRange(first, last, step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*/
|
||||
@@ -741,6 +864,26 @@ public infix fun ShortProgression.step(step: Int): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(first, last, if (increment > 0) step else -step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range with given step.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public infix fun ByteRange.step(step: Int): ByteProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ByteProgression.fromClosedRange(first, last, step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range with given step.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public infix fun ShortRange.step(step: Int): ShortProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ShortProgression.fromClosedRange(first, last, step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
@@ -1192,3 +1335,23 @@ public fun Short.coerceIn(range: Range<Short>): Short {
|
||||
return if (this < range.start) range.start else if (this > range.end) range.end else this
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that this value lies in the specified [range].
|
||||
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun Double.coerceIn(range: Range<Double>): Double {
|
||||
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
|
||||
return if (this < range.start) range.start else if (this > range.end) range.end else this
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that this value lies in the specified [range].
|
||||
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun Float.coerceIn(range: Range<Float>): Float {
|
||||
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
|
||||
return if (this < range.start) range.start else if (this > range.end) range.end else this
|
||||
}
|
||||
|
||||
|
||||
@@ -1048,6 +1048,11 @@ public fun <T, A : Appendable> Sequence<T>.joinTo(buffer: A, separator: CharSequ
|
||||
return buffer
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <T, A : Appendable> Sequence<T>.joinTo(buffer: A, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((T) -> String)? = null): A {
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
|
||||
* If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit]
|
||||
@@ -1057,6 +1062,11 @@ public fun <T> Sequence<T>.joinToString(separator: CharSequence = ", ", prefix:
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun <T> Sequence<T>.joinToString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...", transform: ((T) -> String)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sequence from the given collection.
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,10 @@ public operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): Unit {
|
||||
put(key, value)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@JvmName("set")
|
||||
public fun <K, V> MutableMap<K, V>.set(key: K, value: V): V? = put(key, value)
|
||||
|
||||
/**
|
||||
* getOrPut is not supported on [ConcurrentMap] since it cannot be implemented correctly in terms of concurrency.
|
||||
* Use [concurrentGetOrPut] instead, or cast this to a [MutableMap] if you want to sacrifice the concurrent-safety.
|
||||
|
||||
@@ -0,0 +1,577 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("StringsKt")
|
||||
|
||||
|
||||
package kotlin
|
||||
|
||||
import java.util.NoSuchElementException
|
||||
import kotlin.text.MatchResult
|
||||
import kotlin.text.Regex
|
||||
|
||||
/** Returns `true` if the string is not `null` and not empty */
|
||||
@Deprecated("Use !isNullOrEmpty() or isNullOrEmpty().not() for nullable strings.", ReplaceWith("this != null && this.isNotEmpty()"), DeprecationLevel.ERROR)
|
||||
@kotlin.jvm.JvmName("isNotEmptyNullable")
|
||||
public fun CharSequence?.isNotEmpty(): Boolean = this != null && this.length() > 0
|
||||
|
||||
|
||||
/** Returns `true` if the string is not `null` and not empty */
|
||||
@Deprecated("Use !isNullOrEmpty() or isNullOrEmpty().not() for nullable strings.", ReplaceWith("this != null && this.isNotEmpty()"), DeprecationLevel.HIDDEN)
|
||||
@kotlin.jvm.JvmName("isNotEmptyNullable")
|
||||
public fun String?.isNotEmpty(): Boolean = this != null && this.length() > 0
|
||||
|
||||
/**
|
||||
* Returns `true` if this nullable string is either `null` or empty.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String?.isNullOrEmpty(): Boolean = this == null || this.length() == 0
|
||||
|
||||
/**
|
||||
* Returns `true` if this string is empty (contains no characters).
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.isEmpty(): Boolean = length() == 0
|
||||
|
||||
/**
|
||||
* Returns `true` if this string is not empty.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.isNotEmpty(): Boolean = length() > 0
|
||||
|
||||
// implemented differently in JVM and JS
|
||||
//public fun String.isBlank(): Boolean = length() == 0 || all { it.isWhitespace() }
|
||||
|
||||
|
||||
/**
|
||||
* Returns `true` if this string is not empty and contains some characters except of whitespace characters.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.isNotBlank(): Boolean = !isBlank()
|
||||
|
||||
/**
|
||||
* Returns `true` if this nullable string is either `null` or empty or consists solely of whitespace characters.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String?.isNullOrBlank(): Boolean = this == null || this.isBlank()
|
||||
|
||||
/**
|
||||
* Returns the range of valid character indices for this string.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public val String.indices: IntRange
|
||||
get() = 0..length() - 1
|
||||
|
||||
/**
|
||||
* Returns the index of the last character in the String or -1 if the String is empty.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public val String.lastIndex: Int
|
||||
get() = this.length() - 1
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a substring before the first occurrence of [delimiter].
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.substringBefore(delimiter: Char, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(0, index)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a substring before the first occurrence of [delimiter].
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.substringBefore(delimiter: String, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(0, index)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a substring after the first occurrence of [delimiter].
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.substringAfter(delimiter: Char, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(index + 1, length())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a substring after the first occurrence of [delimiter].
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.substringAfter(delimiter: String, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(index + delimiter.length(), length())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a substring before the last occurrence of [delimiter].
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.substringBeforeLast(delimiter: Char, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(0, index)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a substring before the last occurrence of [delimiter].
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.substringBeforeLast(delimiter: String, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(0, index)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a substring after the last occurrence of [delimiter].
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.substringAfterLast(delimiter: Char, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(index + 1, length())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a substring after the last occurrence of [delimiter].
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.substringAfterLast(delimiter: String, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(index + delimiter.length(), length())
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace part of string before the first occurrence of given delimiter with the [replacement] string.
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.replaceBefore(delimiter: Char, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(0, index, replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace part of string before the first occurrence of given delimiter with the [replacement] string.
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.replaceBefore(delimiter: String, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(0, index, replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace part of string after the first occurrence of given delimiter with the [replacement] string.
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.replaceAfter(delimiter: Char, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + 1, length(), replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace part of string after the first occurrence of given delimiter with the [replacement] string.
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.replaceAfter(delimiter: String, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + delimiter.length(), length(), replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace part of string after the last occurrence of given delimiter with the [replacement] string.
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.replaceAfterLast(delimiter: String, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + delimiter.length(), length(), replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace part of string after the last occurrence of given delimiter with the [replacement] string.
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.replaceAfterLast(delimiter: Char, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + 1, length(), replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace part of string before the last occurrence of given delimiter with the [replacement] string.
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.replaceBeforeLast(delimiter: Char, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(0, index, replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace part of string before the last occurrence of given delimiter with the [replacement] string.
|
||||
* If the string does not contain the delimiter, returns [missingDelimiterValue] which defaults to the original string.
|
||||
*/
|
||||
public fun String.replaceBeforeLast(delimiter: String, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(0, index, replacement)
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.replaceRange(firstIndex: Int, lastIndex: Int, replacement: String): String
|
||||
= replaceRange(firstIndex, lastIndex, replacement)
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.replaceRange(range: IntRange, replacement: String): String
|
||||
= replaceRange(range.start, range.end + 1, replacement)
|
||||
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.removePrefix(prefix: String): String = removePrefix(prefix)
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.removeSuffix(suffix: String): String = removeSuffix(suffix)
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.removeSurrounding(prefix: String, suffix: String): String = removeSurrounding(prefix, suffix)
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.removeSurrounding(delimiter: String): String = removeSurrounding(delimiter, delimiter)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new string obtained by replacing each substring of this string that matches the given regular expression
|
||||
* with the given [replacement].
|
||||
*
|
||||
* The [replacement] can consist of any combination of literal text and $-substitutions. To treat the replacement string
|
||||
* literally escape it with the [kotlin.text.Regex.Companion.escapeReplacement] method.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.replace(regex: Regex, replacement: String): String = regex.replace(this, replacement)
|
||||
|
||||
/**
|
||||
* Returns a new string obtained by replacing each substring of this string that matches the given regular expression
|
||||
* with the result of the given function [transform] that takes [MatchResult] and returns a string to be used as a
|
||||
* replacement for that match.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.replace(regex: Regex, transform: (MatchResult) -> String): String = regex.replace(this, transform)
|
||||
|
||||
/**
|
||||
* Replaces the first occurrence of the given regular expression [regex] in this string with specified [replacement] expression.
|
||||
*
|
||||
* @param replacement A replacement expression that can include substitutions. See [Regex.replaceFirst] for details.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.replaceFirst(regex: Regex, replacement: String): String = regex.replaceFirst(this, replacement)
|
||||
|
||||
|
||||
/**
|
||||
* Returns `true` if this string matches the given regular expression.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.matches(regex: Regex): Boolean = regex.matches(this)
|
||||
|
||||
|
||||
/**
|
||||
* Returns `true` if this string starts with the specified character.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.startsWith(char: Char, ignoreCase: Boolean = false): Boolean =
|
||||
this.length() > 0 && this[0].equals(char, ignoreCase)
|
||||
|
||||
/**
|
||||
* Returns `true` if this string ends with the specified character.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.endsWith(char: Char, ignoreCase: Boolean = false): Boolean =
|
||||
this.length() > 0 && this[lastIndex].equals(char, ignoreCase)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// indexOfAny()
|
||||
|
||||
private fun String.findAnyOf(chars: CharArray, startIndex: Int, ignoreCase: Boolean, last: Boolean): Pair<Int, Char>? {
|
||||
if (!ignoreCase && chars.size() == 1) {
|
||||
val char = chars.single()
|
||||
val index = if (!last) nativeIndexOf(char, startIndex) else nativeLastIndexOf(char, startIndex)
|
||||
return if (index < 0) null else index to char
|
||||
}
|
||||
|
||||
val indices = if (!last) Math.max(startIndex, 0)..lastIndex else Math.min(startIndex, lastIndex) downTo 0
|
||||
for (index in indices) {
|
||||
val charAtIndex = get(index)
|
||||
val matchingCharIndex = chars.indexOfFirst { it.equals(charAtIndex, ignoreCase) }
|
||||
if (matchingCharIndex >= 0)
|
||||
return index to chars[matchingCharIndex]
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the index of the first occurrence of any of the specified [chars] in this string, starting from the specified [startIndex] and
|
||||
* optionally ignoring the case.
|
||||
*
|
||||
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
||||
* @returns An index of the first occurrence of matched character from [chars] or -1 if none of [chars] are found.
|
||||
*
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.indexOfAny(chars: CharArray, startIndex: Int = 0, ignoreCase: Boolean = false): Int =
|
||||
findAnyOf(chars, startIndex, ignoreCase, last = false)?.first ?: -1
|
||||
|
||||
/**
|
||||
* Finds the index of the last occurrence of any of the specified [chars] in this string, starting from the specified [startIndex] and
|
||||
* optionally ignoring the case.
|
||||
*
|
||||
* @param startIndex The index of character to start searching at. The search proceeds backward toward the beginning of the string.
|
||||
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
||||
* @returns An index of the last occurrence of matched character from [chars] or -1 if none of [chars] are found.
|
||||
*
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.lastIndexOfAny(chars: CharArray, startIndex: Int = lastIndex, ignoreCase: Boolean = false): Int =
|
||||
findAnyOf(chars, startIndex, ignoreCase, last = true)?.first ?: -1
|
||||
|
||||
|
||||
private fun String.findAnyOf(strings: Collection<String>, startIndex: Int, ignoreCase: Boolean, last: Boolean): Pair<Int, String>? {
|
||||
if (!ignoreCase && strings.size() == 1) {
|
||||
val string = strings.single()
|
||||
val index = if (!last) nativeIndexOf(string, startIndex) else nativeLastIndexOf(string, startIndex)
|
||||
return if (index < 0) null else index to string
|
||||
}
|
||||
|
||||
val indices = if (!last) Math.max(startIndex, 0)..length() else Math.min(startIndex, lastIndex) downTo 0
|
||||
for (index in indices) {
|
||||
val matchingString = strings.firstOrNull { it.regionMatches(0, this, index, it.length(), ignoreCase) }
|
||||
if (matchingString != null)
|
||||
return index to matchingString
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first occurrence of any of the specified [strings] in this string, starting from the specified [startIndex] and
|
||||
* optionally ignoring the case.
|
||||
*
|
||||
* @param ignoreCase `true` to ignore character case when matching a string. By default `false`.
|
||||
* @returns A pair of an index of the first occurrence of matched string from [strings] and the string matched or `null` if none of [strings] are found.
|
||||
*
|
||||
* To avoid ambiguous results when strings in [strings] have characters in common, this method proceeds from
|
||||
* the beginning to the end of this string, and finds at each position the first element in [strings]
|
||||
* that matches this string at that position.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.findAnyOf(strings: Collection<String>, startIndex: Int = 0, ignoreCase: Boolean = false): Pair<Int, String>? =
|
||||
findAnyOf(strings, startIndex, ignoreCase, last = false)
|
||||
|
||||
/**
|
||||
* Finds the last occurrence of any of the specified [strings] in this string, starting from the specified [startIndex] and
|
||||
* optionally ignoring the case.
|
||||
*
|
||||
* @param startIndex The index of character to start searching at. The search proceeds backward toward the beginning of the string.
|
||||
* @param ignoreCase `true` to ignore character case when matching a string. By default `false`.
|
||||
* @returns A pair of an index of the last occurrence of matched string from [strings] and the string matched or `null` if none of [strings] are found.
|
||||
*
|
||||
* To avoid ambiguous results when strings in [strings] have characters in common, this method proceeds from
|
||||
* the end toward the beginning of this string, and finds at each position the first element in [strings]
|
||||
* that matches this string at that position.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.findLastAnyOf(strings: Collection<String>, startIndex: Int = lastIndex, ignoreCase: Boolean = false): Pair<Int, String>? =
|
||||
findAnyOf(strings, startIndex, ignoreCase, last = true)
|
||||
|
||||
/**
|
||||
* Finds the index of the first occurrence of any of the specified [strings] in this string, starting from the specified [startIndex] and
|
||||
* optionally ignoring the case.
|
||||
*
|
||||
* @param ignoreCase `true` to ignore character case when matching a string. By default `false`.
|
||||
* @returns An index of the first occurrence of matched string from [strings] or -1 if none of [strings] are found.
|
||||
*
|
||||
* To avoid ambiguous results when strings in [strings] have characters in common, this method proceeds from
|
||||
* the beginning to the end of this string, and finds at each position the first element in [strings]
|
||||
* that matches this string at that position.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.indexOfAny(strings: Collection<String>, startIndex: Int = 0, ignoreCase: Boolean = false): Int =
|
||||
findAnyOf(strings, startIndex, ignoreCase, last = false)?.first ?: -1
|
||||
|
||||
/**
|
||||
* Finds the index of the last occurrence of any of the specified [strings] in this string, starting from the specified [startIndex] and
|
||||
* optionally ignoring the case.
|
||||
*
|
||||
* @param startIndex The index of character to start searching at. The search proceeds backward toward the beginning of the string.
|
||||
* @param ignoreCase `true` to ignore character case when matching a string. By default `false`.
|
||||
* @returns An index of the last occurrence of matched string from [strings] or -1 if none of [strings] are found.
|
||||
*
|
||||
* To avoid ambiguous results when strings in [strings] have characters in common, this method proceeds from
|
||||
* the end toward the beginning of this string, and finds at each position the first element in [strings]
|
||||
* that matches this string at that position.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.lastIndexOfAny(strings: Collection<String>, startIndex: Int = lastIndex, ignoreCase: Boolean = false): Int =
|
||||
findAnyOf(strings, startIndex, ignoreCase, last = true)?.first ?: -1
|
||||
|
||||
|
||||
// indexOf
|
||||
|
||||
/**
|
||||
* Returns the index within this string of the first occurrence of the specified character, starting from the specified [startIndex].
|
||||
*
|
||||
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
||||
* @returns An index of the first occurrence of [char] or -1 if none is found.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.indexOf(char: Char, startIndex: Int = 0, ignoreCase: Boolean = false): Int {
|
||||
return if (ignoreCase)
|
||||
indexOfAny(charArrayOf(char), startIndex, ignoreCase)
|
||||
else
|
||||
nativeIndexOf(char, startIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index within this string of the first occurrence of the specified [string], starting from the specified [startIndex].
|
||||
*
|
||||
* @param ignoreCase `true` to ignore character case when matching a string. By default `false`.
|
||||
* @returns An index of the first occurrence of [string] or -1 if none is found.
|
||||
*/
|
||||
@kotlin.jvm.JvmOverloads
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.indexOf(string: String, startIndex: Int = 0, ignoreCase: Boolean = false): Int {
|
||||
return if (ignoreCase)
|
||||
indexOfAny(listOf(string), startIndex, ignoreCase)
|
||||
else
|
||||
nativeIndexOf(string, startIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index within this string of the last occurrence of the specified character, starting from the specified [startIndex].
|
||||
*
|
||||
* @param startIndex The index of character to start searching at. The search proceeds backward toward the beginning of the string.
|
||||
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
||||
* @returns An index of the first occurrence of [char] or -1 if none is found.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.lastIndexOf(char: Char, startIndex: Int = lastIndex, ignoreCase: Boolean = false): Int {
|
||||
return if (ignoreCase)
|
||||
lastIndexOfAny(charArrayOf(char), startIndex, ignoreCase)
|
||||
else
|
||||
nativeLastIndexOf(char, startIndex)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the index within this string of the last occurrence of the specified [string], starting from the specified [startIndex].
|
||||
*
|
||||
* @param startIndex The index of character to start searching at. The search proceeds backward toward the beginning of the string.
|
||||
* @param ignoreCase `true` to ignore character case when matching a string. By default `false`.
|
||||
* @returns An index of the first occurrence of [string] or -1 if none is found.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.lastIndexOf(string: String, startIndex: Int = lastIndex, ignoreCase: Boolean = false): Int {
|
||||
return if (ignoreCase)
|
||||
lastIndexOfAny(listOf(string), startIndex, ignoreCase)
|
||||
else
|
||||
nativeLastIndexOf(string, startIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if this string contains the specified sequence of characters as a substring.
|
||||
*
|
||||
* @param ignoreCase `true` to ignore character case when comparing strings. By default `false`.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public operator fun String.contains(seq: CharSequence, ignoreCase: Boolean = false): Boolean =
|
||||
indexOf(seq.toString(), ignoreCase = ignoreCase) >= 0
|
||||
|
||||
|
||||
/**
|
||||
* Returns `true` if this string contains the specified character.
|
||||
*
|
||||
* @param ignoreCase `true` to ignore character case when comparing characters. By default `false`.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public operator fun String.contains(char: Char, ignoreCase: Boolean = false): Boolean =
|
||||
indexOf(char, ignoreCase = ignoreCase) >= 0
|
||||
|
||||
|
||||
|
||||
|
||||
// split
|
||||
|
||||
/**
|
||||
* Splits this string to a sequence of strings around occurrences of the specified [delimiters].
|
||||
*
|
||||
* @param delimiters One or more strings to be used as delimiters.
|
||||
* @param ignoreCase `true` to ignore character case when matching a delimiter. By default `false`.
|
||||
* @param limit The maximum number of substrings to return. Zero by default means no limit is set.
|
||||
*
|
||||
* To avoid ambiguous results when strings in [delimiters] have characters in common, this method proceeds from
|
||||
* the beginning to the end of this string, and finds at each position the first element in [delimiters]
|
||||
* that matches this string at that position.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.splitToSequence(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): Sequence<String> =
|
||||
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit)
|
||||
|
||||
/**
|
||||
* Splits this string to a list of strings around occurrences of the specified [delimiters].
|
||||
*
|
||||
* @param delimiters One or more strings to be used as delimiters.
|
||||
* @param ignoreCase `true` to ignore character case when matching a delimiter. By default `false`.
|
||||
* @param limit The maximum number of substrings to return. Zero by default means no limit is set.
|
||||
*
|
||||
* To avoid ambiguous results when strings in [delimiters] have characters in common, this method proceeds from
|
||||
* the beginning to the end of this string, and matches at each position the first element in [delimiters]
|
||||
* that is equal to a delimiter in this instance at that position.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.split(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): List<String> =
|
||||
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList()
|
||||
|
||||
/**
|
||||
* Splits this string to a sequence of strings around occurrences of the specified [delimiters].
|
||||
*
|
||||
* @param delimiters One or more characters to be used as delimiters.
|
||||
* @param ignoreCase `true` to ignore character case when matching a delimiter. By default `false`.
|
||||
* @param limit The maximum number of substrings to return.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.splitToSequence(vararg delimiters: Char, ignoreCase: Boolean = false, limit: Int = 0): Sequence<String> =
|
||||
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit)
|
||||
|
||||
/**
|
||||
* Splits this string to a list of strings around occurrences of the specified [delimiters].
|
||||
*
|
||||
* @param delimiters One or more characters to be used as delimiters.
|
||||
* @param ignoreCase `true` to ignore character case when matching a delimiter. By default `false`.
|
||||
* @param limit The maximum number of substrings to return.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.split(vararg delimiters: Char, ignoreCase: Boolean = false, limit: Int = 0): List<String> =
|
||||
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList()
|
||||
|
||||
/**
|
||||
* Splits this string around matches of the given regular expression.
|
||||
*
|
||||
* @param limit Non-negative value specifying the maximum number of substrings to return.
|
||||
* Zero by default means no limit is set.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.split(pattern: Regex, limit: Int = 0): List<String> = pattern.split(this, limit)
|
||||
|
||||
/**
|
||||
* Splits this string to a sequence of lines delimited by any of the following character sequences: CRLF, LF or CR.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.lineSequence(): Sequence<String> = lineSequence()
|
||||
|
||||
/**
|
||||
* * Splits this string to a list of lines delimited by any of the following character sequences: CRLF, LF or CR.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.lines(): List<String> = lineSequence().toList()
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("StringsKt")
|
||||
|
||||
package kotlin
|
||||
|
||||
import java.io.StringReader
|
||||
import java.util.regex.Pattern
|
||||
import java.nio.charset.Charset
|
||||
import java.util.*
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns `true` if this string is equal to [anotherString], optionally ignoring character case.
|
||||
*
|
||||
* @param ignoreCase `true` to ignore character case when comparing strings. By default `false`.
|
||||
*/
|
||||
public fun String.equals(anotherString: String, ignoreCase: Boolean = false): Boolean {
|
||||
return if (!ignoreCase)
|
||||
(this as java.lang.String).equals(anotherString)
|
||||
else
|
||||
(this as java.lang.String).equalsIgnoreCase(anotherString)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new string with all occurrences of [oldChar] replaced with [newChar].
|
||||
*/
|
||||
public fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String {
|
||||
if (!ignoreCase)
|
||||
return (this as java.lang.String).replace(oldChar, newChar)
|
||||
else
|
||||
return splitToSequence(oldChar, ignoreCase = ignoreCase).joinToString(separator = newChar.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string
|
||||
* with the specified [newValue] string.
|
||||
*/
|
||||
public fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String =
|
||||
splitToSequence(oldValue, ignoreCase = ignoreCase).joinToString(separator = newValue)
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new string with the first occurrence of [oldChar] replaced with [newChar].
|
||||
*/
|
||||
public fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String {
|
||||
val index = indexOf(oldChar, ignoreCase = ignoreCase)
|
||||
return if (index < 0) this else this.replaceRange(index, index + 1, newChar.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new string obtained by replacing the first occurrence of the [oldValue] substring in this string
|
||||
* with the specified [newValue] string.
|
||||
*/
|
||||
public fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean = false): String {
|
||||
val index = indexOf(oldValue, ignoreCase = ignoreCase)
|
||||
return if (index < 0) this else this.replaceRange(index, index + oldValue.length(), newValue)
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Splits this string around matches of the given regular expression.
|
||||
|
||||
* @param limit Non-negative value specifying the maximum number of substrings to return.
|
||||
* Zero by default means no limit is set.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.split(regex: Pattern, limit: Int = 0): List<String>
|
||||
{
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit" } )
|
||||
return regex.split(this, if (limit == 0) -1 else limit).asList()
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/**
|
||||
* Compares two strings lexicographically, optionally ignoring case differences.
|
||||
*/
|
||||
public fun String.compareTo(other: String, ignoreCase: Boolean = false): Int {
|
||||
if (ignoreCase)
|
||||
return (this as java.lang.String).compareToIgnoreCase(other)
|
||||
else
|
||||
return (this as java.lang.String).compareTo(other)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new string obtained by concatenating this string and the specified string.
|
||||
*/
|
||||
public fun String.concat(str: String): String = (this as java.lang.String).concat(str)
|
||||
|
||||
/**
|
||||
* Returns `true` if this string is equal to the contents of the specified CharSequence.
|
||||
*/
|
||||
public fun String.contentEquals(cs: CharSequence): Boolean = (this as java.lang.String).contentEquals(cs)
|
||||
|
||||
/**
|
||||
* Returns `true` if this string is equal to the contents of the specified StringBuffer.
|
||||
*/
|
||||
public fun String.contentEquals(sb: StringBuffer): Boolean = (this as java.lang.String).contentEquals(sb)
|
||||
|
||||
*/
|
||||
/**
|
||||
* Returns `true` if this string is empty or consists solely of whitespace characters.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.isBlank(): Boolean = length() == 0 || all { it.isWhitespace() }
|
||||
|
||||
/*
|
||||
|
||||
/**
|
||||
* Returns a subsequence of this sequence specified by given [range].
|
||||
*/
|
||||
public fun CharSequence.slice(range: IntRange): CharSequence {
|
||||
return subSequence(range.start, range.end + 1) // inclusive
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of this string having its first letter uppercased, or the original string,
|
||||
* if it's empty or already starts with an upper case letter.
|
||||
*
|
||||
* @sample test.text.StringTest.capitalize
|
||||
*/
|
||||
public fun String.capitalize(): String {
|
||||
return if (isNotEmpty() && charAt(0).isLowerCase()) substring(0, 1).toUpperCase() + substring(1) else this
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of this string having its first letter lowercased, or the original string,
|
||||
* if it's empty or already starts with a lower case letter.
|
||||
*
|
||||
* @sample test.text.StringTest.decapitalize
|
||||
*/
|
||||
public fun String.decapitalize(): String {
|
||||
return if (isNotEmpty() && charAt(0).isUpperCase()) substring(0, 1).toLowerCase() + substring(1) else this
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Repeats a given string [n] times.
|
||||
* @throws [IllegalArgumentException] when n < 0.
|
||||
* @sample test.text.StringJVMTest.repeat
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.repeat(n: Int): String {
|
||||
if (n < 0)
|
||||
throw IllegalArgumentException("Value should be non-negative, but was $n")
|
||||
|
||||
val sb = StringBuilder()
|
||||
for (i in 1..n) {
|
||||
sb.append(this)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Appends the contents of this string, excluding the first characters that satisfy the given [predicate],
|
||||
* to the given Appendable.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public inline fun <T : Appendable> String.dropWhileTo(result: T, predicate: (Char) -> Boolean): T {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.append(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the first characters from this string that satisfy the given [predicate] to the given Appendable.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public inline fun <T : Appendable> String.takeWhileTo(result: T, predicate: (Char) -> Boolean): T {
|
||||
for (c in this) if (predicate(c)) result.append(c) else break
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
return true
|
||||
"""
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("none(predicate: (T) -> Boolean)") {
|
||||
@@ -29,7 +30,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
return true
|
||||
"""
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("none()") {
|
||||
@@ -41,7 +43,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
return true
|
||||
"""
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("any(predicate: (T) -> Boolean)") {
|
||||
@@ -55,7 +58,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
return false
|
||||
"""
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("any()") {
|
||||
@@ -67,7 +71,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
return false
|
||||
"""
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("count(predicate: (T) -> Boolean)") {
|
||||
@@ -82,7 +87,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
return count
|
||||
"""
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("count()") {
|
||||
@@ -95,8 +101,9 @@ fun aggregates(): List<GenericFunction> {
|
||||
return count
|
||||
"""
|
||||
}
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
doc(CharSequences) { "Returns the length of this char sequence."}
|
||||
body(CharSequences) {
|
||||
body(CharSequences, Strings) {
|
||||
"return length"
|
||||
}
|
||||
body(Maps, Collections, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
@@ -106,7 +113,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
|
||||
templates add f("sumBy(selector: (T) -> Int)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
include(CharSequences, Strings)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
doc { f -> "Returns the sum of all values produced by [selector] function applied to each ${f.element} in the ${f.collection}." }
|
||||
returns("Int")
|
||||
body {
|
||||
@@ -122,7 +130,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
|
||||
templates add f("sumByDouble(selector: (T) -> Double)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
include(CharSequences, Strings)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
doc { f -> "Returns the sum of all values produced by [selector] function applied to each ${f.element} in the ${f.collection}." }
|
||||
returns("Double")
|
||||
body {
|
||||
@@ -154,7 +163,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
return min
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
@@ -192,7 +202,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
return minElem
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
|
||||
@@ -257,7 +268,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
|
||||
@@ -296,7 +308,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
return maxElem
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
|
||||
@@ -345,7 +358,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
templates add f("fold(initial: R, operation: (R, T) -> R)") {
|
||||
inline(true)
|
||||
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each ${f.element}." }
|
||||
typeParam("R")
|
||||
returns("R")
|
||||
@@ -361,7 +375,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
templates add f("foldRight(initial: R, operation: (T, R) -> R)") {
|
||||
inline(true)
|
||||
|
||||
only(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
only(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
doc { f -> "Accumulates value starting with [initial] value and applying [operation] from right to left to each ${f.element} and current accumulator value." }
|
||||
typeParam("R")
|
||||
returns("R")
|
||||
@@ -380,7 +395,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
|
||||
templates add f("reduce(operation: (T, T) -> T)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
exclude(ArraysOfObjects, Iterables, Sequences)
|
||||
|
||||
doc { f -> "Accumulates value starting with the first ${f.element} and applying [operation] from left to right to current accumulator value and each ${f.element}." }
|
||||
@@ -424,7 +440,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
templates add f("reduceRight(operation: (T, T) -> T)") {
|
||||
inline(true)
|
||||
|
||||
only(CharSequences, ArraysOfPrimitives)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
only(CharSequences, Strings, ArraysOfPrimitives)
|
||||
doc { f -> "Accumulates value starting with last ${f.element} and applying [operation] from right to left to each ${f.element} and current accumulator value." }
|
||||
returns("T")
|
||||
body {
|
||||
@@ -475,12 +492,14 @@ fun aggregates(): List<GenericFunction> {
|
||||
for (element in this) action(element)
|
||||
"""
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("forEachIndexed(action: (Int, T) -> Unit)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Performs the given [action] on each ${f.element}, providing sequential index with the ${f.element}." }
|
||||
returns("Unit")
|
||||
body {
|
||||
|
||||
@@ -69,6 +69,27 @@ fun comparables(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("coerceIn(range: Range<T>)") {
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives)
|
||||
only(numericPrimitives.filterNot { it.isIntegral() })
|
||||
returns("SELF")
|
||||
deprecate { forBinaryCompatibility } // force use generic overload instead
|
||||
doc {
|
||||
"""
|
||||
Ensures that this value lies in the specified [range].
|
||||
|
||||
@return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
|
||||
"""
|
||||
}
|
||||
body {
|
||||
"""
|
||||
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.")
|
||||
return if (this < range.start) range.start else if (this > range.end) range.end else this
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("coerceIn(range: ClosedRange<T>)") {
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives, Generic)
|
||||
|
||||
@@ -228,7 +228,8 @@ fun elements(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(Lists, CharSequences, ArraysOfPrimitives, ArraysOfObjects) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(Lists, CharSequences, Strings, ArraysOfPrimitives, ArraysOfObjects) {
|
||||
"""
|
||||
for (index in indices) {
|
||||
if (predicate(this[index])) {
|
||||
@@ -258,7 +259,8 @@ fun elements(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(Lists, CharSequences, ArraysOfPrimitives, ArraysOfObjects) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(Lists, CharSequences, Strings, ArraysOfPrimitives, ArraysOfObjects) {
|
||||
"""
|
||||
for (index in indices.reversed()) {
|
||||
if (predicate(this[index])) {
|
||||
@@ -287,7 +289,8 @@ fun elements(): List<GenericFunction> {
|
||||
return elementAtOrElse(index) { throw IndexOutOfBoundsException("Sequence doesn't contain element at index $index.") }
|
||||
"""
|
||||
}
|
||||
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return get(index)
|
||||
"""
|
||||
@@ -327,8 +330,9 @@ fun elements(): List<GenericFunction> {
|
||||
return defaultValue(index)
|
||||
"""
|
||||
}
|
||||
inline(true, CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
inline(true, CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
"""
|
||||
@@ -339,7 +343,8 @@ fun elements(): List<GenericFunction> {
|
||||
doc { f -> "Returns ${f.element.prefixWithArticle()} at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this ${f.collection}." }
|
||||
returns("T")
|
||||
inline(true)
|
||||
only(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
only(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
body {
|
||||
"""
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
@@ -381,7 +386,8 @@ fun elements(): List<GenericFunction> {
|
||||
return null
|
||||
"""
|
||||
}
|
||||
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else null
|
||||
"""
|
||||
@@ -391,7 +397,8 @@ fun elements(): List<GenericFunction> {
|
||||
templates add f("getOrNull(index: Int)") {
|
||||
doc { f -> "Returns ${f.element.prefixWithArticle()} at the given [index] or `null` if the [index] is out of bounds of this ${f.collection}." }
|
||||
returns("T?")
|
||||
only(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
only(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
body {
|
||||
"""
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else null
|
||||
@@ -423,7 +430,8 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
"""
|
||||
}
|
||||
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
@@ -460,7 +468,8 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
"""
|
||||
}
|
||||
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return if (isEmpty()) null else this[0]
|
||||
"""
|
||||
@@ -478,7 +487,8 @@ fun elements(): List<GenericFunction> {
|
||||
templates add f("first(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> """Returns the first ${f.element} matching the given [predicate].
|
||||
@throws [NoSuchElementException] if no such ${f.element} is found.""" }
|
||||
returns("T")
|
||||
@@ -493,7 +503,8 @@ fun elements(): List<GenericFunction> {
|
||||
templates add f("firstOrNull(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Returns the first ${f.element} matching the given [predicate], or `null` if ${f.element} was not found." }
|
||||
returns("T?")
|
||||
body {
|
||||
@@ -506,7 +517,8 @@ fun elements(): List<GenericFunction> {
|
||||
|
||||
templates add f("find(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Returns the first ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
|
||||
returns("T?")
|
||||
body { "return firstOrNull(predicate)"}
|
||||
@@ -548,7 +560,8 @@ fun elements(): List<GenericFunction> {
|
||||
return last
|
||||
"""
|
||||
}
|
||||
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
@@ -587,7 +600,8 @@ fun elements(): List<GenericFunction> {
|
||||
return last
|
||||
"""
|
||||
}
|
||||
body(CharSequences) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
return if (isEmpty()) null else this[length - 1]
|
||||
"""
|
||||
@@ -602,7 +616,8 @@ fun elements(): List<GenericFunction> {
|
||||
templates add f("last(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> """Returns the last ${f.element} matching the given [predicate].
|
||||
@throws [NoSuchElementException] if no such ${f.element} is found.""" }
|
||||
returns("T")
|
||||
@@ -627,7 +642,7 @@ fun elements(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(CharSequences, ArraysOfPrimitives, ArraysOfObjects, Lists) {
|
||||
body(CharSequences, Strings, ArraysOfPrimitives, ArraysOfObjects, Lists) {
|
||||
"""
|
||||
for (index in this.indices.reversed()) {
|
||||
val element = this[index]
|
||||
@@ -640,7 +655,8 @@ fun elements(): List<GenericFunction> {
|
||||
|
||||
templates add f("lastOrNull(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
|
||||
returns("T?")
|
||||
body { f ->
|
||||
@@ -661,7 +677,7 @@ fun elements(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(CharSequences, ArraysOfPrimitives, ArraysOfObjects, Lists) {
|
||||
body(CharSequences, Strings, ArraysOfPrimitives, ArraysOfObjects, Lists) {
|
||||
"""
|
||||
for (index in this.indices.reversed()) {
|
||||
val element = this[index]
|
||||
@@ -674,7 +690,8 @@ fun elements(): List<GenericFunction> {
|
||||
|
||||
templates add f("findLast(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
include(Lists, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Lists, CharSequences, Strings)
|
||||
doc { f -> "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
|
||||
returns("T?")
|
||||
body { "return lastOrNull(predicate)"}
|
||||
@@ -714,7 +731,8 @@ fun elements(): List<GenericFunction> {
|
||||
return single
|
||||
"""
|
||||
}
|
||||
body(CharSequences) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
return when (length) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
@@ -764,7 +782,8 @@ fun elements(): List<GenericFunction> {
|
||||
return single
|
||||
"""
|
||||
}
|
||||
body(CharSequences) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
return if (length == 1) this[0] else null
|
||||
"""
|
||||
@@ -778,7 +797,8 @@ fun elements(): List<GenericFunction> {
|
||||
|
||||
templates add f("single(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Returns the single ${f.element} matching the given [predicate], or throws exception if there is no or more than one matching ${f.element}." }
|
||||
returns("T")
|
||||
body {
|
||||
@@ -800,7 +820,8 @@ fun elements(): List<GenericFunction> {
|
||||
|
||||
templates add f("singleOrNull(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Returns the single ${f.element} matching the given [predicate], or `null` if ${f.element} was not found or more than one ${f.element} was found." }
|
||||
returns("T?")
|
||||
body {
|
||||
|
||||
@@ -384,7 +384,8 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(CharSequences) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
for (index in 0..length - 1) {
|
||||
val element = get(index)
|
||||
@@ -479,8 +480,9 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
doc(CharSequences) { "Appends all characters not matching the given [predicate] to the given [destination]." }
|
||||
body(CharSequences) {
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
for (element in this) if (!predicate(element)) destination.append(element)
|
||||
return destination
|
||||
|
||||
@@ -556,7 +556,8 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("zip(other: CharSequence, transform: (Char, Char) -> V)") {
|
||||
only(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
only(CharSequences, Strings)
|
||||
doc {
|
||||
"""
|
||||
Returns a list of values built from characters of both char sequences with same indexes using provided [transform]. List has length of shortest char sequence.
|
||||
@@ -598,7 +599,8 @@ fun generators(): List<GenericFunction> {
|
||||
|
||||
templates add f("zip(other: String)") {
|
||||
infix(true)
|
||||
only(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
only(CharSequences, Strings)
|
||||
deprecate { forBinaryCompatibility }
|
||||
returns("List<Pair<Char, Char>>")
|
||||
body {
|
||||
|
||||
@@ -6,7 +6,8 @@ fun mapping(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
templates add f("withIndex()") {
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Returns a ${if (f == Sequences) f.mapResult else "lazy [Iterable]"} of [IndexedValue] for each ${f.element} of the original ${f.collection}." }
|
||||
returns("Iterable<IndexedValue<T>>")
|
||||
body {
|
||||
@@ -40,7 +41,8 @@ fun mapping(): List<GenericFunction> {
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"return mapIndexedTo(ArrayList<R>(size), transform)"
|
||||
}
|
||||
body(CharSequences) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"return mapIndexedTo(ArrayList<R>(length), transform)"
|
||||
}
|
||||
inline(false, Sequences)
|
||||
@@ -67,7 +69,8 @@ fun mapping(): List<GenericFunction> {
|
||||
body(ArraysOfObjects, ArraysOfPrimitives, Maps) {
|
||||
"return mapTo(ArrayList<R>(size), transform)"
|
||||
}
|
||||
body(CharSequences) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"return mapTo(ArrayList<R>(length), transform)"
|
||||
}
|
||||
|
||||
@@ -146,7 +149,8 @@ fun mapping(): List<GenericFunction> {
|
||||
return destination
|
||||
"""
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("mapIndexedTo(destination: C, transform: (Int, T) -> R)") {
|
||||
@@ -170,8 +174,9 @@ fun mapping(): List<GenericFunction> {
|
||||
return destination
|
||||
"""
|
||||
}
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
deprecate(Maps) { Deprecation("Use entries.mapIndexedTo instead.", replaceWith = "this.entries.mapIndexedTo(destination, transform)") }
|
||||
include(Maps, CharSequences)
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("mapNotNullTo(destination: C, transform: (T) -> R?)") {
|
||||
@@ -226,7 +231,8 @@ fun mapping(): List<GenericFunction> {
|
||||
body {
|
||||
"return flatMapTo(ArrayList<R>(), transform)"
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("flatMap(transform: (T) -> Sequence<R>)") {
|
||||
@@ -255,7 +261,8 @@ fun mapping(): List<GenericFunction> {
|
||||
return destination
|
||||
"""
|
||||
}
|
||||
include(Maps, CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(Maps, CharSequences, Strings)
|
||||
}
|
||||
|
||||
templates add f("flatMapTo(destination: C, transform: (T) -> Sequence<R>)") {
|
||||
@@ -280,7 +287,8 @@ fun mapping(): List<GenericFunction> {
|
||||
templates add f("groupBy(selector: (T) -> K)") {
|
||||
inline(true)
|
||||
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Returns a map of the ${f.element}s in original ${f.collection} grouped by the key returned by the given [selector] function." }
|
||||
typeParam("K")
|
||||
returns("Map<K, List<T>>")
|
||||
@@ -290,7 +298,8 @@ fun mapping(): List<GenericFunction> {
|
||||
templates add f("groupByTo(map: MutableMap<K, MutableList<T>>, selector: (T) -> K)") {
|
||||
inline(true)
|
||||
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
typeParam("K")
|
||||
doc { f -> "Appends ${f.element}s from original ${f.collection} grouped by the key returned by the given [selector] function to the given [map]." }
|
||||
returns("Map<K, MutableList<T>>")
|
||||
|
||||
@@ -14,22 +14,32 @@ fun ranges(): List<GenericFunction> {
|
||||
fun <T> Collection<T>.permutations(): List<Pair<T, T>> = flatMap { a -> map { b -> a to b } }
|
||||
|
||||
templates add f("reversed()") {
|
||||
only(ProgressionsOfPrimitives)
|
||||
only(RangesOfPrimitives, ProgressionsOfPrimitives)
|
||||
only(rangePrimitives)
|
||||
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range in the opposite direction with the same step." }
|
||||
doc(RangesOfPrimitives) { "Returns a progression that goes over this range in reverse direction." }
|
||||
returns("TProgression")
|
||||
deprecate(RangesOfPrimitives) { forBinaryCompatibility }
|
||||
body(RangesOfPrimitives) {
|
||||
"return TProgression.fromClosedRange(last, first, -ONE)"
|
||||
}
|
||||
body(ProgressionsOfPrimitives) {
|
||||
"return TProgression.fromClosedRange(last, first, -increment)"
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("reversed()") {
|
||||
only(ProgressionsOfPrimitives)
|
||||
only(RangesOfPrimitives, ProgressionsOfPrimitives)
|
||||
only(defaultPrimitives - PrimitiveType.Boolean - rangePrimitives - floatingPointPrimitives)
|
||||
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range in the opposite direction with the same step." }
|
||||
doc(RangesOfPrimitives) { "Returns a progression that goes over this range in reverse direction." }
|
||||
returns("TProgression")
|
||||
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING))
|
||||
deprecate(RangesOfPrimitives) { forBinaryCompatibility }
|
||||
annotations("""@Suppress("DEPRECATION_ERROR")""")
|
||||
body(RangesOfPrimitives) {
|
||||
"return TProgression.fromClosedRange(last, first, -ONE)"
|
||||
}
|
||||
body(ProgressionsOfPrimitives) {
|
||||
"return TProgression.fromClosedRange(last, first, -increment)"
|
||||
}
|
||||
@@ -38,10 +48,18 @@ fun ranges(): List<GenericFunction> {
|
||||
templates add f("step(step: SUM)") {
|
||||
infix(true)
|
||||
|
||||
only(ProgressionsOfPrimitives)
|
||||
only(RangesOfPrimitives, ProgressionsOfPrimitives)
|
||||
only(rangePrimitives)
|
||||
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range with the given step." }
|
||||
doc(RangesOfPrimitives) { "Returns a progression that goes over this range with given step." }
|
||||
returns("TProgression")
|
||||
deprecate(RangesOfPrimitives) { forBinaryCompatibility }
|
||||
body(RangesOfPrimitives) {
|
||||
"""
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return TProgression.fromClosedRange(first, last, step)
|
||||
"""
|
||||
}
|
||||
body(ProgressionsOfPrimitives) {
|
||||
"""
|
||||
checkStepIsPositive(step > 0, step)
|
||||
@@ -53,12 +71,27 @@ fun ranges(): List<GenericFunction> {
|
||||
templates add f("step(step: SUM)") {
|
||||
infix(true)
|
||||
|
||||
only(ProgressionsOfPrimitives)
|
||||
only(RangesOfPrimitives, ProgressionsOfPrimitives)
|
||||
only(defaultPrimitives - PrimitiveType.Boolean - rangePrimitives - floatingPointPrimitives)
|
||||
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range with the given step." }
|
||||
doc(RangesOfPrimitives) { "Returns a progression that goes over this range with given step." }
|
||||
returns("TProgression")
|
||||
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING))
|
||||
deprecate(RangesOfPrimitives) { forBinaryCompatibility }
|
||||
annotations("""@Suppress("DEPRECATION_ERROR")""")
|
||||
body(RangesOfPrimitives) {
|
||||
"""
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return TProgression.fromClosedRange(first, last, step)
|
||||
"""
|
||||
}
|
||||
bodyForTypes(RangesOfPrimitives, PrimitiveType.Float, PrimitiveType.Double) {
|
||||
"""
|
||||
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.")
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return TProgression.fromClosedRange(start, end, step)
|
||||
"""
|
||||
}
|
||||
body(ProgressionsOfPrimitives) {
|
||||
"""
|
||||
checkStepIsPositive(step > 0, step)
|
||||
@@ -102,12 +135,34 @@ fun ranges(): List<GenericFunction> {
|
||||
body { "return $progressionType.fromClosedRange($fromExpr, $toExpr, $incrementExpr)" }
|
||||
}
|
||||
|
||||
fun downToDeprecated(fromType: PrimitiveType, toType: PrimitiveType) = f("`-downTo`(to: $toType)") {
|
||||
deprecate { forBinaryCompatibility }
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives)
|
||||
only(fromType)
|
||||
val elementType = maxByCapacity(fromType, toType)
|
||||
val progressionType = elementType.name + "Progression"
|
||||
returns(progressionType)
|
||||
annotations("""@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]""")
|
||||
val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()"
|
||||
val toExpr = if (elementType == toType) "to" else "to.to$elementType()"
|
||||
val incrementExpr = when (elementType) {
|
||||
PrimitiveType.Long -> "-1L"
|
||||
PrimitiveType.Float -> "-1.0F"
|
||||
PrimitiveType.Double -> "-1.0"
|
||||
else -> "-1"
|
||||
}
|
||||
|
||||
body { "return $progressionType.fromClosedRange($fromExpr, $toExpr, $incrementExpr)" }
|
||||
}
|
||||
|
||||
val numericPrimitives = PrimitiveType.numericPrimitives
|
||||
val numericPermutations = numericPrimitives.permutations()
|
||||
val primitivePermutations = numericPermutations + (PrimitiveType.Char to PrimitiveType.Char)
|
||||
val integralPermutations = primitivePermutations.filter { it.first.isIntegral() && it.second.isIntegral() }
|
||||
|
||||
templates addAll integralPermutations.map { downTo(it.first, it.second) }
|
||||
templates addAll listOf(PrimitiveType.Byte, PrimitiveType.Short).permutations().map { downToDeprecated(it.first, it.second) }
|
||||
|
||||
fun until(fromType: PrimitiveType, toType: PrimitiveType) = f("until(to: $toType)") {
|
||||
infix(true)
|
||||
@@ -152,7 +207,36 @@ fun ranges(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
fun untilDeprecated(fromType: PrimitiveType, toType: PrimitiveType) = f("`-until`(to: $toType)") {
|
||||
deprecate { forBinaryCompatibility }
|
||||
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives)
|
||||
only(fromType)
|
||||
val elementType = maxByCapacity(fromType, toType)
|
||||
val progressionType = elementType.name + "Range"
|
||||
returns(progressionType)
|
||||
annotations("""@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]""")
|
||||
|
||||
val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()"
|
||||
|
||||
if (elementType == toType) {
|
||||
// hack to work around incorrect char overflow behavior in JVM and int overflow behavior in JS
|
||||
val toExpr = "to"
|
||||
body {
|
||||
"""
|
||||
val to_ = ($toExpr - 1).to$elementType()
|
||||
if (to_ > to) throw IllegalArgumentException("The to argument value '${'$'}to' was too small.")
|
||||
return $progressionType($fromExpr, to_)
|
||||
"""
|
||||
}
|
||||
} else {
|
||||
body { "return $progressionType($fromExpr, (to.to$elementType() - 1).to$elementType())" }
|
||||
}
|
||||
}
|
||||
|
||||
templates addAll integralPermutations.map { until(it.first, it.second) }
|
||||
templates addAll listOf(PrimitiveType.Byte, PrimitiveType.Short).permutations().map { untilDeprecated(it.first, it.second) }
|
||||
|
||||
fun containsDeprecated(rangeType: PrimitiveType, itemType: PrimitiveType) = f("contains(item: $itemType)") {
|
||||
operator(true)
|
||||
|
||||
@@ -30,7 +30,8 @@ fun sequences(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(CharSequences) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
if (this is String && isEmpty()) return emptySequence()
|
||||
return object : Sequence<T> {
|
||||
|
||||
@@ -6,7 +6,8 @@ fun snapshots(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
templates add f("toCollection(destination: C)") {
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Appends all ${f.element}s to the given [destination] collection." }
|
||||
returns("C")
|
||||
typeParam("C : MutableCollection<in T>")
|
||||
@@ -25,7 +26,8 @@ fun snapshots(): List<GenericFunction> {
|
||||
returns("Set<T>")
|
||||
body { "return toCollection(LinkedHashSet<T>(mapCapacity(collectionSizeOrDefault(12))))" }
|
||||
body(Sequences) { "return toCollection(LinkedHashSet<T>())" }
|
||||
body(CharSequences) { "return toCollection(LinkedHashSet<T>(mapCapacity(length)))" }
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) { "return toCollection(LinkedHashSet<T>(mapCapacity(length)))" }
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) { "return toCollection(LinkedHashSet<T>(mapCapacity(size)))" }
|
||||
}
|
||||
|
||||
@@ -34,12 +36,14 @@ fun snapshots(): List<GenericFunction> {
|
||||
returns("HashSet<T>")
|
||||
body { "return toCollection(HashSet<T>(mapCapacity(collectionSizeOrDefault(12))))" }
|
||||
body(Sequences) { "return toCollection(HashSet<T>())" }
|
||||
body(CharSequences) { "return toCollection(HashSet<T>(mapCapacity(length)))" }
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) { "return toCollection(HashSet<T>(mapCapacity(length)))" }
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) { "return toCollection(HashSet<T>(mapCapacity(size)))" }
|
||||
}
|
||||
|
||||
templates add f("toSortedSet()") {
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
typeParam("T: Comparable<T>")
|
||||
doc { f -> "Returns a [SortedSet] of all ${f.element}s." }
|
||||
returns("SortedSet<T>")
|
||||
@@ -72,7 +76,8 @@ fun snapshots(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
body(Collections) { "return ArrayList(this)" }
|
||||
body(CharSequences) { "return toCollection(ArrayList<T>(length))" }
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) { "return toCollection(ArrayList<T>(length))" }
|
||||
body(ArraysOfObjects) { "return ArrayList(this.asCollection())" }
|
||||
body(ArraysOfPrimitives) {
|
||||
"""
|
||||
@@ -98,7 +103,8 @@ fun snapshots(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("toList()") {
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
include(CharSequences, Strings)
|
||||
doc { f -> "Returns a [List] containing all ${f.element}s." }
|
||||
returns("List<T>")
|
||||
body { "return this.toArrayList()" }
|
||||
@@ -106,7 +112,9 @@ fun snapshots(): List<GenericFunction> {
|
||||
|
||||
templates add f("toMap(selector: (T) -> K)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(Strings) { "return toMapBy(selector)" }
|
||||
include(CharSequences, Strings)
|
||||
typeParam("K")
|
||||
returns("Map<K, T>")
|
||||
deprecate(Deprecation("Use toMapBy instead.", replaceWith = "toMapBy(selector)"))
|
||||
@@ -148,7 +156,8 @@ fun snapshots(): List<GenericFunction> {
|
||||
return result
|
||||
"""
|
||||
}
|
||||
body(CharSequences) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, T>(Math.max(capacity.toInt(), 16))
|
||||
@@ -206,7 +215,8 @@ fun snapshots(): List<GenericFunction> {
|
||||
return result
|
||||
"""
|
||||
}
|
||||
body(CharSequences) {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
|
||||
@@ -55,6 +55,17 @@ fun strings(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("joinTo(buffer: A, separator: String = \", \", prefix: String = \"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\", transform: ((T) -> String)? = null)") {
|
||||
deprecate { forBinaryCompatibility }
|
||||
typeParam("A : Appendable")
|
||||
returns { "A" }
|
||||
body {
|
||||
"""
|
||||
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("joinToString(separator: CharSequence = \", \", prefix: CharSequence = \"\", postfix: CharSequence = \"\", limit: Int = -1, truncated: CharSequence = \"...\", transform: ((T) -> CharSequence)? = null)") {
|
||||
doc {
|
||||
"""
|
||||
@@ -74,5 +85,15 @@ fun strings(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("joinToString(separator: String = \", \", prefix: String = \"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\", transform: ((T) -> String)? = null)") {
|
||||
deprecate { forBinaryCompatibility }
|
||||
returns("String")
|
||||
body {
|
||||
"""
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
return templates
|
||||
}
|
||||
Reference in New Issue
Block a user