Reformat stdlib: common code
#KT-5558
This commit is contained in:
@@ -20,7 +20,7 @@ public fun <T> compareValuesBy(a: T, b: T, vararg selectors: (T) -> Comparable<*
|
||||
return compareValuesByImpl(a, b, selectors)
|
||||
}
|
||||
|
||||
private fun <T> compareValuesByImpl(a: T, b: T, selectors: Array<out (T)->Comparable<*>?>): Int {
|
||||
private fun <T> compareValuesByImpl(a: T, b: T, selectors: Array<out (T) -> Comparable<*>?>): Int {
|
||||
for (fn in selectors) {
|
||||
val v1 = fn(a)
|
||||
val v2 = fn(b)
|
||||
@@ -92,7 +92,6 @@ public fun <T> compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator<T>
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a comparator using the function to transform value to a [Comparable] instance for comparison.
|
||||
*
|
||||
@@ -100,7 +99,7 @@ public fun <T> compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator<T>
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> compareBy(crossinline selector: (T) -> Comparable<*>?): Comparator<T> =
|
||||
Comparator { a, b -> compareValuesBy(a, b, selector) }
|
||||
Comparator { a, b -> compareValuesBy(a, b, selector) }
|
||||
|
||||
/**
|
||||
* Creates a comparator using the [selector] function to transform values being compared and then applying
|
||||
@@ -110,7 +109,7 @@ public inline fun <T> compareBy(crossinline selector: (T) -> Comparable<*>?): Co
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T, K> compareBy(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T> =
|
||||
Comparator { a, b -> compareValuesBy(a, b, comparator, selector) }
|
||||
Comparator { a, b -> compareValuesBy(a, b, comparator, selector) }
|
||||
|
||||
/**
|
||||
* Creates a descending comparator using the function to transform value to a [Comparable] instance for comparison.
|
||||
@@ -119,7 +118,7 @@ public inline fun <T, K> compareBy(comparator: Comparator<in K>, crossinline sel
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> compareByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator<T> =
|
||||
Comparator { a, b -> compareValuesBy(b, a, selector) }
|
||||
Comparator { a, b -> compareValuesBy(b, a, selector) }
|
||||
|
||||
/**
|
||||
* Creates a descending comparator using the [selector] function to transform values being compared and then applying
|
||||
@@ -131,7 +130,7 @@ public inline fun <T> compareByDescending(crossinline selector: (T) -> Comparabl
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T, K> compareByDescending(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T> =
|
||||
Comparator { a, b -> compareValuesBy(b, a, comparator, selector) }
|
||||
Comparator { a, b -> compareValuesBy(b, a, comparator, selector) }
|
||||
|
||||
/**
|
||||
* Creates a comparator comparing values after the primary comparator defined them equal. It uses
|
||||
@@ -141,10 +140,10 @@ public inline fun <T, K> compareByDescending(comparator: Comparator<in K>, cross
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> Comparator<T>.thenBy(crossinline selector: (T) -> Comparable<*>?): Comparator<T> =
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenBy.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else compareValuesBy(a, b, selector)
|
||||
}
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenBy.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else compareValuesBy(a, b, selector)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a comparator comparing values after the primary comparator defined them equal. It uses
|
||||
@@ -154,10 +153,10 @@ public inline fun <T> Comparator<T>.thenBy(crossinline selector: (T) -> Comparab
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T, K> Comparator<T>.thenBy(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T> =
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenBy.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else compareValuesBy(a, b, comparator, selector)
|
||||
}
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenBy.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else compareValuesBy(a, b, comparator, selector)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a descending comparator using the primary comparator and
|
||||
@@ -167,10 +166,10 @@ public inline fun <T, K> Comparator<T>.thenBy(comparator: Comparator<in K>, cros
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> Comparator<T>.thenByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator<T> =
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenByDescending.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else compareValuesBy(b, a, selector)
|
||||
}
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenByDescending.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else compareValuesBy(b, a, selector)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a descending comparator comparing values after the primary comparator defined them equal. It uses
|
||||
@@ -180,10 +179,10 @@ public inline fun <T> Comparator<T>.thenByDescending(crossinline selector: (T) -
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T, K> Comparator<T>.thenByDescending(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T> =
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenByDescending.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else compareValuesBy(b, a, comparator, selector)
|
||||
}
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenByDescending.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else compareValuesBy(b, a, comparator, selector)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -193,10 +192,10 @@ public inline fun <T, K> Comparator<T>.thenByDescending(comparator: Comparator<i
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> Comparator<T>.thenComparator(crossinline comparison: (a: T, b: T) -> Int): Comparator<T> =
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenComparator.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else comparison(a, b)
|
||||
}
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@thenComparator.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else comparison(a, b)
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines this comparator and the given [comparator] such that the latter is applied only
|
||||
@@ -205,10 +204,10 @@ public inline fun <T> Comparator<T>.thenComparator(crossinline comparison: (a: T
|
||||
* @sample samples.comparisons.Comparisons.then
|
||||
*/
|
||||
public infix fun <T> Comparator<T>.then(comparator: Comparator<in T>): Comparator<T> =
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@then.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else comparator.compare(a, b)
|
||||
}
|
||||
Comparator { a, b ->
|
||||
val previousCompare = this@then.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else comparator.compare(a, b)
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines this comparator and the given [comparator] such that the latter is applied only
|
||||
@@ -217,10 +216,10 @@ public infix fun <T> Comparator<T>.then(comparator: Comparator<in T>): Comparato
|
||||
* @sample samples.comparisons.Comparisons.thenDescending
|
||||
*/
|
||||
public infix fun <T> Comparator<T>.thenDescending(comparator: Comparator<in T>): Comparator<T> =
|
||||
Comparator<T> { a, b ->
|
||||
val previousCompare = this@thenDescending.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else comparator.compare(b, a)
|
||||
}
|
||||
Comparator<T> { a, b ->
|
||||
val previousCompare = this@thenDescending.compare(a, b)
|
||||
if (previousCompare != 0) previousCompare else comparator.compare(b, a)
|
||||
}
|
||||
|
||||
// Not so useful without type inference for receiver of expression
|
||||
/**
|
||||
@@ -229,15 +228,15 @@ public infix fun <T> Comparator<T>.thenDescending(comparator: Comparator<in T>):
|
||||
*
|
||||
* @sample samples.comparisons.Comparisons.nullsFirstLastWithComparator
|
||||
*/
|
||||
public fun <T: Any> nullsFirst(comparator: Comparator<in T>): Comparator<T?> =
|
||||
Comparator { a, b ->
|
||||
when {
|
||||
a === b -> 0
|
||||
a == null -> -1
|
||||
b == null -> 1
|
||||
else -> comparator.compare(a, b)
|
||||
}
|
||||
public fun <T : Any> nullsFirst(comparator: Comparator<in T>): Comparator<T?> =
|
||||
Comparator { a, b ->
|
||||
when {
|
||||
a === b -> 0
|
||||
a == null -> -1
|
||||
b == null -> 1
|
||||
else -> comparator.compare(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a comparator of nullable [Comparable] values
|
||||
@@ -246,7 +245,7 @@ public fun <T: Any> nullsFirst(comparator: Comparator<in T>): Comparator<T?> =
|
||||
* @sample samples.comparisons.Comparisons.nullsFirstLastComparator
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T: Comparable<T>> nullsFirst(): Comparator<T?> = nullsFirst(naturalOrder())
|
||||
public inline fun <T : Comparable<T>> nullsFirst(): Comparator<T?> = nullsFirst(naturalOrder())
|
||||
|
||||
/**
|
||||
* Extends the given [comparator] of non-nullable values to a comparator of nullable values
|
||||
@@ -254,15 +253,15 @@ public inline fun <T: Comparable<T>> nullsFirst(): Comparator<T?> = nullsFirst(n
|
||||
*
|
||||
* @sample samples.comparisons.Comparisons.nullsFirstLastWithComparator
|
||||
*/
|
||||
public fun <T: Any> nullsLast(comparator: Comparator<in T>): Comparator<T?> =
|
||||
Comparator { a, b ->
|
||||
when {
|
||||
a === b -> 0
|
||||
a == null -> 1
|
||||
b == null -> -1
|
||||
else -> comparator.compare(a, b)
|
||||
}
|
||||
public fun <T : Any> nullsLast(comparator: Comparator<in T>): Comparator<T?> =
|
||||
Comparator { a, b ->
|
||||
when {
|
||||
a === b -> 0
|
||||
a == null -> 1
|
||||
b == null -> -1
|
||||
else -> comparator.compare(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a comparator of nullable [Comparable] values
|
||||
@@ -271,21 +270,21 @@ public fun <T: Any> nullsLast(comparator: Comparator<in T>): Comparator<T?> =
|
||||
* @sample samples.comparisons.Comparisons.nullsFirstLastComparator
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T: Comparable<T>> nullsLast(): Comparator<T?> = nullsLast(naturalOrder())
|
||||
public inline fun <T : Comparable<T>> nullsLast(): Comparator<T?> = nullsLast(naturalOrder())
|
||||
|
||||
/**
|
||||
* Returns a comparator that compares [Comparable] objects in natural order.
|
||||
*
|
||||
* @sample samples.comparisons.Comparisons.naturalOrderComparator
|
||||
*/
|
||||
public fun <T: Comparable<T>> naturalOrder(): Comparator<T> = @Suppress("UNCHECKED_CAST") (NaturalOrderComparator as Comparator<T>)
|
||||
public fun <T : Comparable<T>> naturalOrder(): Comparator<T> = @Suppress("UNCHECKED_CAST") (NaturalOrderComparator as Comparator<T>)
|
||||
|
||||
/**
|
||||
* Returns a comparator that compares [Comparable] objects in reversed natural order.
|
||||
*
|
||||
* @sample samples.comparisons.Comparisons.nullsFirstLastWithComparator
|
||||
*/
|
||||
public fun <T: Comparable<T>> reverseOrder(): Comparator<T> = @Suppress("UNCHECKED_CAST") (ReverseOrderComparator as Comparator<T>)
|
||||
public fun <T : Comparable<T>> reverseOrder(): Comparator<T> = @Suppress("UNCHECKED_CAST") (ReverseOrderComparator as Comparator<T>)
|
||||
|
||||
/**
|
||||
* Returns a comparator that imposes the reverse ordering of this comparator.
|
||||
@@ -300,7 +299,7 @@ public fun <T> Comparator<T>.reversed(): Comparator<T> = when (this) {
|
||||
}
|
||||
|
||||
|
||||
private class ReversedComparator<T>(public val comparator: Comparator<T>): Comparator<T> {
|
||||
private class ReversedComparator<T>(public val comparator: Comparator<T>) : Comparator<T> {
|
||||
override fun compare(a: T, b: T): Int = comparator.compare(b, a)
|
||||
@Suppress("VIRTUAL_MEMBER_HIDDEN")
|
||||
fun reversed(): Comparator<T> = comparator
|
||||
@@ -312,7 +311,7 @@ private object NaturalOrderComparator : Comparator<Comparable<Any>> {
|
||||
fun reversed(): Comparator<Comparable<Any>> = ReverseOrderComparator
|
||||
}
|
||||
|
||||
private object ReverseOrderComparator: Comparator<Comparable<Any>> {
|
||||
private object ReverseOrderComparator : Comparator<Comparable<Any>> {
|
||||
override fun compare(a: Comparable<Any>, b: Comparable<Any>): Int = b.compareTo(a)
|
||||
@Suppress("VIRTUAL_MEMBER_HIDDEN")
|
||||
fun reversed(): Comparator<Comparable<Any>> = NaturalOrderComparator
|
||||
|
||||
@@ -30,19 +30,19 @@ public interface CoroutineContext {
|
||||
* The elements from this context with the same key as in the other one are dropped.
|
||||
*/
|
||||
public operator fun plus(context: CoroutineContext): CoroutineContext =
|
||||
if (context === EmptyCoroutineContext) this else // fast path -- avoid lambda creation
|
||||
context.fold(this) { acc, element ->
|
||||
val removed = acc.minusKey(element.key)
|
||||
if (removed === EmptyCoroutineContext) element else {
|
||||
// make sure interceptor is always last in the context (and thus is fast to get when present)
|
||||
val interceptor = removed[ContinuationInterceptor]
|
||||
if (interceptor == null) CombinedContext(removed, element) else {
|
||||
val left = removed.minusKey(ContinuationInterceptor)
|
||||
if (left === EmptyCoroutineContext) CombinedContext(element, interceptor) else
|
||||
CombinedContext(CombinedContext(left, element), interceptor)
|
||||
}
|
||||
if (context === EmptyCoroutineContext) this else // fast path -- avoid lambda creation
|
||||
context.fold(this) { acc, element ->
|
||||
val removed = acc.minusKey(element.key)
|
||||
if (removed === EmptyCoroutineContext) element else {
|
||||
// make sure interceptor is always last in the context (and thus is fast to get when present)
|
||||
val interceptor = removed[ContinuationInterceptor]
|
||||
if (interceptor == null) CombinedContext(removed, element) else {
|
||||
val left = removed.minusKey(ContinuationInterceptor)
|
||||
if (left === EmptyCoroutineContext) CombinedContext(element, interceptor) else
|
||||
CombinedContext(CombinedContext(left, element), interceptor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a context containing elements from this context, but without an element with
|
||||
@@ -62,13 +62,13 @@ public interface CoroutineContext {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public override operator fun <E : Element> get(key: Key<E>): E? =
|
||||
if (this.key === key) this as E else null
|
||||
if (this.key === key) this as E else null
|
||||
|
||||
public override fun <R> fold(initial: R, operation: (R, Element) -> R): R =
|
||||
operation(initial, this)
|
||||
operation(initial, this)
|
||||
|
||||
public override fun minusKey(key: Key<*>): CoroutineContext =
|
||||
if (this.key === key) EmptyCoroutineContext else this
|
||||
if (this.key === key) EmptyCoroutineContext else this
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ internal class CombinedContext(val left: CoroutineContext, val element: Element)
|
||||
}
|
||||
|
||||
public override fun <R> fold(initial: R, operation: (R, Element) -> R): R =
|
||||
operation(left.fold(initial, operation), element)
|
||||
operation(left.fold(initial, operation), element)
|
||||
|
||||
public override fun minusKey(key: Key<*>): CoroutineContext {
|
||||
element[key]?.let { return left }
|
||||
@@ -58,10 +58,10 @@ internal class CombinedContext(val left: CoroutineContext, val element: Element)
|
||||
}
|
||||
|
||||
private fun size(): Int =
|
||||
if (left is CombinedContext) left.size() + 1 else 2
|
||||
if (left is CombinedContext) left.size() + 1 else 2
|
||||
|
||||
private fun contains(element: Element): Boolean =
|
||||
get(element.key) == element
|
||||
get(element.key) == element
|
||||
|
||||
private fun containsAll(context: CombinedContext): Boolean {
|
||||
var cur = context
|
||||
@@ -77,12 +77,12 @@ internal class CombinedContext(val left: CoroutineContext, val element: Element)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
this === other || other is CombinedContext && other.size() == size() && other.containsAll(this)
|
||||
this === other || other is CombinedContext && other.size() == size() && other.containsAll(this)
|
||||
|
||||
override fun hashCode(): Int = left.hashCode() + element.hashCode()
|
||||
|
||||
override fun toString(): String =
|
||||
"[" + fold("") { acc, element ->
|
||||
if (acc.isEmpty()) element.toString() else acc + ", " + element
|
||||
} + "]"
|
||||
"[" + fold("") { acc, element ->
|
||||
if (acc.isEmpty()) element.toString() else acc + ", " + element
|
||||
} + "]"
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
@file:kotlin.jvm.JvmName("CoroutinesKt")
|
||||
|
||||
package kotlin.coroutines.experimental
|
||||
|
||||
import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED
|
||||
@@ -19,8 +20,8 @@ import kotlin.internal.InlineOnly
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public fun <R, T> (suspend R.() -> T).startCoroutine(
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
) {
|
||||
createCoroutineUnchecked(receiver, completion).resume(Unit)
|
||||
}
|
||||
@@ -32,8 +33,8 @@ public fun <R, T> (suspend R.() -> T).startCoroutine(
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public fun <T> (suspend () -> T).startCoroutine(
|
||||
completion: Continuation<T>
|
||||
public fun <T> (suspend () -> T).startCoroutine(
|
||||
completion: Continuation<T>
|
||||
) {
|
||||
createCoroutineUnchecked(completion).resume(Unit)
|
||||
}
|
||||
@@ -49,8 +50,8 @@ public fun <T> (suspend () -> T).startCoroutine(
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public fun <R, T> (suspend R.() -> T).createCoroutine(
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
): Continuation<Unit> = SafeContinuation(createCoroutineUnchecked(receiver, completion), COROUTINE_SUSPENDED)
|
||||
|
||||
/**
|
||||
@@ -64,7 +65,7 @@ public fun <R, T> (suspend R.() -> T).createCoroutine(
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public fun <T> (suspend () -> T).createCoroutine(
|
||||
completion: Continuation<T>
|
||||
completion: Continuation<T>
|
||||
): Continuation<Unit> = SafeContinuation(createCoroutineUnchecked(completion), COROUTINE_SUSPENDED)
|
||||
|
||||
/**
|
||||
@@ -77,11 +78,11 @@ public fun <T> (suspend () -> T).createCoroutine(
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public suspend inline fun <T> suspendCoroutine(crossinline block: (Continuation<T>) -> Unit): T =
|
||||
suspendCoroutineOrReturn { c: Continuation<T> ->
|
||||
val safe = SafeContinuation(c)
|
||||
block(safe)
|
||||
safe.getResult()
|
||||
}
|
||||
suspendCoroutineOrReturn { c: Continuation<T> ->
|
||||
val safe = SafeContinuation(c)
|
||||
block(safe)
|
||||
safe.getResult()
|
||||
}
|
||||
|
||||
/**
|
||||
* Continuation context of current coroutine.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("SequenceBuilderKt")
|
||||
|
||||
package kotlin.coroutines.experimental
|
||||
|
||||
import kotlin.*
|
||||
@@ -84,6 +85,7 @@ public abstract class SequenceBuilder<in T> internal constructor() {
|
||||
}
|
||||
|
||||
private typealias State = Int
|
||||
|
||||
private const val State_NotReady: State = 0
|
||||
private const val State_ManyNotReady: State = 1
|
||||
private const val State_ManyReady: State = 2
|
||||
@@ -129,7 +131,7 @@ private class SequenceBuilderIterator<T> : SequenceBuilder<T>(), Iterator<T>, Co
|
||||
}
|
||||
State_Ready -> {
|
||||
state = State_NotReady
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val result = nextValue as T
|
||||
nextValue = null
|
||||
return result
|
||||
|
||||
@@ -31,7 +31,7 @@ import kotlin.coroutines.experimental.*
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
public suspend inline fun <T> suspendCoroutineOrReturn(crossinline block: (Continuation<T>) -> Any?): T =
|
||||
suspendCoroutineUninterceptedOrReturn { cont -> block(cont.intercepted()) }
|
||||
suspendCoroutineUninterceptedOrReturn { cont -> block(cont.intercepted()) }
|
||||
|
||||
/**
|
||||
* Obtains the current continuation instance inside suspend functions and either suspends
|
||||
@@ -42,7 +42,7 @@ public suspend inline fun <T> suspendCoroutineOrReturn(crossinline block: (Conti
|
||||
@SinceKotlin("1.2")
|
||||
@kotlin.internal.InlineOnly
|
||||
public suspend inline fun <T> suspendCoroutineUninterceptedOrReturn(crossinline block: (Continuation<T>) -> Any?): T =
|
||||
throw NotImplementedError("Implementation of suspendCoroutineUninterceptedOrReturn is intrinsic")
|
||||
throw NotImplementedError("Implementation of suspendCoroutineUninterceptedOrReturn is intrinsic")
|
||||
|
||||
/**
|
||||
* Intercept continuation with [ContinuationInterceptor].
|
||||
@@ -50,7 +50,7 @@ public suspend inline fun <T> suspendCoroutineUninterceptedOrReturn(crossinline
|
||||
@SinceKotlin("1.2")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> Continuation<T>.intercepted(): Continuation<T> =
|
||||
throw NotImplementedError("Implementation of intercepted is intrinsic")
|
||||
throw NotImplementedError("Implementation of intercepted is intrinsic")
|
||||
|
||||
/**
|
||||
* Continuation context of current coroutine.
|
||||
|
||||
@@ -9,14 +9,17 @@ package kotlin.experimental
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun Byte.and(other: Byte): Byte = (this.toInt() and other.toInt()).toByte()
|
||||
|
||||
/** Performs a bitwise OR operation between the two values. */
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun Byte.or(other: Byte): Byte = (this.toInt() or other.toInt()).toByte()
|
||||
|
||||
/** Performs a bitwise XOR operation between the two values. */
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun Byte.xor(other: Byte): Byte = (this.toInt() xor other.toInt()).toByte()
|
||||
|
||||
/** Inverts the bits in this value. */
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@@ -27,14 +30,17 @@ public inline fun Byte.inv(): Byte = (this.toInt().inv()).toByte()
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun Short.and(other: Short): Short = (this.toInt() and other.toInt()).toShort()
|
||||
|
||||
/** Performs a bitwise OR operation between the two values. */
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun Short.or(other: Short): Short = (this.toInt() or other.toInt()).toShort()
|
||||
|
||||
/** Performs a bitwise XOR operation between the two values. */
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun Short.xor(other: Short): Short = (this.toInt() xor other.toInt()).toShort()
|
||||
|
||||
/** Inverts the bits in this value. */
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
|
||||
@@ -86,11 +86,11 @@ internal annotation class AccessibleLateinitPropertyLiteral
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
@SinceKotlin("1.2")
|
||||
internal annotation class RequireKotlin(
|
||||
val version: String,
|
||||
val message: String = "",
|
||||
val level: DeprecationLevel = DeprecationLevel.ERROR,
|
||||
val versionKind: RequireKotlinVersionKind = RequireKotlinVersionKind.LANGUAGE_VERSION,
|
||||
val errorCode: Int = -1
|
||||
val version: String,
|
||||
val message: String = "",
|
||||
val level: DeprecationLevel = DeprecationLevel.ERROR,
|
||||
val versionKind: RequireKotlinVersionKind = RequireKotlinVersionKind.LANGUAGE_VERSION,
|
||||
val errorCode: Int = -1
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ public object Delegates {
|
||||
*
|
||||
* @sample samples.properties.Delegates.notNullDelegate
|
||||
*/
|
||||
public fun <T: Any> notNull(): ReadWriteProperty<Any?, T> = NotNullVar()
|
||||
public fun <T : Any> notNull(): ReadWriteProperty<Any?, T> = NotNullVar()
|
||||
|
||||
/**
|
||||
* Returns a property delegate for a read/write property that calls a specified callback function when changed.
|
||||
@@ -30,7 +30,8 @@ public object Delegates {
|
||||
* @sample samples.properties.Delegates.observableDelegate
|
||||
*/
|
||||
public inline fun <T> observable(initialValue: T, crossinline onChange: (property: KProperty<*>, oldValue: T, newValue: T) -> Unit):
|
||||
ReadWriteProperty<Any?, T> = object : ObservableProperty<T>(initialValue) {
|
||||
ReadWriteProperty<Any?, T> =
|
||||
object : ObservableProperty<T>(initialValue) {
|
||||
override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) = onChange(property, oldValue, newValue)
|
||||
}
|
||||
|
||||
@@ -47,14 +48,15 @@ public object Delegates {
|
||||
* @sample samples.properties.Delegates.throwVetoableDelegate
|
||||
*/
|
||||
public inline fun <T> vetoable(initialValue: T, crossinline onChange: (property: KProperty<*>, oldValue: T, newValue: T) -> Boolean):
|
||||
ReadWriteProperty<Any?, T> = object : ObservableProperty<T>(initialValue) {
|
||||
ReadWriteProperty<Any?, T> =
|
||||
object : ObservableProperty<T>(initialValue) {
|
||||
override fun beforeChange(property: KProperty<*>, oldValue: T, newValue: T): Boolean = onChange(property, oldValue, newValue)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class NotNullVar<T: Any>() : ReadWriteProperty<Any?, T> {
|
||||
private class NotNullVar<T : Any>() : ReadWriteProperty<Any?, T> {
|
||||
private var value: T? = null
|
||||
|
||||
public override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
|
||||
@@ -26,7 +26,7 @@ public abstract class ObservableProperty<T>(initialValue: T) : ReadWriteProperty
|
||||
* The callback which is called after the change of the property is made. The value of the property
|
||||
* has already been changed when this callback is invoked.
|
||||
*/
|
||||
protected open fun afterChange (property: KProperty<*>, oldValue: T, newValue: T): Unit {}
|
||||
protected open fun afterChange(property: KProperty<*>, oldValue: T, newValue: T): Unit {}
|
||||
|
||||
public override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return value
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("RangesKt")
|
||||
|
||||
package kotlin.ranges
|
||||
|
||||
import kotlin.*
|
||||
@@ -17,7 +18,7 @@ import kotlin.*
|
||||
* achieve IEEE-754 comparison order instead of total order of floating point numbers.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public interface ClosedFloatingPointRange<T: Comparable<T>> : ClosedRange<T> {
|
||||
public interface ClosedFloatingPointRange<T : Comparable<T>> : ClosedRange<T> {
|
||||
override fun contains(value: T): Boolean = lessThanOrEquals(start, value) && lessThanOrEquals(value, endInclusive)
|
||||
override fun isEmpty(): Boolean = !lessThanOrEquals(start, endInclusive)
|
||||
|
||||
@@ -30,10 +31,10 @@ public interface ClosedFloatingPointRange<T: Comparable<T>> : ClosedRange<T> {
|
||||
/**
|
||||
* Represents a range of [Comparable] values.
|
||||
*/
|
||||
private open class ComparableRange<T: Comparable<T>> (
|
||||
override val start: T,
|
||||
override val endInclusive: T
|
||||
): ClosedRange<T> {
|
||||
private open class ComparableRange<T : Comparable<T>>(
|
||||
override val start: T,
|
||||
override val endInclusive: T
|
||||
) : ClosedRange<T> {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is ComparableRange<*> && (isEmpty() && other.isEmpty() ||
|
||||
@@ -52,9 +53,9 @@ private open class ComparableRange<T: Comparable<T>> (
|
||||
*
|
||||
* Numbers are compared with the ends of this range according to IEEE-754.
|
||||
*/
|
||||
private class ClosedDoubleRange (
|
||||
start: Double,
|
||||
endInclusive: Double
|
||||
private class ClosedDoubleRange(
|
||||
start: Double,
|
||||
endInclusive: Double
|
||||
) : ClosedFloatingPointRange<Double> {
|
||||
private val _start = start
|
||||
private val _endInclusive = endInclusive
|
||||
@@ -74,6 +75,7 @@ private class ClosedDoubleRange (
|
||||
override fun hashCode(): Int {
|
||||
return if (isEmpty()) -1 else 31 * _start.hashCode() + _endInclusive.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String = "$_start..$_endInclusive"
|
||||
}
|
||||
|
||||
@@ -84,7 +86,7 @@ private class ClosedDoubleRange (
|
||||
* This value needs to be smaller than [that] value, otherwise the returned range will be empty.
|
||||
* @sample samples.ranges.Ranges.rangeFromComparable
|
||||
*/
|
||||
public operator fun <T: Comparable<T>> T.rangeTo(that: T): ClosedRange<T> = ComparableRange(this, that)
|
||||
public operator fun <T : Comparable<T>> T.rangeTo(that: T): ClosedRange<T> = ComparableRange(this, that)
|
||||
|
||||
/**
|
||||
* Creates a range from this [Double] value to the specified [that] value.
|
||||
|
||||
@@ -12,7 +12,7 @@ package kotlin.text
|
||||
* Concatenates this Char and a String.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun Char.plus(other: String) : String = this.toString() + other
|
||||
public inline operator fun Char.plus(other: String): String = this.toString() + other
|
||||
|
||||
/**
|
||||
* Returns `true` if this character is equal to the [other] character, optionally ignoring character case.
|
||||
|
||||
@@ -69,9 +69,9 @@ public fun String.replaceIndent(newIndent: String = ""): String {
|
||||
val lines = lines()
|
||||
|
||||
val minCommonIndent = lines
|
||||
.filter(String::isNotBlank)
|
||||
.map(String::indentWidth)
|
||||
.min() ?: 0
|
||||
.filter(String::isNotBlank)
|
||||
.map(String::indentWidth)
|
||||
.min() ?: 0
|
||||
|
||||
return lines.reindent(length + newIndent.length * lines.size, getIndentFunction(newIndent), { line -> line.drop(minCommonIndent) })
|
||||
}
|
||||
@@ -83,18 +83,18 @@ public fun String.replaceIndent(newIndent: String = ""): String {
|
||||
*/
|
||||
public fun String.prependIndent(indent: String = " "): String =
|
||||
lineSequence()
|
||||
.map {
|
||||
when {
|
||||
it.isBlank() -> {
|
||||
when {
|
||||
it.length < indent.length -> indent
|
||||
else -> it
|
||||
.map {
|
||||
when {
|
||||
it.isBlank() -> {
|
||||
when {
|
||||
it.length < indent.length -> indent
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
else -> indent + it
|
||||
}
|
||||
else -> indent + it
|
||||
}
|
||||
}
|
||||
.joinToString("\n")
|
||||
.joinToString("\n")
|
||||
|
||||
private fun String.indentWidth(): Int = indexOfFirst { !it.isWhitespace() }.let { if (it == -1) length else it }
|
||||
|
||||
@@ -103,14 +103,18 @@ private fun getIndentFunction(indent: String) = when {
|
||||
else -> { line: String -> indent + line }
|
||||
}
|
||||
|
||||
private inline fun List<String>.reindent(resultSizeEstimate: Int, indentAddFunction: (String) -> String, indentCutFunction: (String) -> String?): String {
|
||||
private inline fun List<String>.reindent(
|
||||
resultSizeEstimate: Int,
|
||||
indentAddFunction: (String) -> String,
|
||||
indentCutFunction: (String) -> String?
|
||||
): String {
|
||||
val lastIndex = lastIndex
|
||||
return mapIndexedNotNull { index, value ->
|
||||
if ((index == 0 || index == lastIndex) && value.isBlank())
|
||||
null
|
||||
else
|
||||
indentCutFunction(value)?.let(indentAddFunction) ?: value
|
||||
}
|
||||
if ((index == 0 || index == lastIndex) && value.isBlank())
|
||||
null
|
||||
else
|
||||
indentCutFunction(value)?.let(indentAddFunction) ?: value
|
||||
}
|
||||
.joinTo(StringBuilder(resultSizeEstimate), "\n")
|
||||
.toString()
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ package kotlin.text
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun buildString(builderAction: StringBuilder.() -> Unit): String =
|
||||
StringBuilder().apply(builderAction).toString()
|
||||
StringBuilder().apply(builderAction).toString()
|
||||
|
||||
/**
|
||||
* Builds new string by populating newly created [StringBuilder] initialized with the given [capacity]
|
||||
@@ -23,7 +23,7 @@ public inline fun buildString(builderAction: StringBuilder.() -> Unit): String =
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun buildString(capacity: Int, builderAction: StringBuilder.() -> Unit): String =
|
||||
StringBuilder(capacity).apply(builderAction).toString()
|
||||
StringBuilder(capacity).apply(builderAction).toString()
|
||||
|
||||
/**
|
||||
* Appends all arguments to the given [Appendable].
|
||||
@@ -53,7 +53,6 @@ public fun StringBuilder.append(vararg value: Any?): StringBuilder {
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
||||
when {
|
||||
transform != null -> append(transform(element))
|
||||
|
||||
@@ -31,8 +31,7 @@ public inline fun CharSequence.trim(predicate: (Char) -> Boolean): CharSequence
|
||||
startFound = true
|
||||
else
|
||||
startIndex += 1
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!match)
|
||||
break
|
||||
else
|
||||
@@ -46,8 +45,8 @@ public inline fun CharSequence.trim(predicate: (Char) -> Boolean): CharSequence
|
||||
/**
|
||||
* Returns a string having leading and trailing characters matching the [predicate] removed.
|
||||
*/
|
||||
public inline fun String.trim(predicate: (Char) -> Boolean): String
|
||||
= (this as CharSequence).trim(predicate).toString()
|
||||
public inline fun String.trim(predicate: (Char) -> Boolean): String =
|
||||
(this as CharSequence).trim(predicate).toString()
|
||||
|
||||
/**
|
||||
* Returns a sub sequence of this char sequence having leading characters matching the [predicate] removed.
|
||||
@@ -63,8 +62,8 @@ public inline fun CharSequence.trimStart(predicate: (Char) -> Boolean): CharSequ
|
||||
/**
|
||||
* Returns a string having leading characters matching the [predicate] removed.
|
||||
*/
|
||||
public inline fun String.trimStart(predicate: (Char) -> Boolean): String
|
||||
= (this as CharSequence).trimStart(predicate).toString()
|
||||
public inline fun String.trimStart(predicate: (Char) -> Boolean): String =
|
||||
(this as CharSequence).trimStart(predicate).toString()
|
||||
|
||||
/**
|
||||
* Returns a sub sequence of this char sequence having trailing characters matching the [predicate] removed.
|
||||
@@ -80,8 +79,8 @@ public inline fun CharSequence.trimEnd(predicate: (Char) -> Boolean): CharSequen
|
||||
/**
|
||||
* Returns a string having trailing characters matching the [predicate] removed.
|
||||
*/
|
||||
public inline fun String.trimEnd(predicate: (Char) -> Boolean): String
|
||||
= (this as CharSequence).trimEnd(predicate).toString()
|
||||
public inline fun String.trimEnd(predicate: (Char) -> Boolean): String =
|
||||
(this as CharSequence).trimEnd(predicate).toString()
|
||||
|
||||
/**
|
||||
* Returns a sub sequence of this char sequence having leading and trailing characters from the [chars] array removed.
|
||||
@@ -176,8 +175,8 @@ public fun CharSequence.padStart(length: Int, padChar: Char = ' '): CharSequence
|
||||
* @returns Returns a string, of length at least [length], consisting of string prepended with [padChar] as many times.
|
||||
* as are necessary to reach that length.
|
||||
*/
|
||||
public fun String.padStart(length: Int, padChar: Char = ' '): String
|
||||
= (this as CharSequence).padStart(length, padChar).toString()
|
||||
public fun String.padStart(length: Int, padChar: Char = ' '): String =
|
||||
(this as CharSequence).padStart(length, padChar).toString()
|
||||
|
||||
/**
|
||||
* Returns a char sequence with content of this char sequence padded at the end
|
||||
@@ -209,8 +208,8 @@ public fun CharSequence.padEnd(length: Int, padChar: Char = ' '): CharSequence {
|
||||
* @returns Returns a string, of length at least [length], consisting of string prepended with [padChar] as many times.
|
||||
* as are necessary to reach that length.
|
||||
*/
|
||||
public fun String.padEnd(length: Int, padChar: Char = ' '): String
|
||||
= (this as CharSequence).padEnd(length, padChar).toString()
|
||||
public fun String.padEnd(length: Int, padChar: Char = ' '): String =
|
||||
(this as CharSequence).padEnd(length, padChar).toString()
|
||||
|
||||
/**
|
||||
* Returns `true` if this nullable char sequence is either `null` or empty.
|
||||
@@ -423,8 +422,8 @@ public fun CharSequence.replaceRange(startIndex: Int, endIndex: Int, replacement
|
||||
* @param endIndex the index of the first character after the replacement to keep in the string.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String.replaceRange(startIndex: Int, endIndex: Int, replacement: CharSequence): String
|
||||
= (this as CharSequence).replaceRange(startIndex, endIndex, replacement).toString()
|
||||
public inline fun String.replaceRange(startIndex: Int, endIndex: Int, replacement: CharSequence): String =
|
||||
(this as CharSequence).replaceRange(startIndex, endIndex, replacement).toString()
|
||||
|
||||
/**
|
||||
* Returns a char sequence with content of this char sequence where its part at the given [range]
|
||||
@@ -432,8 +431,8 @@ public inline fun String.replaceRange(startIndex: Int, endIndex: Int, replacemen
|
||||
*
|
||||
* The end index of the [range] is included in the part to be replaced.
|
||||
*/
|
||||
public fun CharSequence.replaceRange(range: IntRange, replacement: CharSequence): CharSequence
|
||||
= replaceRange(range.start, range.endInclusive + 1, replacement)
|
||||
public fun CharSequence.replaceRange(range: IntRange, replacement: CharSequence): CharSequence =
|
||||
replaceRange(range.start, range.endInclusive + 1, replacement)
|
||||
|
||||
/**
|
||||
* Replace the part of string at the given [range] with the [replacement] string.
|
||||
@@ -441,8 +440,8 @@ public fun CharSequence.replaceRange(range: IntRange, replacement: CharSequence)
|
||||
* The end index of the [range] is included in the part to be replaced.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String.replaceRange(range: IntRange, replacement: CharSequence): String
|
||||
= (this as CharSequence).replaceRange(range, replacement).toString()
|
||||
public inline fun String.replaceRange(range: IntRange, replacement: CharSequence): String =
|
||||
(this as CharSequence).replaceRange(range, replacement).toString()
|
||||
|
||||
/**
|
||||
* Returns a char sequence with content of this char sequence where its part at the given range is removed.
|
||||
@@ -473,8 +472,8 @@ public fun CharSequence.removeRange(startIndex: Int, endIndex: Int): CharSequenc
|
||||
* [endIndex] is not included in the removed part.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String.removeRange(startIndex: Int, endIndex: Int): String
|
||||
= (this as CharSequence).removeRange(startIndex, endIndex).toString()
|
||||
public inline fun String.removeRange(startIndex: Int, endIndex: Int): String =
|
||||
(this as CharSequence).removeRange(startIndex, endIndex).toString()
|
||||
|
||||
/**
|
||||
* Returns a char sequence with content of this char sequence where its part at the given [range] is removed.
|
||||
@@ -489,8 +488,8 @@ public fun CharSequence.removeRange(range: IntRange): CharSequence = removeRange
|
||||
* The end index of the [range] is included in the removed part.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String.removeRange(range: IntRange): String
|
||||
= (this as CharSequence).removeRange(range).toString()
|
||||
public inline fun String.removeRange(range: IntRange): String =
|
||||
(this as CharSequence).removeRange(range).toString()
|
||||
|
||||
/**
|
||||
* If this char sequence starts with the given [prefix], returns a new char sequence
|
||||
@@ -666,7 +665,8 @@ public inline fun CharSequence.replace(regex: Regex, replacement: String): Strin
|
||||
* replacement for that match.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun CharSequence.replace(regex: Regex, noinline transform: (MatchResult) -> CharSequence): String = regex.replace(this, transform)
|
||||
public inline fun CharSequence.replace(regex: Regex, noinline transform: (MatchResult) -> CharSequence): String =
|
||||
regex.replace(this, transform)
|
||||
|
||||
/**
|
||||
* Replaces the first occurrence of the given regular expression [regex] in this char sequence with specified [replacement] expression.
|
||||
@@ -688,8 +688,7 @@ public inline infix fun CharSequence.matches(regex: Regex): Boolean = regex.matc
|
||||
* Invoked when it's already known that arguments are not Strings, so that no additional type checks are performed.
|
||||
*/
|
||||
internal fun CharSequence.regionMatchesImpl(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean): Boolean {
|
||||
if ((otherOffset < 0) || (thisOffset < 0) || (thisOffset > this.length - length)
|
||||
|| (otherOffset > other.length - length)) {
|
||||
if ((otherOffset < 0) || (thisOffset < 0) || (thisOffset > this.length - length) || (otherOffset > other.length - length)) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -704,13 +703,13 @@ internal fun CharSequence.regionMatchesImpl(thisOffset: Int, other: CharSequence
|
||||
* Returns `true` if this char sequence starts with the specified character.
|
||||
*/
|
||||
public fun CharSequence.startsWith(char: Char, ignoreCase: Boolean = false): Boolean =
|
||||
this.length > 0 && this[0].equals(char, ignoreCase)
|
||||
this.length > 0 && this[0].equals(char, ignoreCase)
|
||||
|
||||
/**
|
||||
* Returns `true` if this char sequence ends with the specified character.
|
||||
*/
|
||||
public fun CharSequence.endsWith(char: Char, ignoreCase: Boolean = false): Boolean =
|
||||
this.length > 0 && this[lastIndex].equals(char, ignoreCase)
|
||||
this.length > 0 && this[lastIndex].equals(char, ignoreCase)
|
||||
|
||||
/**
|
||||
* Returns `true` if this char sequence starts with the specified prefix.
|
||||
@@ -1024,7 +1023,7 @@ public operator fun CharSequence.contains(other: CharSequence, ignoreCase: Boole
|
||||
*/
|
||||
@Suppress("INAPPLICABLE_OPERATOR_MODIFIER")
|
||||
public operator fun CharSequence.contains(char: Char, ignoreCase: Boolean = false): Boolean =
|
||||
indexOf(char, ignoreCase = ignoreCase) >= 0
|
||||
indexOf(char, ignoreCase = ignoreCase) >= 0
|
||||
|
||||
/**
|
||||
* Returns `true` if this char sequence contains at least one match of the specified regular expression [regex].
|
||||
@@ -1036,7 +1035,12 @@ public inline operator fun CharSequence.contains(regex: Regex): Boolean = regex.
|
||||
// rangesDelimitedBy
|
||||
|
||||
|
||||
private class DelimitedRangesSequence(private val input: CharSequence, private val startIndex: Int, private val limit: Int, private val getNextMatch: CharSequence.(Int) -> Pair<Int, Int>?): Sequence<IntRange> {
|
||||
private class DelimitedRangesSequence(
|
||||
private val input: CharSequence,
|
||||
private val startIndex: Int,
|
||||
private val limit: Int,
|
||||
private val getNextMatch: CharSequence.(Int) -> Pair<Int, Int>?
|
||||
) : Sequence<IntRange> {
|
||||
|
||||
override fun iterator(): Iterator<IntRange> = object : Iterator<IntRange> {
|
||||
var nextState: Int = -1 // -1 for unknown, 0 for done, 1 for continue
|
||||
@@ -1049,20 +1053,17 @@ private class DelimitedRangesSequence(private val input: CharSequence, private v
|
||||
if (nextSearchIndex < 0) {
|
||||
nextState = 0
|
||||
nextItem = null
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (limit > 0 && ++counter >= limit || nextSearchIndex > input.length) {
|
||||
nextItem = currentStartIndex..input.lastIndex
|
||||
nextSearchIndex = -1
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
val match = input.getNextMatch(nextSearchIndex)
|
||||
if (match == null) {
|
||||
nextItem = currentStartIndex..input.lastIndex
|
||||
nextSearchIndex = -1
|
||||
}
|
||||
else {
|
||||
val (index,length) = match
|
||||
} else {
|
||||
val (index, length) = match
|
||||
nextItem = currentStartIndex until index
|
||||
currentStartIndex = index + length
|
||||
nextSearchIndex = currentStartIndex + if (length == 0) 1 else 0
|
||||
@@ -1106,7 +1107,8 @@ private fun CharSequence.rangesDelimitedBy(delimiters: CharArray, startIndex: In
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit." })
|
||||
|
||||
return DelimitedRangesSequence(this, startIndex, limit, { startIndex ->
|
||||
indexOfAny(delimiters, startIndex, ignoreCase = ignoreCase).let { if (it < 0) null else it to 1 } })
|
||||
indexOfAny(delimiters, startIndex, ignoreCase = ignoreCase).let { if (it < 0) null else it to 1 }
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1147,7 +1149,7 @@ private fun CharSequence.rangesDelimitedBy(delimiters: Array<out String>, startI
|
||||
* that matches this string at that position.
|
||||
*/
|
||||
public fun CharSequence.splitToSequence(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): Sequence<String> =
|
||||
rangesDelimitedBy(delimiters, ignoreCase = ignoreCase, limit = limit).map { substring(it) }
|
||||
rangesDelimitedBy(delimiters, ignoreCase = ignoreCase, limit = limit).map { substring(it) }
|
||||
|
||||
/**
|
||||
* Splits this char sequence to a list of strings around occurrences of the specified [delimiters].
|
||||
@@ -1179,7 +1181,7 @@ public fun CharSequence.split(vararg delimiters: String, ignoreCase: Boolean = f
|
||||
* @param limit The maximum number of substrings to return.
|
||||
*/
|
||||
public fun CharSequence.splitToSequence(vararg delimiters: Char, ignoreCase: Boolean = false, limit: Int = 0): Sequence<String> =
|
||||
rangesDelimitedBy(delimiters, ignoreCase = ignoreCase, limit = limit).map { substring(it) }
|
||||
rangesDelimitedBy(delimiters, ignoreCase = ignoreCase, limit = limit).map { substring(it) }
|
||||
|
||||
/**
|
||||
* Splits this char sequence to a list of strings around occurrences of the specified [delimiters].
|
||||
|
||||
@@ -112,6 +112,7 @@ public interface MatchResult {
|
||||
public operator inline fun component9(): String = match.groupValues[9]
|
||||
@kotlin.internal.InlineOnly
|
||||
public operator inline fun component10(): String = match.groupValues[10]
|
||||
|
||||
/**
|
||||
* Returns destructured group values as a list of strings.
|
||||
* First value in the returned list corresponds to the value of the first group, and so on.
|
||||
|
||||
@@ -48,20 +48,18 @@ public class KotlinVersion(val major: Int, val minor: Int, val patch: Int) : Com
|
||||
* Returns `true` if this version is not less than the version specified
|
||||
* with the provided [major] and [minor] components.
|
||||
*/
|
||||
public fun isAtLeast(major: Int, minor: Int): Boolean =
|
||||
// or this.version >= versionOf(major, minor, 0)
|
||||
this.major > major || (this.major == major &&
|
||||
this.minor >= minor)
|
||||
public fun isAtLeast(major: Int, minor: Int): Boolean = // this.version >= versionOf(major, minor, 0)
|
||||
this.major > major || (this.major == major &&
|
||||
this.minor >= minor)
|
||||
|
||||
/**
|
||||
* Returns `true` if this version is not less than the version specified
|
||||
* with the provided [major], [minor] and [patch] components.
|
||||
*/
|
||||
public fun isAtLeast(major: Int, minor: Int, patch: Int): Boolean =
|
||||
// or this.version >= versionOf(major, minor, patch)
|
||||
this.major > major || (this.major == major &&
|
||||
(this.minor > minor || this.minor == minor &&
|
||||
this.patch >= patch))
|
||||
public fun isAtLeast(major: Int, minor: Int, patch: Int): Boolean = // this.version >= versionOf(major, minor, patch)
|
||||
this.major > major || (this.major == major &&
|
||||
(this.minor > minor || this.minor == minor &&
|
||||
this.patch >= patch))
|
||||
|
||||
companion object {
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,7 @@ public interface Lazy<out T> {
|
||||
* Once the value was initialized it must not change during the rest of lifetime of this Lazy instance.
|
||||
*/
|
||||
public val value: T
|
||||
|
||||
/**
|
||||
* Returns `true` if a value for this Lazy instance has been already initialized, and `false` otherwise.
|
||||
* Once this function has returned `true` it stays `true` for the rest of lifetime of this Lazy instance.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("PreconditionsKt")
|
||||
|
||||
package kotlin
|
||||
|
||||
import kotlin.internal.contracts.*
|
||||
@@ -42,7 +43,7 @@ public inline fun require(value: Boolean, lazyMessage: () -> Any): Unit {
|
||||
* Throws an [IllegalArgumentException] if the [value] is null. Otherwise returns the not null value.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T:Any> requireNotNull(value: T?): T {
|
||||
public inline fun <T : Any> requireNotNull(value: T?): T {
|
||||
contract {
|
||||
returns() implies (value != null)
|
||||
}
|
||||
@@ -56,7 +57,7 @@ public inline fun <T:Any> requireNotNull(value: T?): T {
|
||||
* @sample samples.misc.Preconditions.failRequireWithLazyMessage
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T:Any> requireNotNull(value: T?, lazyMessage: () -> Any): T {
|
||||
public inline fun <T : Any> requireNotNull(value: T?, lazyMessage: () -> Any): T {
|
||||
contract {
|
||||
returns() implies (value != null)
|
||||
}
|
||||
@@ -105,7 +106,7 @@ public inline fun check(value: Boolean, lazyMessage: () -> Any): Unit {
|
||||
* @sample samples.misc.Preconditions.failCheckWithLazyMessage
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T:Any> checkNotNull(value: T?): T = checkNotNull(value) { "Required value was null." }
|
||||
public inline fun <T : Any> checkNotNull(value: T?): T = checkNotNull(value) { "Required value was null." }
|
||||
|
||||
/**
|
||||
* Throws an [IllegalStateException] with the result of calling [lazyMessage] if the [value] is null. Otherwise
|
||||
@@ -114,7 +115,7 @@ public inline fun <T:Any> checkNotNull(value: T?): T = checkNotNull(value) { "Re
|
||||
* @sample samples.misc.Preconditions.failCheckWithLazyMessage
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T:Any> checkNotNull(value: T?, lazyMessage: () -> Any): T {
|
||||
public inline fun <T : Any> checkNotNull(value: T?, lazyMessage: () -> Any): T {
|
||||
contract {
|
||||
returns() implies (value != null)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
@file:kotlin.jvm.JvmName("TuplesKt")
|
||||
|
||||
package kotlin
|
||||
|
||||
|
||||
@@ -23,9 +24,9 @@ package kotlin
|
||||
* @constructor Creates a new instance of Pair.
|
||||
*/
|
||||
public data class Pair<out A, out B>(
|
||||
public val first: A,
|
||||
public val second: B
|
||||
) : Serializable {
|
||||
public val first: A,
|
||||
public val second: B
|
||||
) : Serializable {
|
||||
|
||||
/**
|
||||
* Returns string representation of the [Pair] including its [first] and [second] values.
|
||||
@@ -62,10 +63,10 @@ public fun <T> Pair<T, T>.toList(): List<T> = listOf(first, second)
|
||||
* @property third Third value.
|
||||
*/
|
||||
public data class Triple<out A, out B, out C>(
|
||||
public val first: A,
|
||||
public val second: B,
|
||||
public val third: C
|
||||
) : Serializable {
|
||||
public val first: A,
|
||||
public val second: B,
|
||||
public val third: C
|
||||
) : Serializable {
|
||||
|
||||
/**
|
||||
* Returns string representation of the [Triple] including its [first], [second] and [third] values.
|
||||
|
||||
Reference in New Issue
Block a user