Reformat stdlib: jvm part
#KT-5558
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
@file:Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@file:Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
@file:JvmName("CollectionsJDK8Kt")
|
@file:JvmName("CollectionsJDK8Kt")
|
||||||
@file:kotlin.jvm.JvmPackageName("kotlin.collections.jdk8")
|
@file:kotlin.jvm.JvmPackageName("kotlin.collections.jdk8")
|
||||||
|
|
||||||
package kotlin.collections
|
package kotlin.collections
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,8 +26,8 @@ package kotlin.collections
|
|||||||
*/
|
*/
|
||||||
@SinceKotlin("1.2")
|
@SinceKotlin("1.2")
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.getOrDefault(key: K, defaultValue: V): V
|
public inline fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.getOrDefault(key: K, defaultValue: V): V =
|
||||||
= (this as Map<K, V>).getOrDefault(key, defaultValue)
|
(this as Map<K, V>).getOrDefault(key, defaultValue)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,5 +36,5 @@ public inline fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.getOrDefa
|
|||||||
*/
|
*/
|
||||||
@SinceKotlin("1.2")
|
@SinceKotlin("1.2")
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun <@kotlin.internal.OnlyInputTypes K, @kotlin.internal.OnlyInputTypes V> MutableMap<out K, out V>.remove(key: K, value: V): Boolean
|
public inline fun <@kotlin.internal.OnlyInputTypes K, @kotlin.internal.OnlyInputTypes V> MutableMap<out K, out V>.remove(key: K, value: V): Boolean =
|
||||||
= (this as MutableMap<K, V>).remove(key, value)
|
(this as MutableMap<K, V>).remove(key, value)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ internal open class JDK8PlatformImplementations : JDK7PlatformImplementations()
|
|||||||
override fun getMatchResultNamedGroup(matchResult: MatchResult, name: String): MatchGroup? {
|
override fun getMatchResultNamedGroup(matchResult: MatchResult, name: String): MatchGroup? {
|
||||||
val matcher = matchResult as? Matcher ?: throw UnsupportedOperationException("Retrieving groups by name is not supported on this platform.")
|
val matcher = matchResult as? Matcher ?: throw UnsupportedOperationException("Retrieving groups by name is not supported on this platform.")
|
||||||
|
|
||||||
val range = matcher.start(name)..matcher.end(name)-1
|
val range = matcher.start(name)..matcher.end(name) - 1
|
||||||
return if (range.start >= 0)
|
return if (range.start >= 0)
|
||||||
MatchGroup(matcher.group(name), range)
|
MatchGroup(matcher.group(name), range)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ public fun DoubleStream.asSequence(): Sequence<Double> = Sequence { iterator() }
|
|||||||
* Creates a sequential [Stream] instance that produces elements from the original sequence.
|
* Creates a sequential [Stream] instance that produces elements from the original sequence.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.2")
|
@SinceKotlin("1.2")
|
||||||
public fun <T> Sequence<T>.asStream(): Stream<T> = StreamSupport.stream({ Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED) }, Spliterator.ORDERED, false)
|
public fun <T> Sequence<T>.asStream(): Stream<T> =
|
||||||
|
StreamSupport.stream({ Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED) }, Spliterator.ORDERED, false)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a [List] containing all elements produced by this stream.
|
* Returns a [List] containing all elements produced by this stream.
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ package kotlin.text
|
|||||||
*/
|
*/
|
||||||
@SinceKotlin("1.2")
|
@SinceKotlin("1.2")
|
||||||
public operator fun MatchGroupCollection.get(name: String): MatchGroup? {
|
public operator fun MatchGroupCollection.get(name: String): MatchGroup? {
|
||||||
val namedGroups = this as? MatchNamedGroupCollection ?:
|
val namedGroups = this as? MatchNamedGroupCollection
|
||||||
throw UnsupportedOperationException("Retrieving groups by name is not supported on this platform.")
|
?: throw UnsupportedOperationException("Retrieving groups by name is not supported on this platform.")
|
||||||
|
|
||||||
return namedGroups[name]
|
return namedGroups[name]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class StreamsTest {
|
|||||||
|
|
||||||
fun<T> assertSequenceContent(expected: List<T>, actual: Sequence<T>) {
|
fun<T> assertSequenceContent(expected: List<T>, actual: Sequence<T>) {
|
||||||
assertEquals(expected, actual.toList())
|
assertEquals(expected, actual.toList())
|
||||||
assertFailsWith<IllegalStateException> ("Second iteration fails") { actual.toList() }
|
assertFailsWith<IllegalStateException>("Second iteration fails") { actual.toList() }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,12 +83,12 @@ public val <T : Any> Class<T>.kotlin: KClass<T>
|
|||||||
/**
|
/**
|
||||||
* Returns the runtime Java class of this object.
|
* Returns the runtime Java class of this object.
|
||||||
*/
|
*/
|
||||||
public inline val <T: Any> T.javaClass : Class<T>
|
public inline val <T : Any> T.javaClass: Class<T>
|
||||||
@Suppress("UsePropertyAccessSyntax")
|
@Suppress("UsePropertyAccessSyntax")
|
||||||
get() = (this as java.lang.Object).getClass() as Class<T>
|
get() = (this as java.lang.Object).getClass() as Class<T>
|
||||||
|
|
||||||
@Deprecated("Use 'java' property to get Java class corresponding to this Kotlin class or cast this instance to Any if you really want to get the runtime Java class of this implementation of KClass.", ReplaceWith("(this as Any).javaClass"), level = DeprecationLevel.ERROR)
|
@Deprecated("Use 'java' property to get Java class corresponding to this Kotlin class or cast this instance to Any if you really want to get the runtime Java class of this implementation of KClass.", ReplaceWith("(this as Any).javaClass"), level = DeprecationLevel.ERROR)
|
||||||
public inline val <T: Any> KClass<T>.javaClass: Class<KClass<T>>
|
public inline val <T : Any> KClass<T>.javaClass: Class<KClass<T>>
|
||||||
@JvmName("getRuntimeClassOfKClassInstance")
|
@JvmName("getRuntimeClassOfKClassInstance")
|
||||||
@Suppress("UsePropertyAccessSyntax")
|
@Suppress("UsePropertyAccessSyntax")
|
||||||
get() = (this as java.lang.Object).getClass() as Class<KClass<T>>
|
get() = (this as java.lang.Object).getClass() as Class<KClass<T>>
|
||||||
|
|||||||
@@ -8,17 +8,17 @@ package kotlin.jvm.internal
|
|||||||
internal object DoubleCompanionObject {
|
internal object DoubleCompanionObject {
|
||||||
val MIN_VALUE: Double = java.lang.Double.MIN_VALUE
|
val MIN_VALUE: Double = java.lang.Double.MIN_VALUE
|
||||||
val MAX_VALUE: Double = java.lang.Double.MAX_VALUE
|
val MAX_VALUE: Double = java.lang.Double.MAX_VALUE
|
||||||
val POSITIVE_INFINITY : Double = java.lang.Double.POSITIVE_INFINITY
|
val POSITIVE_INFINITY: Double = java.lang.Double.POSITIVE_INFINITY
|
||||||
val NEGATIVE_INFINITY : Double = java.lang.Double.NEGATIVE_INFINITY
|
val NEGATIVE_INFINITY: Double = java.lang.Double.NEGATIVE_INFINITY
|
||||||
val NaN : Double = java.lang.Double.NaN
|
val NaN: Double = java.lang.Double.NaN
|
||||||
}
|
}
|
||||||
|
|
||||||
internal object FloatCompanionObject {
|
internal object FloatCompanionObject {
|
||||||
val MIN_VALUE: Float = java.lang.Float.MIN_VALUE
|
val MIN_VALUE: Float = java.lang.Float.MIN_VALUE
|
||||||
val MAX_VALUE: Float = java.lang.Float.MAX_VALUE
|
val MAX_VALUE: Float = java.lang.Float.MAX_VALUE
|
||||||
val POSITIVE_INFINITY : Float = java.lang.Float.POSITIVE_INFINITY
|
val POSITIVE_INFINITY: Float = java.lang.Float.POSITIVE_INFINITY
|
||||||
val NEGATIVE_INFINITY : Float = java.lang.Float.NEGATIVE_INFINITY
|
val NEGATIVE_INFINITY: Float = java.lang.Float.NEGATIVE_INFINITY
|
||||||
val NaN : Float = java.lang.Float.NaN
|
val NaN: Float = java.lang.Float.NaN
|
||||||
}
|
}
|
||||||
|
|
||||||
internal object IntCompanionObject {
|
internal object IntCompanionObject {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@file:JvmName("ThreadsKt")
|
@file:JvmName("ThreadsKt")
|
||||||
|
|
||||||
package kotlin.concurrent
|
package kotlin.concurrent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +17,14 @@ package kotlin.concurrent
|
|||||||
* @param name the name of the thread.
|
* @param name the name of the thread.
|
||||||
* @param priority the priority 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() {
|
val thread = object : Thread() {
|
||||||
public override fun run() {
|
public override fun run() {
|
||||||
block()
|
block()
|
||||||
@@ -47,6 +55,6 @@ public fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClass
|
|||||||
* is stored for the current thread and then returned.
|
* is stored for the current thread and then returned.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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)
|
return get() ?: default().also(this::set)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ internal actual constructor(
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private val RESULT = AtomicReferenceFieldUpdater.newUpdater<SafeContinuation<*>, Any?>(
|
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)
|
private class Fail(val exception: Throwable)
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
@file:kotlin.jvm.JvmName("IntrinsicsKt")
|
@file:kotlin.jvm.JvmName("IntrinsicsKt")
|
||||||
@file:kotlin.jvm.JvmMultifileClass
|
@file:kotlin.jvm.JvmMultifileClass
|
||||||
|
|
||||||
package kotlin.coroutines.experimental.intrinsics
|
package kotlin.coroutines.experimental.intrinsics
|
||||||
|
|
||||||
import kotlin.coroutines.experimental.*
|
import kotlin.coroutines.experimental.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@file:JvmName("CoroutineIntrinsics")
|
@file:JvmName("CoroutineIntrinsics")
|
||||||
|
|
||||||
package kotlin.coroutines.experimental.jvm.internal
|
package kotlin.coroutines.experimental.jvm.internal
|
||||||
|
|
||||||
import kotlin.coroutines.experimental.Continuation
|
import kotlin.coroutines.experimental.Continuation
|
||||||
|
|||||||
@@ -26,23 +26,19 @@ internal val IMPLEMENTATIONS: PlatformImplementations = run {
|
|||||||
if (version >= 0x10008) {
|
if (version >= 0x10008) {
|
||||||
try {
|
try {
|
||||||
return@run Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance() as PlatformImplementations
|
return@run Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance() as PlatformImplementations
|
||||||
}
|
} catch (e: ClassNotFoundException) { }
|
||||||
catch (e: ClassNotFoundException) { }
|
|
||||||
try {
|
try {
|
||||||
return@run Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance() as PlatformImplementations
|
return@run Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance() as PlatformImplementations
|
||||||
}
|
} catch (e: ClassNotFoundException) { }
|
||||||
catch (e: ClassNotFoundException) { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version >= 0x10007) {
|
if (version >= 0x10007) {
|
||||||
try {
|
try {
|
||||||
return@run Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance() as PlatformImplementations
|
return@run Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance() as PlatformImplementations
|
||||||
}
|
} catch (e: ClassNotFoundException) { }
|
||||||
catch (e: ClassNotFoundException) { }
|
|
||||||
try {
|
try {
|
||||||
return@run Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance() as PlatformImplementations
|
return@run Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance() as PlatformImplementations
|
||||||
}
|
} catch (e: ClassNotFoundException) { }
|
||||||
catch (e: ClassNotFoundException) { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformImplementations()
|
PlatformImplementations()
|
||||||
|
|||||||
@@ -4,11 +4,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@file:JvmName("ConstantsKt")
|
@file:JvmName("ConstantsKt")
|
||||||
|
|
||||||
package kotlin.io
|
package kotlin.io
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default buffer size when working with buffered streams.
|
* Returns the default buffer size when working with buffered streams.
|
||||||
*/
|
*/
|
||||||
public const val DEFAULT_BUFFER_SIZE: Int = 8 * 1024
|
public const val DEFAULT_BUFFER_SIZE: Int = 8 * 1024
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ 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 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
|
* @property reason the description of the error
|
||||||
*/
|
*/
|
||||||
open public class FileSystemException(public val file: File,
|
open public class FileSystemException(
|
||||||
|
public val file: File,
|
||||||
public val other: File? = null,
|
public val other: File? = null,
|
||||||
public val reason: String? = null
|
public val reason: String? = null
|
||||||
) : IOException(constructMessage(file, other, reason))
|
) : IOException(constructMessage(file, other, reason))
|
||||||
@@ -34,21 +35,27 @@ open public class FileSystemException(public val file: File,
|
|||||||
/**
|
/**
|
||||||
* An exception class which is used when some file to create or copy to already exists.
|
* An exception class which is used when some file to create or copy to already exists.
|
||||||
*/
|
*/
|
||||||
public class FileAlreadyExistsException(file: File,
|
public class FileAlreadyExistsException(
|
||||||
|
file: File,
|
||||||
other: File? = null,
|
other: File? = null,
|
||||||
reason: String? = null) : FileSystemException(file, other, reason)
|
reason: String? = null
|
||||||
|
) : FileSystemException(file, other, reason)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An exception class which is used when we have not enough access for some operation.
|
* An exception class which is used when we have not enough access for some operation.
|
||||||
*/
|
*/
|
||||||
public class AccessDeniedException(file: File,
|
public class AccessDeniedException(
|
||||||
|
file: File,
|
||||||
other: File? = null,
|
other: File? = null,
|
||||||
reason: String? = null) : FileSystemException(file, other, reason)
|
reason: String? = null
|
||||||
|
) : FileSystemException(file, other, reason)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An exception class which is used when file to copy does not exist.
|
* An exception class which is used when file to copy does not exist.
|
||||||
*/
|
*/
|
||||||
public class NoSuchFileException(file: File,
|
public class NoSuchFileException(
|
||||||
|
file: File,
|
||||||
other: File? = null,
|
other: File? = null,
|
||||||
reason: String? = null) : FileSystemException(file, other, reason)
|
reason: String? = null
|
||||||
|
) : FileSystemException(file, other, reason)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
@file:JvmMultifileClass
|
@file:JvmMultifileClass
|
||||||
@file:JvmName("FilesKt")
|
@file:JvmName("FilesKt")
|
||||||
|
|
||||||
package kotlin.io
|
package kotlin.io
|
||||||
|
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@@ -17,7 +18,8 @@ import kotlin.internal.*
|
|||||||
* Returns a new [FileReader] for reading the content of this file.
|
* Returns a new [FileReader] for reading the content of this file.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* 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.
|
* @param bufferSize necessary size of the buffer.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Returns a new [FileWriter] for writing the content of this file.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* 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.
|
* @param bufferSize necessary size of the buffer.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Returns a new [PrintWriter] for writing the content of this file.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Gets the entire content of this file as a byte array.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@file:JvmName("ByteStreamsKt")
|
@file:JvmName("ByteStreamsKt")
|
||||||
|
|
||||||
package kotlin.io
|
package kotlin.io
|
||||||
|
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@@ -60,15 +61,15 @@ public inline fun ByteArray.inputStream(): ByteArrayInputStream = ByteArrayInput
|
|||||||
* @param length the length of the portion of the array to read.
|
* @param length the length of the portion of the array to read.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Creates a buffered input stream wrapping this stream.
|
||||||
* @param bufferSize the buffer size to use.
|
* @param bufferSize the buffer size to use.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun InputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedInputStream
|
public inline fun InputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedInputStream =
|
||||||
= if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize)
|
if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize)
|
||||||
|
|
||||||
/** Creates a reader on this input stream using UTF-8 or the specified [charset]. */
|
/** Creates a reader on this input stream using UTF-8 or the specified [charset]. */
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
@@ -83,8 +84,8 @@ public inline fun InputStream.bufferedReader(charset: Charset = Charsets.UTF_8):
|
|||||||
* @param bufferSize the buffer size to use.
|
* @param bufferSize the buffer size to use.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun OutputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedOutputStream
|
public inline fun OutputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedOutputStream =
|
||||||
= if (this is BufferedOutputStream) this else BufferedOutputStream(this, bufferSize)
|
if (this is BufferedOutputStream) this else BufferedOutputStream(this, bufferSize)
|
||||||
|
|
||||||
/** Creates a writer on this output stream using UTF-8 or the specified [charset]. */
|
/** Creates a writer on this output stream using UTF-8 or the specified [charset]. */
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@file:JvmName("TextStreamsKt")
|
@file:JvmName("TextStreamsKt")
|
||||||
|
|
||||||
package kotlin.io
|
package kotlin.io
|
||||||
|
|
||||||
import java.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. */
|
/** Returns a buffered reader wrapping this Reader, or this Reader itself if it is already buffered. */
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun Reader.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader
|
public inline fun Reader.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader =
|
||||||
= if (this is BufferedReader) this else BufferedReader(this, bufferSize)
|
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. */
|
/** Returns a buffered reader wrapping this Writer, or this Writer itself if it is already buffered. */
|
||||||
@kotlin.internal.InlineOnly
|
@kotlin.internal.InlineOnly
|
||||||
public inline fun Writer.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter
|
public inline fun Writer.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter =
|
||||||
= if (this is BufferedWriter) this else BufferedWriter(this, bufferSize)
|
if (this is BufferedWriter) this else BufferedWriter(this, bufferSize)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterates through each line of this reader, calls [action] for each line read
|
* Iterates through each line of this reader, calls [action] for each line read
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
@file:JvmMultifileClass
|
@file:JvmMultifileClass
|
||||||
@file:JvmName("FilesKt")
|
@file:JvmName("FilesKt")
|
||||||
|
|
||||||
package kotlin.io
|
package kotlin.io
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -141,7 +142,7 @@ internal fun File.toComponents(): FilePathComponents {
|
|||||||
* Number 0 belongs to a component closest to the root,
|
* Number 0 belongs to a component closest to the root,
|
||||||
* number count-1 belongs to a component farthest from the root.
|
* number count-1 belongs to a component farthest from the root.
|
||||||
* @throws IllegalArgumentException if [beginIndex] is negative,
|
* @throws IllegalArgumentException if [beginIndex] is negative,
|
||||||
* or [endIndex] is greater than existing number of components,
|
* or [endIndex] is greater than existing number of components,
|
||||||
* or [beginIndex] is greater than [endIndex].
|
* or [beginIndex] is greater than [endIndex].
|
||||||
*/
|
*/
|
||||||
internal fun File.subPath(beginIndex: Int, endIndex: Int): File = toComponents().subPath(beginIndex, endIndex)
|
internal fun File.subPath(beginIndex: Int, endIndex: Int): File = toComponents().subPath(beginIndex, endIndex)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
@file:JvmMultifileClass
|
@file:JvmMultifileClass
|
||||||
@file:JvmName("FilesKt")
|
@file:JvmName("FilesKt")
|
||||||
|
|
||||||
package kotlin.io
|
package kotlin.io
|
||||||
|
|
||||||
import kotlin.*
|
import kotlin.*
|
||||||
@@ -43,7 +44,7 @@ public class FileTreeWalk private constructor(
|
|||||||
private val maxDepth: Int = Int.MAX_VALUE
|
private val maxDepth: Int = Int.MAX_VALUE
|
||||||
) : Sequence<File> {
|
) : 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. */
|
/** 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] */
|
/** 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 {
|
init {
|
||||||
if (_Assertions.ENABLED)
|
if (_Assertions.ENABLED)
|
||||||
assert(rootDir.isDirectory) { "rootDir must be verified to be directory beforehand." }
|
assert(rootDir.isDirectory) { "rootDir must be verified to be directory beforehand." }
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
@file:JvmMultifileClass
|
@file:JvmMultifileClass
|
||||||
@file:JvmName("FilesKt")
|
@file:JvmName("FilesKt")
|
||||||
|
|
||||||
package kotlin.io
|
package kotlin.io
|
||||||
|
|
||||||
import java.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.
|
* If [directory] is not specified then the default temporary-file directory will be used.
|
||||||
*
|
*
|
||||||
* @return a file object corresponding to a newly-created directory.
|
* @return a file object corresponding to a newly-created directory.
|
||||||
*
|
*
|
||||||
* @throws IOException in case of input/output error.
|
* @throws IOException in case of input/output error.
|
||||||
* @throws IllegalArgumentException if [prefix] is shorter than three symbols.
|
* @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.
|
* If [directory] is not specified then the default temporary-file directory will be used.
|
||||||
*
|
*
|
||||||
* @return a file object corresponding to a newly-created file.
|
* @return a file object corresponding to a newly-created file.
|
||||||
*
|
*
|
||||||
* @throws IOException in case of input/output error.
|
* @throws IOException in case of input/output error.
|
||||||
* @throws IllegalArgumentException if [prefix] is shorter than three symbols.
|
* @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.
|
* @throws IllegalArgumentException if this and base paths have different roots.
|
||||||
*/
|
*/
|
||||||
public fun File.toRelativeString(base: File): String
|
public fun File.toRelativeString(base: File): String =
|
||||||
= toRelativeStringOrNull(base) ?: throw IllegalArgumentException("this and base files have different roots: $this and $base.")
|
toRelativeStringOrNull(base) ?: throw IllegalArgumentException("this and base files have different roots: $this and $base.")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the relative path for this file from [base] file.
|
* 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.
|
* @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
|
public fun File.relativeToOrSelf(base: File): File =
|
||||||
= toRelativeStringOrNull(base)?.let(::File) ?: this
|
toRelativeStringOrNull(base)?.let(::File) ?: this
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the relative path for this file from [base] file.
|
* 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.
|
* @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?
|
public fun File.relativeToOrNull(base: File): File? =
|
||||||
= toRelativeStringOrNull(base)?.let(::File)
|
toRelativeStringOrNull(base)?.let(::File)
|
||||||
|
|
||||||
|
|
||||||
private fun File.toRelativeStringOrNull(base: File): String? {
|
private fun File.toRelativeStringOrNull(base: File): String? {
|
||||||
@@ -125,7 +126,7 @@ private fun File.toRelativeStringOrNull(base: File): String? {
|
|||||||
val baseCount = baseComponents.size
|
val baseCount = baseComponents.size
|
||||||
val thisCount = thisComponents.size
|
val thisCount = thisComponents.size
|
||||||
|
|
||||||
val sameCount = run countSame@ {
|
val sameCount = run countSame@{
|
||||||
var i = 0
|
var i = 0
|
||||||
val maxSameCount = minOf(thisCount, baseCount)
|
val maxSameCount = minOf(thisCount, baseCount)
|
||||||
while (i < maxSameCount && thisComponents.segments[i] == baseComponents.segments[i])
|
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()
|
val stillExists = if (!overwrite) true else !target.delete()
|
||||||
|
|
||||||
if (stillExists) {
|
if (stillExists) {
|
||||||
throw FileAlreadyExistsException(file = this,
|
throw FileAlreadyExistsException(
|
||||||
|
file = this,
|
||||||
other = target,
|
other = target,
|
||||||
reason = "The destination file already exists.")
|
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.
|
* @param overwrite `true` if it is allowed to overwrite existing destination files and directories.
|
||||||
* @return `false` if the copying was terminated, `true` otherwise.
|
* @return `false` if the copying was terminated, `true` otherwise.
|
||||||
*/
|
*/
|
||||||
public fun File.copyRecursively(target: File,
|
public fun File.copyRecursively(
|
||||||
|
target: File,
|
||||||
overwrite: Boolean = false,
|
overwrite: Boolean = false,
|
||||||
onError: (File, IOException) -> OnErrorAction =
|
onError: (File, IOException) -> OnErrorAction = { _, exception -> throw exception }
|
||||||
{ _, exception -> throw exception }
|
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (!exists()) {
|
if (!exists()) {
|
||||||
return onError(this, NoSuchFileException(file = this, reason = "The source file doesn't exist.")) !=
|
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.
|
* @return normalized pathname with . and possibly .. removed.
|
||||||
*/
|
*/
|
||||||
public fun File.normalize(): File
|
public fun File.normalize(): File =
|
||||||
= with (toComponents()) { root.resolve(segments.normalize().joinToString(File.separator)) }
|
with(toComponents()) { root.resolve(segments.normalize().joinToString(File.separator)) }
|
||||||
|
|
||||||
private fun FilePathComponents.normalize(): FilePathComponents
|
private fun FilePathComponents.normalize(): FilePathComponents =
|
||||||
= FilePathComponents(root, segments.normalize())
|
FilePathComponents(root, segments.normalize())
|
||||||
|
|
||||||
private fun List<File>.normalize(): List<File> {
|
private fun List<File>.normalize(): List<File> {
|
||||||
val list: MutableList<File> = ArrayList(this.size)
|
val list: MutableList<File> = ArrayList(this.size)
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ package kotlin.jvm.internal.unsafe
|
|||||||
|
|
||||||
import kotlin.*
|
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.JvmMultifileClass
|
||||||
@file:kotlin.jvm.JvmName("RangesKt")
|
@file:kotlin.jvm.JvmName("RangesKt")
|
||||||
|
|
||||||
package kotlin.ranges
|
package kotlin.ranges
|
||||||
|
|
||||||
import kotlin.*
|
import kotlin.*
|
||||||
@@ -14,10 +15,10 @@ import kotlin.*
|
|||||||
*
|
*
|
||||||
* Numbers are compared with the ends of this range according to IEEE-754.
|
* Numbers are compared with the ends of this range according to IEEE-754.
|
||||||
*/
|
*/
|
||||||
private class ClosedFloatRange (
|
private class ClosedFloatRange(
|
||||||
start: Float,
|
start: Float,
|
||||||
endInclusive: Float
|
endInclusive: Float
|
||||||
): ClosedFloatingPointRange<Float> {
|
) : ClosedFloatingPointRange<Float> {
|
||||||
private val _start = start
|
private val _start = start
|
||||||
private val _endInclusive = endInclusive
|
private val _endInclusive = endInclusive
|
||||||
override val start: Float get() = _start
|
override val start: Float get() = _start
|
||||||
@@ -36,6 +37,7 @@ private class ClosedFloatRange (
|
|||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return if (isEmpty()) -1 else 31 * _start.hashCode() + _endInclusive.hashCode()
|
return if (isEmpty()) -1 else 31 * _start.hashCode() + _endInclusive.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String = "$_start..$_endInclusive"
|
override fun toString(): String = "$_start..$_endInclusive"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ package kotlin.system
|
|||||||
/**
|
/**
|
||||||
* Executes the given block and returns elapsed time in milliseconds.
|
* 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()
|
val start = System.currentTimeMillis()
|
||||||
block()
|
block()
|
||||||
return System.currentTimeMillis() - start
|
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.
|
* 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()
|
val start = System.nanoTime()
|
||||||
block()
|
block()
|
||||||
return System.nanoTime() - start
|
return System.nanoTime() - start
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ internal actual fun digitOf(char: Char, radix: Int): Int = Character.digit(char.
|
|||||||
*/
|
*/
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal actual fun checkRadix(radix: Int): Int {
|
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}")
|
throw IllegalArgumentException("radix $radix was not in valid range ${Character.MIN_RADIX..Character.MAX_RADIX}")
|
||||||
}
|
}
|
||||||
return radix
|
return radix
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ private inline fun <T> screenFloatValue(str: String, parse: (String) -> T): T? {
|
|||||||
parse(str)
|
parse(str)
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
} catch(e: NumberFormatException) { // overflow
|
} catch (e: NumberFormatException) { // overflow
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
* @param endIndex the end offset (exclusive) of the substring to copy.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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)
|
(this as java.lang.String).getChars(startIndex, endIndex, destination, destinationOffset)
|
||||||
return destination
|
return destination
|
||||||
}
|
}
|
||||||
@@ -143,14 +148,15 @@ public inline fun String.Companion.format(format: String, vararg args: Any?): St
|
|||||||
* using the specified locale.
|
* using the specified locale.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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,
|
* Uses the provided [format] as a format string and returns a string obtained by substituting the specified arguments,
|
||||||
* using the specified locale.
|
* using the specified locale.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* 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.
|
* @param limit Non-negative value specifying the maximum number of substrings to return.
|
||||||
* Zero by default means no limit is set.
|
* Zero by default means no limit is set.
|
||||||
*/
|
*/
|
||||||
public fun CharSequence.split(regex: Pattern, limit: Int = 0): List<String>
|
public fun CharSequence.split(regex: Pattern, 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 regex.split(this, if (limit == 0) -1 else limit).asList()
|
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.
|
* @param charset the character set to use.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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
|
* 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.
|
* @param length the number of bytes to be converted.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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
|
* 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.
|
* and returns the conversion result as a string.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Converts the characters in the specified array to a string.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Converts the characters from a portion of the specified array to a string.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Converts the code points from a portion of the specified Unicode code point array to a string.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Converts the contents of the specified StringBuffer to a string.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Converts the contents of the specified StringBuilder to a string.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* 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.
|
* Returns the number of Unicode code points in the specified text range of this String.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* 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.
|
* Returns the index within this string that is offset from the given [index] by [codePointOffset] code points.
|
||||||
*/
|
*/
|
||||||
@kotlin.internal.InlineOnly
|
@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.
|
* Returns `true` if the specified range in this char sequence is equal to the specified range in another char sequence.
|
||||||
@@ -418,7 +433,7 @@ public actual fun String.decapitalize(): String {
|
|||||||
* @sample samples.text.Strings.repeat
|
* @sample samples.text.Strings.repeat
|
||||||
*/
|
*/
|
||||||
public actual fun CharSequence.repeat(n: Int): String {
|
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) {
|
return when (n) {
|
||||||
0 -> ""
|
0 -> ""
|
||||||
|
|||||||
@@ -14,9 +14,11 @@ private interface FlagEnum {
|
|||||||
public val value: Int
|
public val value: Int
|
||||||
public val mask: Int
|
public val mask: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Iterable<FlagEnum>.toInt(): Int =
|
private fun Iterable<FlagEnum>.toInt(): Int =
|
||||||
this.fold(0, { value, option -> value or option.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> =
|
|
||||||
|
private inline fun <reified T> fromInt(value: Int): Set<T> where T : FlagEnum, T : Enum<T> =
|
||||||
Collections.unmodifiableSet(EnumSet.allOf(T::class.java).apply {
|
Collections.unmodifiableSet(EnumSet.allOf(T::class.java).apply {
|
||||||
retainAll { value and it.mask == it.value }
|
retainAll { value and it.mask == it.value }
|
||||||
})
|
})
|
||||||
@@ -87,13 +89,13 @@ internal constructor(private val nativePattern: Pattern) : Serializable {
|
|||||||
|
|
||||||
|
|
||||||
/** Creates a regular expression from the specified [pattern] string and the default options. */
|
/** 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]. */
|
/** 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]. */
|
/** 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. */
|
/** 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.
|
* @return An instance of [MatchResult] if match was found or `null` otherwise.
|
||||||
*/
|
*/
|
||||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
@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].
|
* 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")
|
@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.
|
* 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.
|
* @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")
|
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||||
public actual fun split(input: CharSequence, limit: Int = 0): List<String> {
|
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()
|
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 {
|
actual companion object {
|
||||||
/** Returns a literal regex for the specified [literal] string. */
|
/** Returns a literal regex for the specified [literal] string. */
|
||||||
public actual fun fromLiteral(literal: String): Regex = literal.toRegex(RegexOption.LITERAL)
|
public actual fun fromLiteral(literal: String): Regex = literal.toRegex(RegexOption.LITERAL)
|
||||||
|
|
||||||
/** Returns a literal pattern for the specified [literal] string. */
|
/** Returns a literal pattern for the specified [literal] string. */
|
||||||
public actual fun escape(literal: String): String = Pattern.quote(literal)
|
public actual fun escape(literal: String): String = Pattern.quote(literal)
|
||||||
|
|
||||||
/** Returns a literal replacement expression for the specified [literal] string. */
|
/** Returns a literal replacement expression for the specified [literal] string. */
|
||||||
public actual fun escapeReplacement(literal: String): String = Matcher.quoteReplacement(literal)
|
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
|
else
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(name: String): MatchGroup? {
|
override fun get(name: String): MatchGroup? {
|
||||||
return IMPLEMENTATIONS.getMatchResultNamedGroup(matchResult, name)
|
return IMPLEMENTATIONS.getMatchResultNamedGroup(matchResult, name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ package kotlin
|
|||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal object _Assertions {
|
internal object _Assertions {
|
||||||
@JvmField @PublishedApi
|
@JvmField
|
||||||
|
@PublishedApi
|
||||||
internal val ENABLED: Boolean = javaClass.desiredAssertionStatus()
|
internal val ENABLED: Boolean = javaClass.desiredAssertionStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ private class SynchronizedLazyImpl<out T>(initializer: () -> T, lock: Any? = nul
|
|||||||
val _v2 = _value
|
val _v2 = _value
|
||||||
if (_v2 !== UNINITIALIZED_VALUE) {
|
if (_v2 !== UNINITIALIZED_VALUE) {
|
||||||
@Suppress("UNCHECKED_CAST") (_v2 as T)
|
@Suppress("UNCHECKED_CAST") (_v2 as T)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
val typedValue = initializer!!()
|
val typedValue = initializer!!()
|
||||||
_value = typedValue
|
_value = typedValue
|
||||||
initializer = null
|
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(
|
private val valueUpdater = java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(
|
||||||
SafePublicationLazyImpl::class.java,
|
SafePublicationLazyImpl::class.java,
|
||||||
Any::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")
|
@SinceKotlin("1.2")
|
||||||
@InlineOnly
|
@InlineOnly
|
||||||
public actual inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b)
|
public actual inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the greater of two values.
|
* Returns the greater of two values.
|
||||||
*
|
*
|
||||||
@@ -524,6 +525,7 @@ public actual inline val Double.sign: Double get() = nativeMath.signum(this)
|
|||||||
@SinceKotlin("1.2")
|
@SinceKotlin("1.2")
|
||||||
@InlineOnly
|
@InlineOnly
|
||||||
public actual inline fun Double.withSign(sign: Double): Double = nativeMath.copySign(this, sign)
|
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.
|
* 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")
|
@SinceKotlin("1.2")
|
||||||
@InlineOnly
|
@InlineOnly
|
||||||
public actual inline fun Double.nextUp(): Double = nativeMath.nextUp(this)
|
public actual inline fun Double.nextUp(): Double = nativeMath.nextUp(this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the [Double] value nearest to this value in direction of negative infinity.
|
* 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`
|
* @throws IllegalArgumentException when this value is `NaN`
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.2")
|
@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 ========================================
|
// ================ Float Math ========================================
|
||||||
@@ -963,6 +966,7 @@ public actual inline fun sign(x: Float): Float = nativeMath.signum(x)
|
|||||||
@SinceKotlin("1.2")
|
@SinceKotlin("1.2")
|
||||||
@InlineOnly
|
@InlineOnly
|
||||||
public actual inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b)
|
public actual inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the greater of two values.
|
* Returns the greater of two values.
|
||||||
*
|
*
|
||||||
@@ -1048,6 +1052,7 @@ public actual inline val Float.sign: Float get() = nativeMath.signum(this)
|
|||||||
@SinceKotlin("1.2")
|
@SinceKotlin("1.2")
|
||||||
@InlineOnly
|
@InlineOnly
|
||||||
public actual inline fun Float.withSign(sign: Float): Float = nativeMath.copySign(this, sign)
|
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.
|
* 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")
|
@SinceKotlin("1.2")
|
||||||
@InlineOnly
|
@InlineOnly
|
||||||
public inline fun Float.nextUp(): Float = nativeMath.nextUp(this)
|
public inline fun Float.nextUp(): Float = nativeMath.nextUp(this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the [Float] value nearest to this value in direction of negative infinity.
|
* 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`
|
* @throws IllegalArgumentException when this value is `NaN`
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.2")
|
@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].
|
* Rounds this [Float] value to the nearest integer and converts the result to [Long].
|
||||||
|
|||||||
Reference in New Issue
Block a user