Reformat stdlib: jvm part
#KT-5558
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
@file:JvmName("ThreadsKt")
|
||||
|
||||
package kotlin.concurrent
|
||||
|
||||
/**
|
||||
@@ -16,7 +17,14 @@ package kotlin.concurrent
|
||||
* @param name the name of the thread.
|
||||
* @param priority the priority of the thread.
|
||||
*/
|
||||
public fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: () -> Unit): Thread {
|
||||
public fun thread(
|
||||
start: Boolean = true,
|
||||
isDaemon: Boolean = false,
|
||||
contextClassLoader: ClassLoader? = null,
|
||||
name: String? = null,
|
||||
priority: Int = -1,
|
||||
block: () -> Unit
|
||||
): Thread {
|
||||
val thread = object : Thread() {
|
||||
public override fun run() {
|
||||
block()
|
||||
@@ -47,6 +55,6 @@ public fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClass
|
||||
* is stored for the current thread and then returned.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T: Any> ThreadLocal<T>.getOrSet(default: () -> T): T {
|
||||
public inline fun <T : Any> ThreadLocal<T>.getOrSet(default: () -> T): T {
|
||||
return get() ?: default().also(this::set)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED
|
||||
@PublishedApi
|
||||
internal actual class SafeContinuation<in T>
|
||||
internal actual constructor(
|
||||
private val delegate: Continuation<T>,
|
||||
initialResult: Any?
|
||||
private val delegate: Continuation<T>,
|
||||
initialResult: Any?
|
||||
) : Continuation<T> {
|
||||
|
||||
@PublishedApi
|
||||
@@ -31,7 +31,8 @@ internal actual constructor(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@JvmStatic
|
||||
private val RESULT = AtomicReferenceFieldUpdater.newUpdater<SafeContinuation<*>, Any?>(
|
||||
SafeContinuation::class.java, Any::class.java as Class<Any?>, "result")
|
||||
SafeContinuation::class.java, Any::class.java as Class<Any?>, "result"
|
||||
)
|
||||
}
|
||||
|
||||
private class Fail(val exception: Throwable)
|
||||
@@ -53,7 +54,7 @@ internal actual constructor(
|
||||
actual override fun resumeWithException(exception: Throwable) {
|
||||
while (true) { // lock-free loop
|
||||
val result = this.result // atomic read
|
||||
when {
|
||||
when {
|
||||
result === UNDECIDED -> if (RESULT.compareAndSet(this, UNDECIDED, Fail(exception))) return
|
||||
result === COROUTINE_SUSPENDED -> if (RESULT.compareAndSet(this, COROUTINE_SUSPENDED, RESUMED)) {
|
||||
delegate.resumeWithException(exception)
|
||||
|
||||
+36
-34
@@ -5,7 +5,9 @@
|
||||
|
||||
@file:kotlin.jvm.JvmName("IntrinsicsKt")
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
|
||||
package kotlin.coroutines.experimental.intrinsics
|
||||
|
||||
import kotlin.coroutines.experimental.*
|
||||
|
||||
/**
|
||||
@@ -19,7 +21,7 @@ import kotlin.coroutines.experimental.*
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun <T> (suspend () -> T).startCoroutineUninterceptedOrReturn(
|
||||
completion: Continuation<T>
|
||||
completion: Continuation<T>
|
||||
): Any? = (this as Function1<Continuation<T>, Any?>).invoke(completion)
|
||||
|
||||
/**
|
||||
@@ -33,8 +35,8 @@ public actual inline fun <T> (suspend () -> T).startCoroutineUninterceptedOrRetu
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun <R, T> (suspend R.() -> T).startCoroutineUninterceptedOrReturn(
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
): Any? = (this as Function2<R, Continuation<T>, Any?>).invoke(receiver, completion)
|
||||
|
||||
|
||||
@@ -52,15 +54,15 @@ public actual inline fun <R, T> (suspend R.() -> T).startCoroutineUninterceptedO
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public actual fun <T> (suspend () -> T).createCoroutineUnchecked(
|
||||
completion: Continuation<T>
|
||||
completion: Continuation<T>
|
||||
): Continuation<Unit> =
|
||||
if (this !is kotlin.coroutines.experimental.jvm.internal.CoroutineImpl)
|
||||
buildContinuationByInvokeCall(completion) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(this as Function1<Continuation<T>, Any?>).invoke(completion)
|
||||
}
|
||||
else
|
||||
(this.create(completion) as kotlin.coroutines.experimental.jvm.internal.CoroutineImpl).facade
|
||||
if (this !is kotlin.coroutines.experimental.jvm.internal.CoroutineImpl)
|
||||
buildContinuationByInvokeCall(completion) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(this as Function1<Continuation<T>, Any?>).invoke(completion)
|
||||
}
|
||||
else
|
||||
(this.create(completion) as kotlin.coroutines.experimental.jvm.internal.CoroutineImpl).facade
|
||||
|
||||
/**
|
||||
* Creates a coroutine with receiver type [R] and result type [T].
|
||||
@@ -74,36 +76,36 @@ public actual fun <T> (suspend () -> T).createCoroutineUnchecked(
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public actual fun <R, T> (suspend R.() -> T).createCoroutineUnchecked(
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
receiver: R,
|
||||
completion: Continuation<T>
|
||||
): Continuation<Unit> =
|
||||
if (this !is kotlin.coroutines.experimental.jvm.internal.CoroutineImpl)
|
||||
buildContinuationByInvokeCall(completion) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(this as Function2<R, Continuation<T>, Any?>).invoke(receiver, completion)
|
||||
}
|
||||
else
|
||||
(this.create(receiver, completion) as kotlin.coroutines.experimental.jvm.internal.CoroutineImpl).facade
|
||||
if (this !is kotlin.coroutines.experimental.jvm.internal.CoroutineImpl)
|
||||
buildContinuationByInvokeCall(completion) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(this as Function2<R, Continuation<T>, Any?>).invoke(receiver, completion)
|
||||
}
|
||||
else
|
||||
(this.create(receiver, completion) as kotlin.coroutines.experimental.jvm.internal.CoroutineImpl).facade
|
||||
|
||||
// INTERNAL DEFINITIONS
|
||||
|
||||
private inline fun <T> buildContinuationByInvokeCall(
|
||||
completion: Continuation<T>,
|
||||
crossinline block: () -> Any?
|
||||
completion: Continuation<T>,
|
||||
crossinline block: () -> Any?
|
||||
): Continuation<Unit> {
|
||||
val continuation =
|
||||
object : Continuation<Unit> {
|
||||
override val context: CoroutineContext
|
||||
get() = completion.context
|
||||
val continuation =
|
||||
object : Continuation<Unit> {
|
||||
override val context: CoroutineContext
|
||||
get() = completion.context
|
||||
|
||||
override fun resume(value: Unit) {
|
||||
processBareContinuationResume(completion, block)
|
||||
}
|
||||
override fun resume(value: Unit) {
|
||||
processBareContinuationResume(completion, block)
|
||||
}
|
||||
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
completion.resumeWithException(exception)
|
||||
}
|
||||
}
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
completion.resumeWithException(exception)
|
||||
}
|
||||
}
|
||||
|
||||
return kotlin.coroutines.experimental.jvm.internal.interceptContinuationIfNeeded(completion.context, continuation)
|
||||
return kotlin.coroutines.experimental.jvm.internal.interceptContinuationIfNeeded(completion.context, continuation)
|
||||
}
|
||||
|
||||
+3
-3
@@ -15,9 +15,9 @@ import kotlin.jvm.internal.Lambda
|
||||
* @suppress
|
||||
*/
|
||||
abstract class CoroutineImpl(
|
||||
arity: Int,
|
||||
@JvmField
|
||||
protected var completion: Continuation<Any?>?
|
||||
arity: Int,
|
||||
@JvmField
|
||||
protected var completion: Continuation<Any?>?
|
||||
) : Lambda(arity), Continuation<Any?> {
|
||||
|
||||
// label == -1 when coroutine cannot be started (it is just a factory object) or has already finished execution
|
||||
|
||||
+4
-3
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
@file:JvmName("CoroutineIntrinsics")
|
||||
|
||||
package kotlin.coroutines.experimental.jvm.internal
|
||||
|
||||
import kotlin.coroutines.experimental.Continuation
|
||||
@@ -14,9 +15,9 @@ import kotlin.coroutines.experimental.CoroutineContext
|
||||
* @suppress
|
||||
*/
|
||||
fun <T> normalizeContinuation(continuation: Continuation<T>): Continuation<T> =
|
||||
(continuation as? CoroutineImpl)?.facade ?: continuation
|
||||
(continuation as? CoroutineImpl)?.facade ?: continuation
|
||||
|
||||
internal fun <T> interceptContinuationIfNeeded(
|
||||
context: CoroutineContext,
|
||||
continuation: Continuation<T>
|
||||
context: CoroutineContext,
|
||||
continuation: Continuation<T>
|
||||
) = context[ContinuationInterceptor]?.interceptContinuation(continuation) ?: continuation
|
||||
|
||||
@@ -26,23 +26,19 @@ internal val IMPLEMENTATIONS: PlatformImplementations = run {
|
||||
if (version >= 0x10008) {
|
||||
try {
|
||||
return@run Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance() as PlatformImplementations
|
||||
}
|
||||
catch (e: ClassNotFoundException) { }
|
||||
} catch (e: ClassNotFoundException) { }
|
||||
try {
|
||||
return@run Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance() as PlatformImplementations
|
||||
}
|
||||
catch (e: ClassNotFoundException) { }
|
||||
} catch (e: ClassNotFoundException) { }
|
||||
}
|
||||
|
||||
if (version >= 0x10007) {
|
||||
try {
|
||||
return@run Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance() as PlatformImplementations
|
||||
}
|
||||
catch (e: ClassNotFoundException) { }
|
||||
} catch (e: ClassNotFoundException) { }
|
||||
try {
|
||||
return@run Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance() as PlatformImplementations
|
||||
}
|
||||
catch (e: ClassNotFoundException) { }
|
||||
} catch (e: ClassNotFoundException) { }
|
||||
}
|
||||
|
||||
PlatformImplementations()
|
||||
@@ -78,4 +74,4 @@ private fun getJavaVersion(): Int {
|
||||
@PublishedApi
|
||||
@SinceKotlin("1.2")
|
||||
internal fun apiVersionIsAtLeast(major: Int, minor: Int, patch: Int) =
|
||||
KotlinVersion.CURRENT.isAtLeast(major, minor, patch)
|
||||
KotlinVersion.CURRENT.isAtLeast(major, minor, patch)
|
||||
@@ -4,11 +4,12 @@
|
||||
*/
|
||||
|
||||
@file:JvmName("ConstantsKt")
|
||||
|
||||
package kotlin.io
|
||||
|
||||
/**
|
||||
* Returns the default buffer size when working with buffered streams.
|
||||
*/
|
||||
*/
|
||||
public const val DEFAULT_BUFFER_SIZE: Int = 8 * 1024
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,29 +26,36 @@ private fun constructMessage(file: File, other: File?, reason: String?): String
|
||||
* @property other the second file involved in the operation, if any (for example, the target of a copy or move)
|
||||
* @property reason the description of the error
|
||||
*/
|
||||
open public class FileSystemException(public val file: File,
|
||||
public val other: File? = null,
|
||||
public val reason: String? = null
|
||||
open public class FileSystemException(
|
||||
public val file: File,
|
||||
public val other: File? = null,
|
||||
public val reason: String? = null
|
||||
) : IOException(constructMessage(file, other, reason))
|
||||
|
||||
/**
|
||||
* An exception class which is used when some file to create or copy to already exists.
|
||||
*/
|
||||
public class FileAlreadyExistsException(file: File,
|
||||
other: File? = null,
|
||||
reason: String? = null) : FileSystemException(file, other, reason)
|
||||
public class FileAlreadyExistsException(
|
||||
file: File,
|
||||
other: File? = null,
|
||||
reason: String? = null
|
||||
) : FileSystemException(file, other, reason)
|
||||
|
||||
/**
|
||||
* An exception class which is used when we have not enough access for some operation.
|
||||
*/
|
||||
public class AccessDeniedException(file: File,
|
||||
other: File? = null,
|
||||
reason: String? = null) : FileSystemException(file, other, reason)
|
||||
public class AccessDeniedException(
|
||||
file: File,
|
||||
other: File? = null,
|
||||
reason: String? = null
|
||||
) : FileSystemException(file, other, reason)
|
||||
|
||||
/**
|
||||
* An exception class which is used when file to copy does not exist.
|
||||
*/
|
||||
public class NoSuchFileException(file: File,
|
||||
other: File? = null,
|
||||
reason: String? = null) : FileSystemException(file, other, reason)
|
||||
public class NoSuchFileException(
|
||||
file: File,
|
||||
other: File? = null,
|
||||
reason: String? = null
|
||||
) : FileSystemException(file, other, reason)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("FilesKt")
|
||||
|
||||
package kotlin.io
|
||||
|
||||
import java.io.*
|
||||
@@ -17,7 +18,8 @@ import kotlin.internal.*
|
||||
* Returns a new [FileReader] for reading the content of this file.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun File.reader(charset: Charset = Charsets.UTF_8): InputStreamReader = inputStream().reader(charset)
|
||||
public inline fun File.reader(charset: Charset = Charsets.UTF_8): InputStreamReader =
|
||||
inputStream().reader(charset)
|
||||
|
||||
/**
|
||||
* Returns a new [BufferedReader] for reading the content of this file.
|
||||
@@ -25,13 +27,15 @@ public inline fun File.reader(charset: Charset = Charsets.UTF_8): InputStreamRea
|
||||
* @param bufferSize necessary size of the buffer.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun File.bufferedReader(charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader = reader(charset).buffered(bufferSize)
|
||||
public inline fun File.bufferedReader(charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader =
|
||||
reader(charset).buffered(bufferSize)
|
||||
|
||||
/**
|
||||
* Returns a new [FileWriter] for writing the content of this file.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun File.writer(charset: Charset = Charsets.UTF_8): OutputStreamWriter = outputStream().writer(charset)
|
||||
public inline fun File.writer(charset: Charset = Charsets.UTF_8): OutputStreamWriter =
|
||||
outputStream().writer(charset)
|
||||
|
||||
/**
|
||||
* Returns a new [BufferedWriter] for writing the content of this file.
|
||||
@@ -39,13 +43,15 @@ public inline fun File.writer(charset: Charset = Charsets.UTF_8): OutputStreamWr
|
||||
* @param bufferSize necessary size of the buffer.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun File.bufferedWriter(charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter = writer(charset).buffered(bufferSize)
|
||||
public inline fun File.bufferedWriter(charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter =
|
||||
writer(charset).buffered(bufferSize)
|
||||
|
||||
/**
|
||||
* Returns a new [PrintWriter] for writing the content of this file.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun File.printWriter(charset: Charset = Charsets.UTF_8): PrintWriter = PrintWriter(bufferedWriter(charset))
|
||||
public inline fun File.printWriter(charset: Charset = Charsets.UTF_8): PrintWriter =
|
||||
PrintWriter(bufferedWriter(charset))
|
||||
|
||||
/**
|
||||
* Gets the entire content of this file as a byte array.
|
||||
@@ -199,4 +205,4 @@ public fun File.readLines(charset: Charset = Charsets.UTF_8): List<String> {
|
||||
*/
|
||||
@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION, message = "Requires newer compiler version to be inlined correctly.")
|
||||
public inline fun <T> File.useLines(charset: Charset = Charsets.UTF_8, block: (Sequence<String>) -> T): T =
|
||||
bufferedReader(charset).use { block(it.lineSequence()) }
|
||||
bufferedReader(charset).use { block(it.lineSequence()) }
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
@file:JvmName("ByteStreamsKt")
|
||||
|
||||
package kotlin.io
|
||||
|
||||
import java.io.*
|
||||
@@ -12,37 +13,37 @@ import java.util.NoSuchElementException
|
||||
|
||||
/** Returns an [Iterator] of bytes read from this input stream. */
|
||||
public operator fun BufferedInputStream.iterator(): ByteIterator =
|
||||
object : ByteIterator() {
|
||||
object : ByteIterator() {
|
||||
|
||||
var nextByte = -1
|
||||
var nextByte = -1
|
||||
|
||||
var nextPrepared = false
|
||||
var nextPrepared = false
|
||||
|
||||
var finished = false
|
||||
var finished = false
|
||||
|
||||
private fun prepareNext() {
|
||||
if (!nextPrepared && !finished) {
|
||||
nextByte = read()
|
||||
nextPrepared = true
|
||||
finished = (nextByte == -1)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun hasNext(): Boolean {
|
||||
prepareNext()
|
||||
return !finished
|
||||
}
|
||||
|
||||
public override fun nextByte(): Byte {
|
||||
prepareNext()
|
||||
if (finished)
|
||||
throw NoSuchElementException("Input stream is over.")
|
||||
val res = nextByte.toByte()
|
||||
nextPrepared = false
|
||||
return res
|
||||
private fun prepareNext() {
|
||||
if (!nextPrepared && !finished) {
|
||||
nextByte = read()
|
||||
nextPrepared = true
|
||||
finished = (nextByte == -1)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun hasNext(): Boolean {
|
||||
prepareNext()
|
||||
return !finished
|
||||
}
|
||||
|
||||
public override fun nextByte(): Byte {
|
||||
prepareNext()
|
||||
if (finished)
|
||||
throw NoSuchElementException("Input stream is over.")
|
||||
val res = nextByte.toByte()
|
||||
nextPrepared = false
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Creates a new byte input stream for the string. */
|
||||
@kotlin.internal.InlineOnly
|
||||
@@ -60,15 +61,15 @@ public inline fun ByteArray.inputStream(): ByteArrayInputStream = ByteArrayInput
|
||||
* @param length the length of the portion of the array to read.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun ByteArray.inputStream(offset: Int, length: Int) : ByteArrayInputStream = ByteArrayInputStream(this, offset, length)
|
||||
public inline fun ByteArray.inputStream(offset: Int, length: Int): ByteArrayInputStream = ByteArrayInputStream(this, offset, length)
|
||||
|
||||
/**
|
||||
* Creates a buffered input stream wrapping this stream.
|
||||
* @param bufferSize the buffer size to use.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun InputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedInputStream
|
||||
= if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize)
|
||||
public inline fun InputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedInputStream =
|
||||
if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize)
|
||||
|
||||
/** Creates a reader on this input stream using UTF-8 or the specified [charset]. */
|
||||
@kotlin.internal.InlineOnly
|
||||
@@ -83,8 +84,8 @@ public inline fun InputStream.bufferedReader(charset: Charset = Charsets.UTF_8):
|
||||
* @param bufferSize the buffer size to use.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun OutputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedOutputStream
|
||||
= if (this is BufferedOutputStream) this else BufferedOutputStream(this, bufferSize)
|
||||
public inline fun OutputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedOutputStream =
|
||||
if (this is BufferedOutputStream) this else BufferedOutputStream(this, bufferSize)
|
||||
|
||||
/** Creates a writer on this output stream using UTF-8 or the specified [charset]. */
|
||||
@kotlin.internal.InlineOnly
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
@file:JvmName("TextStreamsKt")
|
||||
|
||||
package kotlin.io
|
||||
|
||||
import java.io.*
|
||||
@@ -15,13 +16,13 @@ import kotlin.internal.*
|
||||
|
||||
/** Returns a buffered reader wrapping this Reader, or this Reader itself if it is already buffered. */
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Reader.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader
|
||||
= if (this is BufferedReader) this else BufferedReader(this, bufferSize)
|
||||
public inline fun Reader.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader =
|
||||
if (this is BufferedReader) this else BufferedReader(this, bufferSize)
|
||||
|
||||
/** Returns a buffered reader wrapping this Writer, or this Writer itself if it is already buffered. */
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Writer.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter
|
||||
= if (this is BufferedWriter) this else BufferedWriter(this, bufferSize)
|
||||
public inline fun Writer.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter =
|
||||
if (this is BufferedWriter) this else BufferedWriter(this, bufferSize)
|
||||
|
||||
/**
|
||||
* Iterates through each line of this reader, calls [action] for each line read
|
||||
@@ -49,7 +50,7 @@ public fun Reader.readLines(): List<String> {
|
||||
*/
|
||||
@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION, message = "Requires newer compiler version to be inlined correctly.")
|
||||
public inline fun <T> Reader.useLines(block: (Sequence<String>) -> T): T =
|
||||
buffered().use { block(it.lineSequence()) }
|
||||
buffered().use { block(it.lineSequence()) }
|
||||
|
||||
/** Creates a new reader for the string. */
|
||||
@kotlin.internal.InlineOnly
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("FilesKt")
|
||||
|
||||
package kotlin.io
|
||||
|
||||
import java.io.File
|
||||
@@ -141,7 +142,7 @@ internal fun File.toComponents(): FilePathComponents {
|
||||
* Number 0 belongs to a component closest to the root,
|
||||
* number count-1 belongs to a component farthest from the root.
|
||||
* @throws IllegalArgumentException if [beginIndex] is negative,
|
||||
* or [endIndex] is greater than existing number of components,
|
||||
* or [beginIndex] is greater than [endIndex].
|
||||
* or [endIndex] is greater than existing number of components,
|
||||
* or [beginIndex] is greater than [endIndex].
|
||||
*/
|
||||
internal fun File.subPath(beginIndex: Int, endIndex: Int): File = toComponents().subPath(beginIndex, endIndex)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("FilesKt")
|
||||
|
||||
package kotlin.io
|
||||
|
||||
import kotlin.*
|
||||
@@ -35,15 +36,15 @@ public enum class FileWalkDirection {
|
||||
* If the file path given does not exist, walker iterates nothing, i.e. it's equivalent to an empty sequence.
|
||||
*/
|
||||
public class FileTreeWalk private constructor(
|
||||
private val start: File,
|
||||
private val direction: FileWalkDirection = FileWalkDirection.TOP_DOWN,
|
||||
private val onEnter: ((File) -> Boolean)?,
|
||||
private val onLeave: ((File) -> Unit)?,
|
||||
private val onFail: ((f: File, e: IOException) -> Unit)?,
|
||||
private val maxDepth: Int = Int.MAX_VALUE
|
||||
private val start: File,
|
||||
private val direction: FileWalkDirection = FileWalkDirection.TOP_DOWN,
|
||||
private val onEnter: ((File) -> Boolean)?,
|
||||
private val onLeave: ((File) -> Unit)?,
|
||||
private val onFail: ((f: File, e: IOException) -> Unit)?,
|
||||
private val maxDepth: Int = Int.MAX_VALUE
|
||||
) : Sequence<File> {
|
||||
|
||||
internal constructor(start: File, direction: FileWalkDirection = FileWalkDirection.TOP_DOWN): this(start, direction, null, null, null)
|
||||
internal constructor(start: File, direction: FileWalkDirection = FileWalkDirection.TOP_DOWN) : this(start, direction, null, null, null)
|
||||
|
||||
|
||||
/** Returns an iterator walking through files. */
|
||||
@@ -56,7 +57,7 @@ public class FileTreeWalk private constructor(
|
||||
}
|
||||
|
||||
/** Abstract class that encapsulates directory visiting in some order, beginning from a given [rootDir] */
|
||||
private abstract class DirectoryState(rootDir: File): WalkState(rootDir) {
|
||||
private abstract class DirectoryState(rootDir: File) : WalkState(rootDir) {
|
||||
init {
|
||||
if (_Assertions.ENABLED)
|
||||
assert(rootDir.isDirectory) { "rootDir must be verified to be directory beforehand." }
|
||||
@@ -265,7 +266,7 @@ public class FileTreeWalk private constructor(
|
||||
* @param direction walk direction, top-down (by default) or bottom-up.
|
||||
*/
|
||||
public fun File.walk(direction: FileWalkDirection = FileWalkDirection.TOP_DOWN): FileTreeWalk =
|
||||
FileTreeWalk(this, direction)
|
||||
FileTreeWalk(this, direction)
|
||||
|
||||
/**
|
||||
* Gets a sequence for visiting this directory and all its content in top-down order.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("FilesKt")
|
||||
|
||||
package kotlin.io
|
||||
|
||||
import java.io.*
|
||||
@@ -21,7 +22,7 @@ import kotlin.comparisons.*
|
||||
* If [directory] is not specified then the default temporary-file directory will be used.
|
||||
*
|
||||
* @return a file object corresponding to a newly-created directory.
|
||||
*
|
||||
*
|
||||
* @throws IOException in case of input/output error.
|
||||
* @throws IllegalArgumentException if [prefix] is shorter than three symbols.
|
||||
*/
|
||||
@@ -43,7 +44,7 @@ public fun createTempDir(prefix: String = "tmp", suffix: String? = null, directo
|
||||
* If [directory] is not specified then the default temporary-file directory will be used.
|
||||
*
|
||||
* @return a file object corresponding to a newly-created file.
|
||||
*
|
||||
*
|
||||
* @throws IOException in case of input/output error.
|
||||
* @throws IllegalArgumentException if [prefix] is shorter than three symbols.
|
||||
*/
|
||||
@@ -79,8 +80,8 @@ public val File.nameWithoutExtension: String
|
||||
*
|
||||
* @throws IllegalArgumentException if this and base paths have different roots.
|
||||
*/
|
||||
public fun File.toRelativeString(base: File): String
|
||||
= toRelativeStringOrNull(base) ?: throw IllegalArgumentException("this and base files have different roots: $this and $base.")
|
||||
public fun File.toRelativeString(base: File): String =
|
||||
toRelativeStringOrNull(base) ?: throw IllegalArgumentException("this and base files have different roots: $this and $base.")
|
||||
|
||||
/**
|
||||
* Calculates the relative path for this file from [base] file.
|
||||
@@ -100,8 +101,8 @@ public fun File.relativeTo(base: File): File = File(this.toRelativeString(base))
|
||||
*
|
||||
* @return File with relative path from [base] to this, or `this` if this and base paths have different roots.
|
||||
*/
|
||||
public fun File.relativeToOrSelf(base: File): File
|
||||
= toRelativeStringOrNull(base)?.let(::File) ?: this
|
||||
public fun File.relativeToOrSelf(base: File): File =
|
||||
toRelativeStringOrNull(base)?.let(::File) ?: this
|
||||
|
||||
/**
|
||||
* Calculates the relative path for this file from [base] file.
|
||||
@@ -110,8 +111,8 @@ public fun File.relativeToOrSelf(base: File): File
|
||||
*
|
||||
* @return File with relative path from [base] to this, or `null` if this and base paths have different roots.
|
||||
*/
|
||||
public fun File.relativeToOrNull(base: File): File?
|
||||
= toRelativeStringOrNull(base)?.let(::File)
|
||||
public fun File.relativeToOrNull(base: File): File? =
|
||||
toRelativeStringOrNull(base)?.let(::File)
|
||||
|
||||
|
||||
private fun File.toRelativeStringOrNull(base: File): String? {
|
||||
@@ -125,7 +126,7 @@ private fun File.toRelativeStringOrNull(base: File): String? {
|
||||
val baseCount = baseComponents.size
|
||||
val thisCount = thisComponents.size
|
||||
|
||||
val sameCount = run countSame@ {
|
||||
val sameCount = run countSame@{
|
||||
var i = 0
|
||||
val maxSameCount = minOf(thisCount, baseCount)
|
||||
while (i < maxSameCount && thisComponents.segments[i] == baseComponents.segments[i])
|
||||
@@ -189,9 +190,11 @@ public fun File.copyTo(target: File, overwrite: Boolean = false, bufferSize: Int
|
||||
val stillExists = if (!overwrite) true else !target.delete()
|
||||
|
||||
if (stillExists) {
|
||||
throw FileAlreadyExistsException(file = this,
|
||||
other = target,
|
||||
reason = "The destination file already exists.")
|
||||
throw FileAlreadyExistsException(
|
||||
file = this,
|
||||
other = target,
|
||||
reason = "The destination file already exists."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,10 +257,10 @@ private class TerminateException(file: File) : FileSystemException(file) {}
|
||||
* @param overwrite `true` if it is allowed to overwrite existing destination files and directories.
|
||||
* @return `false` if the copying was terminated, `true` otherwise.
|
||||
*/
|
||||
public fun File.copyRecursively(target: File,
|
||||
overwrite: Boolean = false,
|
||||
onError: (File, IOException) -> OnErrorAction =
|
||||
{ _, exception -> throw exception }
|
||||
public fun File.copyRecursively(
|
||||
target: File,
|
||||
overwrite: Boolean = false,
|
||||
onError: (File, IOException) -> OnErrorAction = { _, exception -> throw exception }
|
||||
): Boolean {
|
||||
if (!exists()) {
|
||||
return onError(this, NoSuchFileException(file = this, reason = "The source file doesn't exist.")) !=
|
||||
@@ -375,11 +378,11 @@ public fun File.endsWith(other: String): Boolean = endsWith(File(other))
|
||||
*
|
||||
* @return normalized pathname with . and possibly .. removed.
|
||||
*/
|
||||
public fun File.normalize(): File
|
||||
= with (toComponents()) { root.resolve(segments.normalize().joinToString(File.separator)) }
|
||||
public fun File.normalize(): File =
|
||||
with(toComponents()) { root.resolve(segments.normalize().joinToString(File.separator)) }
|
||||
|
||||
private fun FilePathComponents.normalize(): FilePathComponents
|
||||
= FilePathComponents(root, segments.normalize())
|
||||
private fun FilePathComponents.normalize(): FilePathComponents =
|
||||
FilePathComponents(root, segments.normalize())
|
||||
|
||||
private fun List<File>.normalize(): List<File> {
|
||||
val list: MutableList<File> = ArrayList(this.size)
|
||||
|
||||
@@ -7,6 +7,8 @@ package kotlin.jvm.internal.unsafe
|
||||
|
||||
import kotlin.*
|
||||
|
||||
private fun monitorEnter(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
|
||||
private fun monitorEnter(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit =
|
||||
throw UnsupportedOperationException("This function can only be used privately")
|
||||
|
||||
private fun monitorExit(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
|
||||
private fun monitorExit(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit =
|
||||
throw UnsupportedOperationException("This function can only be used privately")
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("RangesKt")
|
||||
|
||||
package kotlin.ranges
|
||||
|
||||
import kotlin.*
|
||||
@@ -14,10 +15,10 @@ import kotlin.*
|
||||
*
|
||||
* Numbers are compared with the ends of this range according to IEEE-754.
|
||||
*/
|
||||
private class ClosedFloatRange (
|
||||
private class ClosedFloatRange(
|
||||
start: Float,
|
||||
endInclusive: Float
|
||||
): ClosedFloatingPointRange<Float> {
|
||||
) : ClosedFloatingPointRange<Float> {
|
||||
private val _start = start
|
||||
private val _endInclusive = endInclusive
|
||||
override val start: Float get() = _start
|
||||
@@ -36,6 +37,7 @@ private class ClosedFloatRange (
|
||||
override fun hashCode(): Int {
|
||||
return if (isEmpty()) -1 else 31 * _start.hashCode() + _endInclusive.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String = "$_start..$_endInclusive"
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ package kotlin.system
|
||||
/**
|
||||
* Executes the given block and returns elapsed time in milliseconds.
|
||||
*/
|
||||
public inline fun measureTimeMillis(block: () -> Unit) : Long {
|
||||
public inline fun measureTimeMillis(block: () -> Unit): Long {
|
||||
val start = System.currentTimeMillis()
|
||||
block()
|
||||
return System.currentTimeMillis() - start
|
||||
@@ -18,7 +18,7 @@ public inline fun measureTimeMillis(block: () -> Unit) : Long {
|
||||
/**
|
||||
* Executes the given block and returns elapsed time in nanoseconds.
|
||||
*/
|
||||
public inline fun measureNanoTime(block: () -> Unit) : Long {
|
||||
public inline fun measureNanoTime(block: () -> Unit): Long {
|
||||
val start = System.nanoTime()
|
||||
block()
|
||||
return System.nanoTime() - start
|
||||
|
||||
@@ -141,7 +141,7 @@ internal actual fun digitOf(char: Char, radix: Int): Int = Character.digit(char.
|
||||
*/
|
||||
@PublishedApi
|
||||
internal actual fun checkRadix(radix: Int): Int {
|
||||
if(radix !in Character.MIN_RADIX..Character.MAX_RADIX) {
|
||||
if (radix !in Character.MIN_RADIX..Character.MAX_RADIX) {
|
||||
throw IllegalArgumentException("radix $radix was not in valid range ${Character.MIN_RADIX..Character.MAX_RADIX}")
|
||||
}
|
||||
return radix
|
||||
|
||||
@@ -267,7 +267,7 @@ private inline fun <T> screenFloatValue(str: String, parse: (String) -> T): T? {
|
||||
parse(str)
|
||||
else
|
||||
null
|
||||
} catch(e: NumberFormatException) { // overflow
|
||||
} catch (e: NumberFormatException) { // overflow
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boole
|
||||
*/
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String =
|
||||
splitToSequence(oldValue, ignoreCase = ignoreCase).joinToString(separator = newValue)
|
||||
splitToSequence(oldValue, ignoreCase = ignoreCase).joinToString(separator = newValue)
|
||||
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,12 @@ public inline fun String.toCharArray(): CharArray = (this as java.lang.String).t
|
||||
* @param endIndex the end offset (exclusive) of the substring to copy.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String.toCharArray(destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = length): CharArray {
|
||||
public inline fun String.toCharArray(
|
||||
destination: CharArray,
|
||||
destinationOffset: Int = 0,
|
||||
startIndex: Int = 0,
|
||||
endIndex: Int = length
|
||||
): CharArray {
|
||||
(this as java.lang.String).getChars(startIndex, endIndex, destination, destinationOffset)
|
||||
return destination
|
||||
}
|
||||
@@ -143,14 +148,15 @@ public inline fun String.Companion.format(format: String, vararg args: Any?): St
|
||||
* using the specified locale.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String.format(locale: Locale, vararg args : Any?) : String = java.lang.String.format(locale, this, *args)
|
||||
public inline fun String.format(locale: Locale, vararg args: Any?): String = java.lang.String.format(locale, this, *args)
|
||||
|
||||
/**
|
||||
* Uses the provided [format] as a format string and returns a string obtained by substituting the specified arguments,
|
||||
* using the specified locale.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String.Companion.format(locale: Locale, format: String, vararg args: Any?): String = java.lang.String.format(locale, format, *args)
|
||||
public inline fun String.Companion.format(locale: Locale, format: String, vararg args: Any?): String =
|
||||
java.lang.String.format(locale, format, *args)
|
||||
|
||||
/**
|
||||
* Splits this char sequence around matches of the given regular expression.
|
||||
@@ -158,9 +164,8 @@ public inline fun String.Companion.format(locale: Locale, format: String, vararg
|
||||
* @param limit Non-negative value specifying the maximum number of substrings to return.
|
||||
* Zero by default means no limit is set.
|
||||
*/
|
||||
public fun CharSequence.split(regex: Pattern, limit: Int = 0): List<String>
|
||||
{
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit." } )
|
||||
public fun CharSequence.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()
|
||||
}
|
||||
|
||||
@@ -221,7 +226,8 @@ public fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean
|
||||
* @param charset the character set to use.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String(bytes: ByteArray, offset: Int, length: Int, charset: Charset): String = java.lang.String(bytes, offset, length, charset) as String
|
||||
public inline fun String(bytes: ByteArray, offset: Int, length: Int, charset: Charset): String =
|
||||
java.lang.String(bytes, offset, length, charset) as String
|
||||
|
||||
/**
|
||||
* Converts the data from the specified array of bytes to characters using the specified character set
|
||||
@@ -239,44 +245,51 @@ public inline fun String(bytes: ByteArray, charset: Charset): String = java.lang
|
||||
* @param length the number of bytes to be converted.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String(bytes: ByteArray, offset: Int, length: Int): String = java.lang.String(bytes, offset, length, Charsets.UTF_8) as String
|
||||
public inline fun String(bytes: ByteArray, offset: Int, length: Int): String =
|
||||
java.lang.String(bytes, offset, length, Charsets.UTF_8) as String
|
||||
|
||||
/**
|
||||
* Converts the data from the specified array of bytes to characters using the UTF-8 character set
|
||||
* and returns the conversion result as a string.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String(bytes: ByteArray): String = java.lang.String(bytes, Charsets.UTF_8) as String
|
||||
public inline fun String(bytes: ByteArray): String =
|
||||
java.lang.String(bytes, Charsets.UTF_8) as String
|
||||
|
||||
/**
|
||||
* Converts the characters in the specified array to a string.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String(chars: CharArray): String = java.lang.String(chars) as String
|
||||
public inline fun String(chars: CharArray): String =
|
||||
java.lang.String(chars) as String
|
||||
|
||||
/**
|
||||
* Converts the characters from a portion of the specified array to a string.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String(chars: CharArray, offset: Int, length: Int): String = java.lang.String(chars, offset, length) as String
|
||||
public inline fun String(chars: CharArray, offset: Int, length: Int): String =
|
||||
java.lang.String(chars, offset, length) as String
|
||||
|
||||
/**
|
||||
* Converts the code points from a portion of the specified Unicode code point array to a string.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String(codePoints: IntArray, offset: Int, length: Int): String = java.lang.String(codePoints, offset, length) as String
|
||||
public inline fun String(codePoints: IntArray, offset: Int, length: Int): String =
|
||||
java.lang.String(codePoints, offset, length) as String
|
||||
|
||||
/**
|
||||
* Converts the contents of the specified StringBuffer to a string.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String(stringBuffer: java.lang.StringBuffer): String = java.lang.String(stringBuffer) as String
|
||||
public inline fun String(stringBuffer: java.lang.StringBuffer): String =
|
||||
java.lang.String(stringBuffer) as String
|
||||
|
||||
/**
|
||||
* Converts the contents of the specified StringBuilder to a string.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String(stringBuilder: java.lang.StringBuilder): String = java.lang.String(stringBuilder) as String
|
||||
public inline fun String(stringBuilder: java.lang.StringBuilder): String =
|
||||
java.lang.String(stringBuilder) as String
|
||||
|
||||
/**
|
||||
* Returns the character (Unicode code point) at the specified index.
|
||||
@@ -294,7 +307,8 @@ public inline fun String.codePointBefore(index: Int): Int = (this as java.lang.S
|
||||
* Returns the number of Unicode code points in the specified text range of this String.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String.codePointCount(beginIndex: Int, endIndex: Int): Int = (this as java.lang.String).codePointCount(beginIndex, endIndex)
|
||||
public inline fun String.codePointCount(beginIndex: Int, endIndex: Int): Int =
|
||||
(this as java.lang.String).codePointCount(beginIndex, endIndex)
|
||||
|
||||
/**
|
||||
* Compares two strings lexicographically, optionally ignoring case differences.
|
||||
@@ -333,7 +347,8 @@ public actual fun CharSequence.isBlank(): Boolean = length == 0 || indices.all {
|
||||
* Returns the index within this string that is offset from the given [index] by [codePointOffset] code points.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun String.offsetByCodePoints(index: Int, codePointOffset: Int): Int = (this as java.lang.String).offsetByCodePoints(index, codePointOffset)
|
||||
public inline fun String.offsetByCodePoints(index: Int, codePointOffset: Int): Int =
|
||||
(this as java.lang.String).offsetByCodePoints(index, codePointOffset)
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified range in this char sequence is equal to the specified range in another char sequence.
|
||||
@@ -358,10 +373,10 @@ public actual fun CharSequence.regionMatches(thisOffset: Int, other: CharSequenc
|
||||
* @param length the length of the substring to compare.
|
||||
*/
|
||||
public fun String.regionMatches(thisOffset: Int, other: String, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean =
|
||||
if (!ignoreCase)
|
||||
(this as java.lang.String).regionMatches(thisOffset, other, otherOffset, length)
|
||||
else
|
||||
(this as java.lang.String).regionMatches(ignoreCase, thisOffset, other, otherOffset, length)
|
||||
if (!ignoreCase)
|
||||
(this as java.lang.String).regionMatches(thisOffset, other, otherOffset, length)
|
||||
else
|
||||
(this as java.lang.String).regionMatches(ignoreCase, thisOffset, other, otherOffset, length)
|
||||
|
||||
/**
|
||||
* Returns a copy of this string converted to lower case using the rules of the specified locale.
|
||||
@@ -418,7 +433,7 @@ public actual fun String.decapitalize(): String {
|
||||
* @sample samples.text.Strings.repeat
|
||||
*/
|
||||
public actual fun CharSequence.repeat(n: Int): String {
|
||||
require (n >= 0) { "Count 'n' must be non-negative, but was $n." }
|
||||
require(n >= 0) { "Count 'n' must be non-negative, but was $n." }
|
||||
|
||||
return when (n) {
|
||||
0 -> ""
|
||||
|
||||
@@ -14,12 +14,14 @@ private interface FlagEnum {
|
||||
public val value: Int
|
||||
public val mask: Int
|
||||
}
|
||||
|
||||
private fun Iterable<FlagEnum>.toInt(): Int =
|
||||
this.fold(0, { value, option -> value or option.value })
|
||||
private inline fun <reified T> fromInt(value: Int): Set<T> where T : FlagEnum, T: Enum<T> =
|
||||
Collections.unmodifiableSet(EnumSet.allOf(T::class.java).apply {
|
||||
retainAll { value and it.mask == it.value }
|
||||
})
|
||||
this.fold(0, { value, option -> value or option.value })
|
||||
|
||||
private inline fun <reified T> fromInt(value: Int): Set<T> where T : FlagEnum, T : Enum<T> =
|
||||
Collections.unmodifiableSet(EnumSet.allOf(T::class.java).apply {
|
||||
retainAll { value and it.mask == it.value }
|
||||
})
|
||||
|
||||
/**
|
||||
* Provides enumeration values to use to set regular expression options.
|
||||
@@ -87,13 +89,13 @@ internal constructor(private val nativePattern: Pattern) : Serializable {
|
||||
|
||||
|
||||
/** Creates a regular expression from the specified [pattern] string and the default options. */
|
||||
public actual constructor(pattern: String): this(Pattern.compile(pattern))
|
||||
public actual constructor(pattern: String) : this(Pattern.compile(pattern))
|
||||
|
||||
/** Creates a regular expression from the specified [pattern] string and the specified single [option]. */
|
||||
public actual constructor(pattern: String, option: RegexOption): this(Pattern.compile(pattern, ensureUnicodeCase(option.value)))
|
||||
public actual constructor(pattern: String, option: RegexOption) : this(Pattern.compile(pattern, ensureUnicodeCase(option.value)))
|
||||
|
||||
/** Creates a regular expression from the specified [pattern] string and the specified set of [options]. */
|
||||
public actual constructor(pattern: String, options: Set<RegexOption>): this(Pattern.compile(pattern, ensureUnicodeCase(options.toInt())))
|
||||
public actual constructor(pattern: String, options: Set<RegexOption>) : this(Pattern.compile(pattern, ensureUnicodeCase(options.toInt())))
|
||||
|
||||
|
||||
/** The pattern string of this regular expression. */
|
||||
@@ -117,13 +119,15 @@ internal constructor(private val nativePattern: Pattern) : Serializable {
|
||||
* @return An instance of [MatchResult] if match was found or `null` otherwise.
|
||||
*/
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.matcher(input).findNext(startIndex, input)
|
||||
public actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? =
|
||||
nativePattern.matcher(input).findNext(startIndex, input)
|
||||
|
||||
/**
|
||||
* Returns a sequence of all occurrences of a regular expression within the [input] string, beginning at the specified [startIndex].
|
||||
*/
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = generateSequence({ find(input, startIndex) }, MatchResult::next)
|
||||
public actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> =
|
||||
generateSequence({ find(input, startIndex) }, MatchResult::next)
|
||||
|
||||
/**
|
||||
* Attempts to match the entire [input] CharSequence against the pattern.
|
||||
@@ -170,7 +174,8 @@ internal constructor(private val nativePattern: Pattern) : Serializable {
|
||||
*
|
||||
* @param replacement A replacement expression that can include substitutions. See [Matcher.appendReplacement] for details.
|
||||
*/
|
||||
public actual fun replaceFirst(input: CharSequence, replacement: String): String = nativePattern.matcher(input).replaceFirst(replacement)
|
||||
public actual fun replaceFirst(input: CharSequence, replacement: String): String =
|
||||
nativePattern.matcher(input).replaceFirst(replacement)
|
||||
|
||||
|
||||
/**
|
||||
@@ -181,7 +186,7 @@ internal constructor(private val nativePattern: Pattern) : Serializable {
|
||||
*/
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun split(input: CharSequence, limit: Int = 0): List<String> {
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit." } )
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit." })
|
||||
return nativePattern.split(input, if (limit == 0) -1 else limit).asList()
|
||||
}
|
||||
|
||||
@@ -208,8 +213,10 @@ internal constructor(private val nativePattern: Pattern) : Serializable {
|
||||
actual companion object {
|
||||
/** Returns a literal regex for the specified [literal] string. */
|
||||
public actual fun fromLiteral(literal: String): Regex = literal.toRegex(RegexOption.LITERAL)
|
||||
|
||||
/** Returns a literal pattern for the specified [literal] string. */
|
||||
public actual fun escape(literal: String): String = Pattern.quote(literal)
|
||||
|
||||
/** Returns a literal replacement expression for the specified [literal] string. */
|
||||
public actual fun escapeReplacement(literal: String): String = Matcher.quoteReplacement(literal)
|
||||
|
||||
@@ -247,6 +254,7 @@ private class MatcherMatchResult(private val matcher: Matcher, private val input
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
override fun get(name: String): MatchGroup? {
|
||||
return IMPLEMENTATIONS.getMatchResultNamedGroup(matchResult, name)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ package kotlin
|
||||
|
||||
@PublishedApi
|
||||
internal object _Assertions {
|
||||
@JvmField @PublishedApi
|
||||
@JvmField
|
||||
@PublishedApi
|
||||
internal val ENABLED: Boolean = javaClass.desiredAssertionStatus()
|
||||
}
|
||||
|
||||
|
||||
@@ -125,5 +125,5 @@ public inline fun BigInteger.toBigDecimal(): BigDecimal = BigDecimal(this)
|
||||
@SinceKotlin("1.2")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun BigInteger.toBigDecimal(scale: Int = 0, mathContext: MathContext = MathContext.UNLIMITED): BigDecimal =
|
||||
BigDecimal(this, scale, mathContext)
|
||||
BigDecimal(this, scale, mathContext)
|
||||
|
||||
|
||||
@@ -70,8 +70,7 @@ private class SynchronizedLazyImpl<out T>(initializer: () -> T, lock: Any? = nul
|
||||
val _v2 = _value
|
||||
if (_v2 !== UNINITIALIZED_VALUE) {
|
||||
@Suppress("UNCHECKED_CAST") (_v2 as T)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
val typedValue = initializer!!()
|
||||
_value = typedValue
|
||||
initializer = null
|
||||
@@ -125,6 +124,7 @@ private class SafePublicationLazyImpl<out T>(initializer: () -> T) : Lazy<T>, Se
|
||||
private val valueUpdater = java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(
|
||||
SafePublicationLazyImpl::class.java,
|
||||
Any::class.java,
|
||||
"_value")
|
||||
"_value"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -439,6 +439,7 @@ public actual inline fun sign(x: Double): Double = nativeMath.signum(x)
|
||||
@SinceKotlin("1.2")
|
||||
@InlineOnly
|
||||
public actual inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b)
|
||||
|
||||
/**
|
||||
* Returns the greater of two values.
|
||||
*
|
||||
@@ -524,6 +525,7 @@ public actual inline val Double.sign: Double get() = nativeMath.signum(this)
|
||||
@SinceKotlin("1.2")
|
||||
@InlineOnly
|
||||
public actual inline fun Double.withSign(sign: Double): Double = nativeMath.copySign(this, sign)
|
||||
|
||||
/**
|
||||
* Returns this value with the sign bit same as of the [sign] value.
|
||||
*/
|
||||
@@ -551,6 +553,7 @@ public actual inline val Double.ulp: Double get() = nativeMath.ulp(this)
|
||||
@SinceKotlin("1.2")
|
||||
@InlineOnly
|
||||
public actual inline fun Double.nextUp(): Double = nativeMath.nextUp(this)
|
||||
|
||||
/**
|
||||
* Returns the [Double] value nearest to this value in direction of negative infinity.
|
||||
*/
|
||||
@@ -599,8 +602,8 @@ public actual fun Double.roundToInt(): Int = when {
|
||||
* @throws IllegalArgumentException when this value is `NaN`
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public actual fun Double.roundToLong(): Long = if (isNaN()) throw IllegalArgumentException("Cannot round NaN value.") else nativeMath.round(this)
|
||||
|
||||
public actual fun Double.roundToLong(): Long =
|
||||
if (isNaN()) throw IllegalArgumentException("Cannot round NaN value.") else nativeMath.round(this)
|
||||
|
||||
|
||||
// ================ Float Math ========================================
|
||||
@@ -963,6 +966,7 @@ public actual inline fun sign(x: Float): Float = nativeMath.signum(x)
|
||||
@SinceKotlin("1.2")
|
||||
@InlineOnly
|
||||
public actual inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b)
|
||||
|
||||
/**
|
||||
* Returns the greater of two values.
|
||||
*
|
||||
@@ -1048,6 +1052,7 @@ public actual inline val Float.sign: Float get() = nativeMath.signum(this)
|
||||
@SinceKotlin("1.2")
|
||||
@InlineOnly
|
||||
public actual inline fun Float.withSign(sign: Float): Float = nativeMath.copySign(this, sign)
|
||||
|
||||
/**
|
||||
* Returns this value with the sign bit same as of the [sign] value.
|
||||
*/
|
||||
@@ -1075,6 +1080,7 @@ public inline val Float.ulp: Float get() = nativeMath.ulp(this)
|
||||
@SinceKotlin("1.2")
|
||||
@InlineOnly
|
||||
public inline fun Float.nextUp(): Float = nativeMath.nextUp(this)
|
||||
|
||||
/**
|
||||
* Returns the [Float] value nearest to this value in direction of negative infinity.
|
||||
*/
|
||||
@@ -1105,7 +1111,8 @@ public inline fun Float.nextTowards(to: Float): Float = nativeMath.nextAfter(thi
|
||||
* @throws IllegalArgumentException when this value is `NaN`
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public actual fun Float.roundToInt(): Int = if (isNaN()) throw IllegalArgumentException("Cannot round NaN value.") else nativeMath.round(this)
|
||||
public actual fun Float.roundToInt(): Int =
|
||||
if (isNaN()) throw IllegalArgumentException("Cannot round NaN value.") else nativeMath.round(this)
|
||||
|
||||
/**
|
||||
* Rounds this [Float] value to the nearest integer and converts the result to [Long].
|
||||
|
||||
Reference in New Issue
Block a user