stdlib-js: add actual modifiers where required

This commit is contained in:
Ilya Gorbunov
2018-01-24 21:25:37 +03:00
parent 1be55db681
commit ee9608f8db
29 changed files with 383 additions and 368 deletions
+3 -3
View File
@@ -17,10 +17,10 @@
package kotlin
public interface Comparator<T> {
@JsName("compare") fun compare(a: T, b: T): Int
public actual interface Comparator<T> {
@JsName("compare") actual fun compare(a: T, b: T): Int
}
public inline fun <T> Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator<T> = object : Comparator<T> {
public actual inline fun <T> Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator<T> = object : Comparator<T> {
override fun compare(a: T, b: T): Int = comparison(a, b)
}
@@ -25,22 +25,25 @@ internal annotation class JvmOverloads
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FILE)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
internal annotation class JvmName(public val name: String)
@Suppress("ACTUAL_WITHOUT_EXPECT") // TODO: KT-19507
internal actual annotation class JvmName(public actual val name: String)
@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
internal annotation class JvmMultifileClass
@Suppress("ACTUAL_WITHOUT_EXPECT") // TODO: KT-19507
internal actual annotation class JvmMultifileClass
@Target(AnnotationTarget.FIELD)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
internal annotation class JvmField
@Suppress("ACTUAL_WITHOUT_EXPECT") // TODO: KT-19507
internal actual annotation class JvmField
@Target(AnnotationTarget.FIELD)
@Retention(AnnotationRetention.SOURCE)
public annotation class Volatile
public actual annotation class Volatile
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@Retention(AnnotationRetention.SOURCE)
+5 -5
View File
@@ -17,20 +17,20 @@
package kotlin.text
// actually \s is enough to match all whitespace, but \xA0 added because of different regexp behavior of Rhino used in Selenium tests
public fun Char.isWhitespace(): Boolean = toString().matches("[\\s\\xA0]")
public actual fun Char.isWhitespace(): Boolean = toString().matches("[\\s\\xA0]")
@kotlin.internal.InlineOnly
public inline fun Char.toLowerCase(): Char = js("String.fromCharCode")(this).toLowerCase().charCodeAt(0)
public actual inline fun Char.toLowerCase(): Char = js("String.fromCharCode")(this).toLowerCase().charCodeAt(0)
@kotlin.internal.InlineOnly
public inline fun Char.toUpperCase(): Char = js("String.fromCharCode")(this).toUpperCase().charCodeAt(0)
public actual inline fun Char.toUpperCase(): Char = js("String.fromCharCode")(this).toUpperCase().charCodeAt(0)
/**
* Returns `true` if this character is a Unicode high-surrogate code unit (also known as leading-surrogate code unit).
*/
public fun Char.isHighSurrogate(): Boolean = this in Char.MIN_HIGH_SURROGATE..Char.MAX_HIGH_SURROGATE
public actual fun Char.isHighSurrogate(): Boolean = this in Char.MIN_HIGH_SURROGATE..Char.MAX_HIGH_SURROGATE
/**
* Returns `true` if this character is a Unicode low-surrogate code unit (also known as trailing-surrogate code unit).
*/
public fun Char.isLowSurrogate(): Boolean = this in Char.MIN_LOW_SURROGATE..Char.MAX_LOW_SURROGATE
public actual fun Char.isLowSurrogate(): Boolean = this in Char.MIN_LOW_SURROGATE..Char.MAX_LOW_SURROGATE
+17 -13
View File
@@ -21,10 +21,10 @@ import kotlin.math.floor
/** Returns the array if it's not `null`, or an empty array otherwise. */
@kotlin.internal.InlineOnly
public inline fun <T> Array<out T>?.orEmpty(): Array<out T> = this ?: emptyArray<T>()
public actual inline fun <T> Array<out T>?.orEmpty(): Array<out T> = this ?: emptyArray<T>()
@kotlin.internal.InlineOnly
public inline fun <T> Collection<T>.toTypedArray(): Array<T> = copyToArray(this)
public actual inline fun <T> Collection<T>.toTypedArray(): Array<T> = copyToArray(this)
@JsName("copyToArray")
@PublishedApi
@@ -36,7 +36,7 @@ internal fun <T> copyToArray(collection: Collection<T>): Array<T> {
}
@JsName("copyToArrayImpl")
internal fun copyToArrayImpl(collection: Collection<*>): Array<Any?> {
internal actual fun copyToArrayImpl(collection: Collection<*>): Array<Any?> {
val array = emptyArray<Any?>()
val iterator = collection.iterator()
while (iterator.hasNext())
@@ -45,7 +45,7 @@ internal fun copyToArrayImpl(collection: Collection<*>): Array<Any?> {
}
@JsName("copyToExistingArrayImpl")
internal fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<T>): Array<T> {
internal actual fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<T>): Array<T> {
if (array.size < collection.size)
return copyToArrayImpl(collection).unsafeCast<Array<T>>()
@@ -86,7 +86,7 @@ public fun <K, V> mapOf(pair: Pair<K, V>): Map<K, V> = hashMapOf(pair)
* Each element in the list gets replaced with the [value].
*/
@SinceKotlin("1.2")
public fun <T> MutableList<T>.fill(value: T): Unit {
public actual fun <T> MutableList<T>.fill(value: T): Unit {
for (index in 0..lastIndex) {
this[index] = value
}
@@ -98,7 +98,7 @@ public fun <T> MutableList<T>.fill(value: T): Unit {
* See: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
*/
@SinceKotlin("1.2")
public fun <T> MutableList<T>.shuffle(): Unit {
public actual fun <T> MutableList<T>.shuffle(): Unit {
for (i in lastIndex downTo 1) {
val j = rand(i + 1)
val copy = this[i]
@@ -112,19 +112,19 @@ private fun rand(upperBound: Int) = floor(kotlin.js.Math.random() * upperBound).
* Returns a new list with the elements of this list randomly shuffled.
*/
@SinceKotlin("1.2")
public fun <T> Iterable<T>.shuffled(): List<T> = toMutableList().apply { shuffle() }
public actual fun <T> Iterable<T>.shuffled(): List<T> = toMutableList().apply { shuffle() }
/**
* Sorts elements in the list in-place according to their natural sort order.
*/
public fun <T : Comparable<T>> MutableList<T>.sort(): Unit {
public actual fun <T : Comparable<T>> MutableList<T>.sort(): Unit {
collectionsSort(this, naturalOrder())
}
/**
* Sorts elements in the list in-place according to the order specified with [comparator].
*/
public fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit {
public actual fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit {
collectionsSort(this, comparator)
}
@@ -140,16 +140,20 @@ private fun <T> collectionsSort(list: MutableList<T>, comparator: Comparator<in
}
}
internal fun <T> arrayOfNulls(reference: Array<out T>, size: Int): Array<T> {
internal actual fun <T> arrayOfNulls(reference: Array<T>, size: Int): Array<T> {
return arrayOfNulls<Any>(size).unsafeCast<Array<T>>()
}
// no singleton map implementation in js, return map as is
internal inline fun <K, V> Map<K, V>.toSingletonMapOrSelf(): Map<K, V> = this
@Suppress("NOTHING_TO_INLINE")
internal actual inline fun <K, V> Map<K, V>.toSingletonMapOrSelf(): Map<K, V> = this
internal inline fun <K, V> Map<out K, V>.toSingletonMap(): Map<K, V> = this.toMutableMap()
@Suppress("NOTHING_TO_INLINE")
internal actual inline fun <K, V> Map<out K, V>.toSingletonMap(): Map<K, V> = this.toMutableMap()
internal inline fun <T> Array<out T>.copyToArrayOfAny(isVarargs: Boolean): Array<out Any?> =
@Suppress("NOTHING_TO_INLINE")
internal actual inline fun <T> Array<out T>.copyToArrayOfAny(isVarargs: Boolean): Array<out Any?> =
if (isVarargs)
// no need to copy vararg array in JS
this
@@ -26,19 +26,19 @@ package kotlin.collections
*
* @param E the type of elements contained in the list. The list is invariant on its element type.
*/
public abstract class AbstractMutableList<E> protected constructor() : AbstractMutableCollection<E>(), MutableList<E> {
public actual abstract class AbstractMutableList<E> protected actual constructor() : AbstractMutableCollection<E>(), MutableList<E> {
protected var modCount: Int = 0
abstract override fun add(index: Int, element: E): Unit
abstract override fun removeAt(index: Int): E
abstract override fun set(index: Int, element: E): E
override fun add(element: E): Boolean {
actual override fun add(element: E): Boolean {
add(size, element)
return true
}
override fun addAll(index: Int, elements: Collection<E>): Boolean {
actual override fun addAll(index: Int, elements: Collection<E>): Boolean {
var _index = index
var changed = false
for (e in elements) {
@@ -48,19 +48,19 @@ public abstract class AbstractMutableList<E> protected constructor() : AbstractM
return changed
}
override fun clear() {
actual override fun clear() {
removeRange(0, size)
}
override fun removeAll(elements: Collection<E>): Boolean = removeAll { it in elements }
override fun retainAll(elements: Collection<E>): Boolean = removeAll { it !in elements }
actual override fun removeAll(elements: Collection<E>): Boolean = removeAll { it in elements }
actual override fun retainAll(elements: Collection<E>): Boolean = removeAll { it !in elements }
override fun iterator(): MutableIterator<E> = IteratorImpl()
actual override fun iterator(): MutableIterator<E> = IteratorImpl()
override fun contains(element: E): Boolean = indexOf(element) >= 0
actual override fun contains(element: E): Boolean = indexOf(element) >= 0
override fun indexOf(element: E): Int {
actual override fun indexOf(element: E): Int {
for (index in 0..lastIndex) {
if (get(index) == element) {
return index
@@ -69,7 +69,7 @@ public abstract class AbstractMutableList<E> protected constructor() : AbstractM
return -1
}
override fun lastIndexOf(element: E): Int {
actual override fun lastIndexOf(element: E): Int {
for (index in lastIndex downTo 0) {
if (get(index) == element) {
return index
@@ -78,11 +78,11 @@ public abstract class AbstractMutableList<E> protected constructor() : AbstractM
return -1
}
override fun listIterator(): MutableListIterator<E> = listIterator(0)
override fun listIterator(index: Int): MutableListIterator<E> = ListIteratorImpl(index)
actual override fun listIterator(): MutableListIterator<E> = listIterator(0)
actual override fun listIterator(index: Int): MutableListIterator<E> = ListIteratorImpl(index)
override fun subList(fromIndex: Int, toIndex: Int): MutableList<E> = SubList(this, fromIndex, toIndex)
actual override fun subList(fromIndex: Int, toIndex: Int): MutableList<E> = SubList(this, fromIndex, toIndex)
/**
* Removes the range of elements from this list starting from [fromIndex] and ending with but not including [toIndex].
@@ -28,7 +28,7 @@ package kotlin.collections
* @param K the type of map keys. The map is invariant on its key type.
* @param V the type of map values. The map is invariant on its value type.
*/
public abstract class AbstractMutableMap<K, V> protected constructor() : AbstractMap<K, V>(), MutableMap<K, V> {
public actual abstract class AbstractMutableMap<K, V> protected actual constructor() : AbstractMap<K, V>(), MutableMap<K, V> {
/**
* A mutable [Map.Entry] shared by several [Map] implementations.
@@ -90,7 +90,7 @@ public abstract class AbstractMutableMap<K, V> protected constructor() : Abstrac
return _keys!!
}
abstract override fun put(key: K, value: V): V?
actual abstract override fun put(key: K, value: V): V?
override fun putAll(from: Map<out K, V>) {
for ((key, value) in from) {
@@ -20,7 +20,7 @@ package kotlin.collections
*
* @param E the type of elements contained in the set. The set is invariant on its element type.
*/
public abstract class AbstractMutableSet<E> protected constructor() : AbstractMutableCollection<E>(), MutableSet<E> {
public actual abstract class AbstractMutableSet<E> protected actual constructor() : AbstractMutableCollection<E>(), MutableSet<E> {
/**
* Compares this set with another set instance with the unordered structural equality.
@@ -23,42 +23,47 @@ package kotlin.collections
* There is no speed advantage to pre-allocating array sizes in JavaScript, so this implementation does not include any of the
* capacity and "growth increment" concepts.
*/
public open class ArrayList<E> internal constructor(private var array: Array<Any?>) : AbstractMutableList<E>(), RandomAccess {
public actual open class ArrayList<E> internal constructor(private var array: Array<Any?>) : AbstractMutableList<E>(), MutableList<E>, RandomAccess {
/**
* Creates an empty [ArrayList].
* @param capacity initial capacity (ignored)
*/
public constructor(@Suppress("UNUSED_PARAMETER") capacity: Int = 0) : this(emptyArray()) {}
public actual constructor() : this(emptyArray()) {}
/**
* Creates an empty [ArrayList].
* @param initialCapacity initial capacity (ignored)
*/
public actual constructor(@Suppress("UNUSED_PARAMETER") initialCapacity: Int) : this(emptyArray()) {}
/**
* Creates an [ArrayList] filled from the [elements] collection.
*/
public constructor(elements: Collection<E>) : this(elements.toTypedArray<Any?>()) {}
public actual constructor(elements: Collection<E>) : this(elements.toTypedArray<Any?>()) {}
/** Does nothing in this ArrayList implementation. */
public fun trimToSize() {}
public actual fun trimToSize() {}
/** Does nothing in this ArrayList implementation. */
public fun ensureCapacity(@Suppress("UNUSED_PARAMETER") minCapacity: Int) {}
public actual fun ensureCapacity(@Suppress("UNUSED_PARAMETER") minCapacity: Int) {}
override val size: Int get() = array.size
override fun get(index: Int): E = array[rangeCheck(index)] as E
override fun set(index: Int, element: E): E {
actual override val size: Int get() = array.size
actual override fun get(index: Int): E = array[rangeCheck(index)] as E
actual override fun set(index: Int, element: E): E {
rangeCheck(index)
return array[index].apply { array[index] = element } as E
}
override fun add(element: E): Boolean {
actual override fun add(element: E): Boolean {
array.asDynamic().push(element)
modCount++
return true
}
override fun add(index: Int, element: E): Unit {
actual override fun add(index: Int, element: E): Unit {
array.asDynamic().splice(insertionRangeCheck(index), 0, element)
modCount++
}
override fun addAll(elements: Collection<E>): Boolean {
actual override fun addAll(elements: Collection<E>): Boolean {
if (elements.isEmpty()) return false
array += elements.toTypedArray<Any?>()
@@ -66,7 +71,7 @@ public open class ArrayList<E> internal constructor(private var array: Array<Any
return true
}
override fun addAll(index: Int, elements: Collection<E>): Boolean {
actual override fun addAll(index: Int, elements: Collection<E>): Boolean {
insertionRangeCheck(index)
if (index == size) return addAll(elements)
@@ -81,7 +86,7 @@ public open class ArrayList<E> internal constructor(private var array: Array<Any
return true
}
override fun removeAt(index: Int): E {
actual override fun removeAt(index: Int): E {
rangeCheck(index)
modCount++
return if (index == lastIndex)
@@ -90,7 +95,7 @@ public open class ArrayList<E> internal constructor(private var array: Array<Any
array.asDynamic().splice(index, 1)[0]
}
override fun remove(element: E): Boolean {
actual override fun remove(element: E): Boolean {
for (index in array.indices) {
if (array[index] == element) {
array.asDynamic().splice(index, 1)
@@ -106,15 +111,15 @@ public open class ArrayList<E> internal constructor(private var array: Array<Any
array.asDynamic().splice(fromIndex, toIndex - fromIndex)
}
override fun clear() {
actual override fun clear() {
array = emptyArray()
modCount++
}
override fun indexOf(element: E): Int = array.indexOf(element)
actual override fun indexOf(element: E): Int = array.indexOf(element)
override fun lastIndexOf(element: E): Int = array.lastIndexOf(element)
actual override fun lastIndexOf(element: E): Int = array.lastIndexOf(element)
override fun toString() = arrayToString(array)
override fun toArray(): Array<Any?> = js("[]").slice.call(array)
@@ -20,7 +20,6 @@
package kotlin.collections
import kotlin.collections.Map.Entry
import kotlin.collections.MutableMap.MutableEntry
/**
@@ -28,7 +27,7 @@ import kotlin.collections.MutableMap.MutableEntry
*
* This implementation makes no guarantees regarding the order of enumeration of [keys], [values] and [entries] collections.
*/
public open class HashMap<K, V> : AbstractMutableMap<K, V> {
public actual open class HashMap<K, V> : AbstractMutableMap<K, V>, MutableMap<K, V> {
private inner class EntrySet : AbstractMutableSet<MutableEntry<K, V>>() {
@@ -68,7 +67,7 @@ public open class HashMap<K, V> : AbstractMutableMap<K, V> {
/**
* Constructs an empty [HashMap] instance.
*/
constructor() : this(InternalHashCodeMap(EqualityComparator.HashCode))
actual constructor() : this(InternalHashCodeMap(EqualityComparator.HashCode))
/**
* Constructs an empty [HashMap] instance.
@@ -78,30 +77,33 @@ public open class HashMap<K, V> : AbstractMutableMap<K, V> {
*
* @throws IllegalArgumentException if the initial capacity or load factor are negative
*/
constructor(initialCapacity: Int, loadFactor: Float = 0f) : this() {
actual constructor(initialCapacity: Int, loadFactor: Float) : this() {
// This implementation of HashMap has no need of load factors or capacities.
require(initialCapacity >= 0) { "Negative initial capacity" }
require(loadFactor >= 0) { "Non-positive load factor" }
}
actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f)
/**
* Constructs an instance of [HashMap] filled with the contents of the specified [original] map.
*/
constructor(original: Map<out K, V>) : this() {
actual constructor(original: Map<out K, V>) : this() {
this.putAll(original)
}
override fun clear() {
actual override fun clear() {
internalMap.clear()
// structureChanged(this)
}
override fun containsKey(key: K): Boolean = internalMap.contains(key)
actual override fun containsKey(key: K): Boolean = internalMap.contains(key)
override fun containsValue(value: V): Boolean = internalMap.any { equality.equals(it.value, value) }
actual override fun containsValue(value: V): Boolean = internalMap.any { equality.equals(it.value, value) }
private var _entries: MutableSet<MutableMap.MutableEntry<K, V>>? = null
override val entries: MutableSet<MutableMap.MutableEntry<K, V>> get() {
actual override val entries: MutableSet<MutableMap.MutableEntry<K, V>> get() {
if (_entries == null) {
_entries = createEntrySet()
}
@@ -110,13 +112,13 @@ public open class HashMap<K, V> : AbstractMutableMap<K, V> {
protected open fun createEntrySet(): MutableSet<MutableMap.MutableEntry<K, V>> = EntrySet()
override operator fun get(key: K): V? = internalMap.get(key)
actual override operator fun get(key: K): V? = internalMap.get(key)
override fun put(key: K, value: V): V? = internalMap.put(key, value)
actual override fun put(key: K, value: V): V? = internalMap.put(key, value)
override fun remove(key: K): V? = internalMap.remove(key)
actual override fun remove(key: K): V? = internalMap.remove(key)
override val size: Int get() = internalMap.size
actual override val size: Int get() = internalMap.size
}
@@ -23,21 +23,21 @@ package kotlin.collections
/**
* The implementation of the [MutableSet] interface, backed by a [HashMap] instance.
*/
public open class HashSet<E> : AbstractMutableSet<E> {
public actual open class HashSet<E> : AbstractMutableSet<E>, MutableSet<E> {
private val map: HashMap<E, Any>
/**
* Constructs a new empty [HashSet].
*/
constructor() {
actual constructor() {
map = HashMap<E, Any>()
}
/**
* Constructs a new [HashSet] filled with the elements of the specified collection.
*/
constructor(elements: Collection<E>) {
actual constructor(elements: Collection<E>) {
map = HashMap<E, Any>(elements.size)
addAll(elements)
}
@@ -50,10 +50,12 @@ public open class HashSet<E> : AbstractMutableSet<E> {
*
* @throws IllegalArgumentException if the initial capacity or load factor are negative
*/
constructor(initialCapacity: Int, loadFactor: Float = 0.0f) {
actual constructor(initialCapacity: Int, loadFactor: Float) {
map = HashMap<E, Any>(initialCapacity, loadFactor)
}
actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f)
/**
* Protected constructor to specify the underlying map. This is used by
* LinkedHashSet.
@@ -64,12 +66,12 @@ public open class HashSet<E> : AbstractMutableSet<E> {
this.map = map
}
override fun add(element: E): Boolean {
actual override fun add(element: E): Boolean {
val old = map.put(element, this)
return old == null
}
override fun clear() {
actual override fun clear() {
map.clear()
}
@@ -77,15 +79,15 @@ public open class HashSet<E> : AbstractMutableSet<E> {
// return HashSet<E>(this)
// }
override operator fun contains(element: E): Boolean = map.containsKey(element)
actual override operator fun contains(element: E): Boolean = map.containsKey(element)
override fun isEmpty(): Boolean = map.isEmpty()
actual override fun isEmpty(): Boolean = map.isEmpty()
override fun iterator(): MutableIterator<E> = map.keys.iterator()
actual override fun iterator(): MutableIterator<E> = map.keys.iterator()
override fun remove(element: E): Boolean = map.remove(element) != null
actual override fun remove(element: E): Boolean = map.remove(element) != null
override val size: Int get() = map.size
actual override val size: Int get() = map.size
}
@@ -27,7 +27,7 @@ import kotlin.collections.MutableMap.MutableEntry
*
* The insertion order is preserved by maintaining a doubly-linked list of all of its entries.
*/
public open class LinkedHashMap<K, V> : HashMap<K, V>, Map<K, V> {
public actual open class LinkedHashMap<K, V> : HashMap<K, V>, MutableMap<K, V> {
/**
* The entry we use includes next/prev pointers for a doubly-linked circular
@@ -169,7 +169,7 @@ public open class LinkedHashMap<K, V> : HashMap<K, V>, Map<K, V> {
/**
* Constructs an empty [LinkedHashMap] instance.
*/
constructor() : super() {
actual constructor() : super() {
map = HashMap<K, ChainEntry<K, V>>()
}
@@ -186,19 +186,21 @@ public open class LinkedHashMap<K, V> : HashMap<K, V>, Map<K, V> {
*
* @throws IllegalArgumentException if the initial capacity or load factor are negative
*/
constructor(initialCapacity: Int, loadFactor: Float = 0f) : super(initialCapacity, loadFactor) {
actual constructor(initialCapacity: Int, loadFactor: Float) : super(initialCapacity, loadFactor) {
map = HashMap<K, ChainEntry<K, V>>()
}
actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f)
/**
* Constructs an instance of [LinkedHashMap] filled with the contents of the specified [original] map.
*/
constructor(original: Map<out K, V>) {
actual constructor(original: Map<out K, V>) {
map = HashMap<K, ChainEntry<K, V>>()
this.putAll(original)
}
override fun clear() {
actual override fun clear() {
map.clear()
head = null
}
@@ -208,9 +210,10 @@ public open class LinkedHashMap<K, V> : HashMap<K, V>, Map<K, V> {
// return LinkedHashMap(this)
// }
override fun containsKey(key: K): Boolean = map.containsKey(key)
override fun containsValue(value: V): Boolean {
actual override fun containsKey(key: K): Boolean = map.containsKey(key)
actual override fun containsValue(value: V): Boolean {
var node: ChainEntry<K, V> = head ?: return false
do {
if (node.value == value) {
@@ -224,9 +227,9 @@ public open class LinkedHashMap<K, V> : HashMap<K, V>, Map<K, V> {
override fun createEntrySet(): MutableSet<MutableMap.MutableEntry<K, V>> = EntrySet()
override operator fun get(key: K): V? = map.get(key)?.value
actual override operator fun get(key: K): V? = map.get(key)?.value
override fun put(key: K, value: V): V? {
actual override fun put(key: K, value: V): V? {
val old = map.get(key)
if (old == null) {
val newEntry = ChainEntry(key, value)
@@ -239,7 +242,7 @@ public open class LinkedHashMap<K, V> : HashMap<K, V>, Map<K, V> {
}
}
override fun remove(key: K): V? {
actual override fun remove(key: K): V? {
val entry = map.remove(key)
if (entry != null) {
entry.remove()
@@ -248,7 +251,7 @@ public open class LinkedHashMap<K, V> : HashMap<K, V>, Map<K, V> {
return null
}
override val size: Int get() = map.size
actual override val size: Int get() = map.size
}
@@ -25,19 +25,19 @@ package kotlin.collections
*
* This implementation preserves the insertion order of elements during the iteration.
*/
public open class LinkedHashSet<E> : HashSet<E> {
public actual open class LinkedHashSet<E> : HashSet<E>, MutableSet<E> {
internal constructor(map: LinkedHashMap<E, Any>) : super(map)
/**
* Constructs a new empty [LinkedHashSet].
*/
constructor() : super(LinkedHashMap<E, Any>())
actual constructor() : super(LinkedHashMap<E, Any>())
/**
* Constructs a new [LinkedHashSet] filled with the elements of the specified collection.
*/
constructor(elements: Collection<E>) : super(LinkedHashMap<E, Any>()) {
actual constructor(elements: Collection<E>) : super(LinkedHashMap<E, Any>()) {
addAll(elements)
}
/**
@@ -48,7 +48,9 @@ public open class LinkedHashSet<E> : HashSet<E> {
*
* @throws IllegalArgumentException if the initial capacity or load factor are negative
*/
constructor(initialCapacity: Int, loadFactor: Float = 0.0f) : super(LinkedHashMap<E, Any>(initialCapacity, loadFactor))
actual constructor(initialCapacity: Int, loadFactor: Float) : super(LinkedHashMap<E, Any>(initialCapacity, loadFactor))
actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f)
// public override fun clone(): Any {
// return LinkedHashSet(this)
@@ -19,4 +19,4 @@ package kotlin.collections
/**
* Marker interface indicating that the [List] implementation supports fast indexed access.
*/
public interface RandomAccess
public actual interface RandomAccess
+1 -1
View File
@@ -23,4 +23,4 @@ public typealias Synchronized = kotlin.jvm.Synchronized
public typealias Volatile = kotlin.jvm.Volatile
@kotlin.internal.InlineOnly
public inline fun <R> synchronized(@Suppress("UNUSED_PARAMETER") lock: Any, block: () -> R): R = block()
public actual inline fun <R> synchronized(@Suppress("UNUSED_PARAMETER") lock: Any, block: () -> R): R = block()
+3 -3
View File
@@ -98,16 +98,16 @@ private var output = run {
private inline fun String(value: Any?): String = js("String")(value)
/** Prints a newline to the standard output stream. */
public fun println() {
public actual fun println() {
output.println()
}
/** Prints the given message and newline to the standard output stream. */
public fun println(message: Any?) {
public actual fun println(message: Any?) {
output.println(message)
}
/** Prints the given message to the standard output stream. */
public fun print(message: Any?) {
public actual fun print(message: Any?) {
output.print(message)
}
+7 -7
View File
@@ -52,21 +52,21 @@ private val RESUMED: Any? = Any()
private class Fail(val exception: Throwable)
@PublishedApi
internal class SafeContinuation<in T>
internal constructor(
internal actual class SafeContinuation<in T>
internal actual constructor(
private val delegate: Continuation<T>,
initialResult: Any?
) : Continuation<T> {
@PublishedApi
internal constructor(delegate: Continuation<T>) : this(delegate, UNDECIDED)
internal actual constructor(delegate: Continuation<T>) : this(delegate, UNDECIDED)
public override val context: CoroutineContext
public actual override val context: CoroutineContext
get() = delegate.context
private var result: Any? = initialResult
override fun resume(value: T) {
actual override fun resume(value: T) {
when {
result === UNDECIDED -> {
result = value
@@ -81,7 +81,7 @@ internal constructor(
}
}
override fun resumeWithException(exception: Throwable) {
actual override fun resumeWithException(exception: Throwable) {
when {
result === UNDECIDED -> {
result = Fail(exception)
@@ -97,7 +97,7 @@ internal constructor(
}
@PublishedApi
internal fun getResult(): Any? {
internal actual fun getResult(): Any? {
if (result === UNDECIDED) {
result = COROUTINE_SUSPENDED
}
@@ -21,25 +21,25 @@ import kotlin.coroutines.experimental.Continuation
@SinceKotlin("1.1")
@Suppress("UNCHECKED_CAST")
@kotlin.internal.InlineOnly
public inline fun <T> (suspend () -> T).startCoroutineUninterceptedOrReturn(
public actual inline fun <T> (suspend () -> T).startCoroutineUninterceptedOrReturn(
completion: Continuation<T>
): Any? = this.asDynamic()(completion, false)
@SinceKotlin("1.1")
@Suppress("UNCHECKED_CAST")
@kotlin.internal.InlineOnly
public inline fun <R, T> (suspend R.() -> T).startCoroutineUninterceptedOrReturn(
public actual inline fun <R, T> (suspend R.() -> T).startCoroutineUninterceptedOrReturn(
receiver: R,
completion: Continuation<T>
): Any? = this.asDynamic()(receiver, completion, false)
@SinceKotlin("1.1")
public fun <R, T> (suspend R.() -> T).createCoroutineUnchecked(
public actual fun <R, T> (suspend R.() -> T).createCoroutineUnchecked(
receiver: R,
completion: Continuation<T>
): Continuation<Unit> = this.asDynamic()(receiver, completion, true).facade
@SinceKotlin("1.1")
public fun <T> (suspend () -> T).createCoroutineUnchecked(
public actual fun <T> (suspend () -> T).createCoroutineUnchecked(
completion: Continuation<T>
): Continuation<Unit> = this.asDynamic()(completion, true).facade
+69 -69
View File
@@ -31,102 +31,102 @@ public open class MyException : Exception {
// TODO: remove primary constructors, make all secondary KT-22055
@Suppress("USELESS_ELVIS_RIGHT_IS_NULL")
public open class Error(message: String?, cause: Throwable?) : Throwable(message, cause ?: null) {
constructor() : this(null, null) {
public actual open class Error actual constructor(message: String?, cause: Throwable?) : Throwable(message, cause ?: null) {
actual constructor() : this(null, null) {
Error::class.js.asDynamic().call(this, null, null)
}
constructor(message: String?) : this(message, null) {
actual constructor(message: String?) : this(message, null) {
Error::class.js.asDynamic().call(this, message, null)
}
constructor(cause: Throwable?) : this(undefined, cause) {
actual constructor(cause: Throwable?) : this(undefined, cause) {
Error::class.js.asDynamic().call(this, undefined, cause)
}
}
@Suppress("USELESS_ELVIS_RIGHT_IS_NULL")
public open class Exception(message: String?, cause: Throwable?) : Throwable(message, cause ?: null) {
constructor() : this(null, null) {
public actual open class Exception actual constructor(message: String?, cause: Throwable?) : Throwable(message, cause ?: null) {
actual constructor() : this(null, null) {
Exception::class.js.asDynamic().call(this, null, null)
}
constructor(message: String?) : this(message, null) {
actual constructor(message: String?) : this(message, null) {
Exception::class.js.asDynamic().call(this, message, null)
}
constructor(cause: Throwable?) : this(undefined, cause) {
actual constructor(cause: Throwable?) : this(undefined, cause) {
Exception::class.js.asDynamic().call(this, undefined, cause)
}
}
public open class RuntimeException(message: String?, cause: Throwable?) : Exception(message, cause) {
constructor() : this(null, null)
public actual open class RuntimeException actual constructor(message: String?, cause: Throwable?) : Exception(message, cause) {
actual constructor() : this(null, null)
actual constructor(message: String?) : this(message, null)
actual constructor(cause: Throwable?) : this(undefined, cause)
}
public actual open class IllegalArgumentException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
actual constructor() : this(null, null)
actual constructor(message: String?) : this(message, null)
actual constructor(cause: Throwable?) : this(undefined, cause)
}
public actual open class IllegalStateException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
actual constructor() : this(null, null)
actual constructor(message: String?) : this(message, null)
actual constructor(cause: Throwable?) : this(undefined, cause)
}
public actual open class IndexOutOfBoundsException actual constructor(message: String?) : RuntimeException(message) {
actual constructor() : this(null)
}
public actual open class ConcurrentModificationException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
actual constructor() : this(null, null)
actual constructor(message: String?) : this(message, null)
actual constructor(cause: Throwable?) : this(undefined, cause)
}
public actual open class UnsupportedOperationException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
actual constructor() : this(null, null)
actual constructor(message: String?) : this(message, null)
actual constructor(cause: Throwable?) : this(undefined, cause)
}
public actual open class NumberFormatException actual constructor(message: String?) : IllegalArgumentException(message) {
actual constructor() : this(null)
}
public actual open class NullPointerException actual constructor(message: String?) : RuntimeException(message) {
actual constructor() : this(null)
}
public actual open class ClassCastException actual constructor(message: String?) : RuntimeException(message) {
actual constructor() : this(null)
}
public actual open class AssertionError private constructor(message: String?, cause: Throwable?) : Error(message, cause) {
actual constructor() : this(null)
constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(undefined, cause)
actual constructor(message: Any?) : this(message.toString(), message as? Throwable)
}
public open class IllegalArgumentException(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
constructor() : this(null, null)
constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(undefined, cause)
}
public open class IllegalStateException(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
constructor() : this(null, null)
constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(undefined, cause)
}
public open class IndexOutOfBoundsException(message: String?) : RuntimeException(message) {
constructor() : this(null)
}
public open class ConcurrentModificationException(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
constructor() : this(null, null)
constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(undefined, cause)
}
public open class UnsupportedOperationException(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
constructor() : this(null, null)
constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(undefined, cause)
public actual open class NoSuchElementException actual constructor(message: String?) : RuntimeException(message) {
actual constructor() : this(null)
}
public open class NumberFormatException(message: String?) : IllegalArgumentException(message) {
constructor() : this(null)
public actual open class NoWhenBranchMatchedException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
actual constructor() : this(null, null)
actual constructor(message: String?) : this(message, null)
actual constructor(cause: Throwable?) : this(undefined, cause)
}
public open class NullPointerException(message: String?) : RuntimeException(message) {
constructor() : this(null)
}
public open class ClassCastException(message: String?) : RuntimeException(message) {
constructor() : this(null)
}
public open class AssertionError private constructor(message: String?, cause: Throwable?) : Error(message, cause) {
constructor() : this(null)
constructor(message: String?) : this(message, null)
constructor(message: Any?) : this(message.toString(), message as? Throwable)
}
public open class NoSuchElementException(message: String?) : RuntimeException(message) {
constructor() : this(null)
}
public open class NoWhenBranchMatchedException(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
constructor() : this(null, null)
constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(undefined, cause)
}
public open class UninitializedPropertyAccessException(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
constructor() : this(null, null)
constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(undefined, cause)
public actual open class UninitializedPropertyAccessException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
actual constructor() : this(null, null)
actual constructor(message: String?) : this(message, null)
actual constructor(cause: Throwable?) : this(undefined, cause)
}
+1 -1
View File
@@ -21,7 +21,7 @@ package kotlin.collections
* @return a [Map] associating the key of each group with the count of element in the group.
*/
@SinceKotlin("1.1")
public fun <T, K> Grouping<T, K>.eachCount(): Map<K, Int> =
public actual fun <T, K> Grouping<T, K>.eachCount(): Map<K, Int> =
fold(0) { acc, _ -> acc + 1 }
/**
+1 -1
View File
@@ -17,4 +17,4 @@
package kotlin.io
// temporary for shared code, until we have an annotation like JvmSerializable
internal interface Serializable
internal actual interface Serializable
+3 -3
View File
@@ -53,20 +53,20 @@ public fun booleanArrayOf(vararg elements: Boolean): BooleanArray = definedExter
/**
* Creates a new instance of the [Lazy] that uses the specified initialization function [initializer].
*/
public fun <T> lazy(initializer: () -> T): Lazy<T> = UnsafeLazyImpl(initializer)
public actual fun <T> lazy(initializer: () -> T): Lazy<T> = UnsafeLazyImpl(initializer)
/**
* Creates a new instance of the [Lazy] that uses the specified initialization function [initializer].
*
* The [mode] parameter is ignored. */
public fun <T> lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy<T> = UnsafeLazyImpl(initializer)
public actual fun <T> lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy<T> = UnsafeLazyImpl(initializer)
/**
* Creates a new instance of the [Lazy] that uses the specified initialization function [initializer].
*
* The [lock] parameter is ignored.
*/
public fun <T> lazy(lock: Any?, initializer: () -> T): Lazy<T> = UnsafeLazyImpl(initializer)
public actual fun <T> lazy(lock: Any?, initializer: () -> T): Lazy<T> = UnsafeLazyImpl(initializer)
internal fun fillFrom(src: dynamic, dst: dynamic): dynamic {
+90 -98
View File
@@ -20,14 +20,6 @@ package kotlin.math
import kotlin.internal.InlineOnly
import kotlin.js.Math as nativeMath
// constants, can't use them from nativeMath as they are not constants there
/** Ratio of the circumference of a circle to its diameter, approximately 3.14159. */
@SinceKotlin("1.2")
public const val PI: Double = 3.141592653589793
/** Base of the natural logarithms, approximately 2.71828. */
@SinceKotlin("1.2")
public const val E: Double = 2.718281828459045
// ================ Double Math ========================================
@@ -38,7 +30,7 @@ public const val E: Double = 2.718281828459045
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sin(x: Double): Double = nativeMath.sin(x)
public actual inline fun sin(x: Double): Double = nativeMath.sin(x)
/** Computes the cosine of the angle [x] given in radians.
*
@@ -47,7 +39,7 @@ public inline fun sin(x: Double): Double = nativeMath.sin(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun cos(x: Double): Double = nativeMath.cos(x)
public actual inline fun cos(x: Double): Double = nativeMath.cos(x)
/** Computes the tangent of the angle [x] given in radians.
*
@@ -56,7 +48,7 @@ public inline fun cos(x: Double): Double = nativeMath.cos(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun tan(x: Double): Double = nativeMath.tan(x)
public actual inline fun tan(x: Double): Double = nativeMath.tan(x)
/**
* Computes the arc sine of the value [x];
@@ -67,7 +59,7 @@ public inline fun tan(x: Double): Double = nativeMath.tan(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun asin(x: Double): Double = nativeMath.asin(x)
public actual inline fun asin(x: Double): Double = nativeMath.asin(x)
/**
* Computes the arc cosine of the value [x];
@@ -78,7 +70,7 @@ public inline fun asin(x: Double): Double = nativeMath.asin(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun acos(x: Double): Double = nativeMath.acos(x)
public actual inline fun acos(x: Double): Double = nativeMath.acos(x)
/**
* Computes the arc tangent of the value [x];
@@ -89,7 +81,7 @@ public inline fun acos(x: Double): Double = nativeMath.acos(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atan(x: Double): Double = nativeMath.atan(x)
public actual inline fun atan(x: Double): Double = nativeMath.atan(x)
/**
* Returns the angle `theta` of the polar coordinates `(r, theta)` that correspond
@@ -109,7 +101,7 @@ public inline fun atan(x: Double): Double = nativeMath.atan(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atan2(y: Double, x: Double): Double = nativeMath.atan2(y, x)
public actual inline fun atan2(y: Double, x: Double): Double = nativeMath.atan2(y, x)
/**
* Computes the hyperbolic sine of the value [x].
@@ -121,7 +113,7 @@ public inline fun atan2(y: Double, x: Double): Double = nativeMath.atan2(y, x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sinh(x: Double): Double = nativeMath.sinh(x)
public actual inline fun sinh(x: Double): Double = nativeMath.sinh(x)
/**
* Computes the hyperbolic cosine of the value [x].
@@ -132,7 +124,7 @@ public inline fun sinh(x: Double): Double = nativeMath.sinh(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun cosh(x: Double): Double = nativeMath.cosh(x)
public actual inline fun cosh(x: Double): Double = nativeMath.cosh(x)
/**
* Computes the hyperbolic tangent of the value [x].
@@ -144,7 +136,7 @@ public inline fun cosh(x: Double): Double = nativeMath.cosh(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun tanh(x: Double): Double = nativeMath.tanh(x)
public actual inline fun tanh(x: Double): Double = nativeMath.tanh(x)
/**
* Computes the inverse hyperbolic sine of the value [x].
@@ -158,7 +150,7 @@ public inline fun tanh(x: Double): Double = nativeMath.tanh(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun asinh(x: Double): Double = nativeMath.asinh(x)
public actual inline fun asinh(x: Double): Double = nativeMath.asinh(x)
/**
* Computes the inverse hyperbolic cosine of the value [x].
@@ -172,7 +164,7 @@ public inline fun asinh(x: Double): Double = nativeMath.asinh(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun acosh(x: Double): Double = nativeMath.acosh(x)
public actual inline fun acosh(x: Double): Double = nativeMath.acosh(x)
/**
* Computes the inverse hyperbolic tangent of the value [x].
@@ -187,7 +179,7 @@ public inline fun acosh(x: Double): Double = nativeMath.acosh(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atanh(x: Double): Double = nativeMath.atanh(x)
public actual inline fun atanh(x: Double): Double = nativeMath.atanh(x)
/**
* Computes `sqrt(x^2 + y^2)` without intermediate overflow or underflow.
@@ -198,7 +190,7 @@ public inline fun atanh(x: Double): Double = nativeMath.atanh(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y)
public actual inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y)
/**
* Computes the positive square root of the value [x].
@@ -208,7 +200,7 @@ public inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sqrt(x: Double): Double = nativeMath.sqrt(x)
public actual inline fun sqrt(x: Double): Double = nativeMath.sqrt(x)
/**
* Computes Euler's number `e` raised to the power of the value [x].
@@ -220,7 +212,7 @@ public inline fun sqrt(x: Double): Double = nativeMath.sqrt(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun exp(x: Double): Double = nativeMath.exp(x)
public actual inline fun exp(x: Double): Double = nativeMath.exp(x)
/**
* Computes `exp(x) - 1`.
@@ -236,7 +228,7 @@ public inline fun exp(x: Double): Double = nativeMath.exp(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun expm1(x: Double): Double = nativeMath.expm1(x)
public actual inline fun expm1(x: Double): Double = nativeMath.expm1(x)
/**
* Computes the logarithm of the value [x] to the given [base].
@@ -251,7 +243,7 @@ public inline fun expm1(x: Double): Double = nativeMath.expm1(x)
* See also logarithm functions for common fixed bases: [ln], [log10] and [log2].
*/
@SinceKotlin("1.2")
public fun log(x: Double, base: Double): Double {
public actual fun log(x: Double, base: Double): Double {
if (base <= 0.0 || base == 1.0) return Double.NaN
return nativeMath.log(x) / nativeMath.log(base)
}
@@ -267,7 +259,7 @@ public fun log(x: Double, base: Double): Double {
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ln(x: Double): Double = nativeMath.log(x)
public actual inline fun ln(x: Double): Double = nativeMath.log(x)
/**
* Computes the common logarithm (base 10) of the value [x].
@@ -276,7 +268,7 @@ public inline fun ln(x: Double): Double = nativeMath.log(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log10(x: Double): Double = nativeMath.log10(x)
public actual inline fun log10(x: Double): Double = nativeMath.log10(x)
/**
* Computes the binary logarithm (base 2) of the value [x].
@@ -285,7 +277,7 @@ public inline fun log10(x: Double): Double = nativeMath.log10(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log2(x: Double): Double = nativeMath.log2(x)
public actual inline fun log2(x: Double): Double = nativeMath.log2(x)
/**
* Computes `ln(x + 1)`.
@@ -303,7 +295,7 @@ public inline fun log2(x: Double): Double = nativeMath.log2(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ln1p(x: Double): Double = nativeMath.log1p(x)
public actual inline fun ln1p(x: Double): Double = nativeMath.log1p(x)
/**
* Rounds the given value [x] to an integer towards positive infinity.
@@ -315,7 +307,7 @@ public inline fun ln1p(x: Double): Double = nativeMath.log1p(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ceil(x: Double): Double = nativeMath.ceil(x).unsafeCast<Double>() // TODO: Remove unsafe cast after removing public js.math
public actual inline fun ceil(x: Double): Double = nativeMath.ceil(x).unsafeCast<Double>() // TODO: Remove unsafe cast after removing public js.math
/**
* Rounds the given value [x] to an integer towards negative infinity.
@@ -327,7 +319,7 @@ public inline fun ceil(x: Double): Double = nativeMath.ceil(x).unsafeCast<Double
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun floor(x: Double): Double = nativeMath.floor(x).unsafeCast<Double>()
public actual inline fun floor(x: Double): Double = nativeMath.floor(x).unsafeCast<Double>()
/**
* Rounds the given value [x] to an integer towards zero.
@@ -339,7 +331,7 @@ public inline fun floor(x: Double): Double = nativeMath.floor(x).unsafeCast<Doub
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun truncate(x: Double): Double = nativeMath.trunc(x)
public actual inline fun truncate(x: Double): Double = nativeMath.trunc(x)
/**
* Rounds the given value [x] towards the closest integer with ties rounded towards even integer.
@@ -348,7 +340,7 @@ public inline fun truncate(x: Double): Double = nativeMath.trunc(x)
* - `round(x)` is `x` where `x` is `NaN` or `+Inf` or `-Inf` or already a mathematical integer.
*/
@SinceKotlin("1.2")
public fun round(x: Double): Double {
public actual fun round(x: Double): Double {
if (x % 0.5 != 0.0) {
return nativeMath.round(x).unsafeCast<Double>()
}
@@ -366,7 +358,7 @@ public fun round(x: Double): Double {
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun abs(x: Double): Double = nativeMath.abs(x)
public actual inline fun abs(x: Double): Double = nativeMath.abs(x)
/**
* Returns the sign of the given value [x]:
@@ -379,7 +371,7 @@ public inline fun abs(x: Double): Double = nativeMath.abs(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sign(x: Double): Double = nativeMath.sign(x)
public actual inline fun sign(x: Double): Double = nativeMath.sign(x)
/**
@@ -389,7 +381,7 @@ public inline fun sign(x: Double): Double = nativeMath.sign(x)
*/
@SinceKotlin("1.2")
@InlineOnly
public 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.
*
@@ -397,7 +389,7 @@ public inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b)
public actual inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b)
// extensions
@@ -414,7 +406,7 @@ public inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Double.pow(x: Double): Double = nativeMath.pow(this, x)
public actual inline fun Double.pow(x: Double): Double = nativeMath.pow(this, x)
/**
* Raises this value to the integer power [n].
@@ -423,7 +415,7 @@ public inline fun Double.pow(x: Double): Double = nativeMath.pow(this, x)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Double.pow(n: Int): Double = nativeMath.pow(this, n.toDouble())
public actual inline fun Double.pow(n: Int): Double = nativeMath.pow(this, n.toDouble())
/**
* Returns the absolute value of this value.
@@ -435,7 +427,7 @@ public inline fun Double.pow(n: Int): Double = nativeMath.pow(this, n.toDouble()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Double.absoluteValue: Double get() = nativeMath.abs(this)
public actual inline val Double.absoluteValue: Double get() = nativeMath.abs(this)
/**
* Returns the sign of this value:
@@ -448,7 +440,7 @@ public inline val Double.absoluteValue: Double get() = nativeMath.abs(this)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Double.sign: Double get() = nativeMath.sign(this)
public actual inline val Double.sign: Double get() = nativeMath.sign(this)
/**
* Returns this value with the sign bit same as of the [sign] value.
@@ -456,7 +448,7 @@ public inline val Double.sign: Double get() = nativeMath.sign(this)
* If [sign] is `NaN` the sign of the result is undefined.
*/
@SinceKotlin("1.2")
public fun Double.withSign(sign: Double): Double {
public actual fun Double.withSign(sign: Double): Double {
val thisSignBit = js("Kotlin").doubleSignBit(this).unsafeCast<Int>()
val newSignBit = js("Kotlin").doubleSignBit(sign).unsafeCast<Int>()
return if (thisSignBit == newSignBit) this else -this
@@ -467,7 +459,7 @@ public fun Double.withSign(sign: Double): Double {
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Double.withSign(sign: Int): Double = this.withSign(sign.toDouble())
public actual inline fun Double.withSign(sign: Int): Double = this.withSign(sign.toDouble())
/**
* Returns the ulp (unit in the last place) of this value.
@@ -480,7 +472,7 @@ public inline fun Double.withSign(sign: Int): Double = this.withSign(sign.toDoub
* - `0.0.ulp` is `Double.MIN_VALUE`
*/
@SinceKotlin("1.2")
public val Double.ulp: Double get() = when {
public actual val Double.ulp: Double get() = when {
this < 0 -> (-this).ulp
this.isNaN() || this == Double.POSITIVE_INFINITY -> this
this == Double.MAX_VALUE -> this - this.nextDown()
@@ -491,7 +483,7 @@ public val Double.ulp: Double get() = when {
* Returns the [Double] value nearest to this value in direction of positive infinity.
*/
@SinceKotlin("1.2")
public fun Double.nextUp(): Double = when {
public actual fun Double.nextUp(): Double = when {
this.isNaN() || this == Double.POSITIVE_INFINITY -> this
this == 0.0 -> Double.MIN_VALUE
else -> Double.fromBits(this.toRawBits() + if (this > 0) 1 else -1)
@@ -501,7 +493,7 @@ public fun Double.nextUp(): Double = when {
* Returns the [Double] value nearest to this value in direction of negative infinity.
*/
@SinceKotlin("1.2")
public fun Double.nextDown(): Double = when {
public actual fun Double.nextDown(): Double = when {
this.isNaN() || this == Double.NEGATIVE_INFINITY -> this
this == 0.0 -> -Double.MIN_VALUE
else -> Double.fromBits(this.toRawBits() + if (this > 0) -1 else 1)
@@ -517,7 +509,7 @@ public fun Double.nextDown(): Double = when {
*
*/
@SinceKotlin("1.2")
public fun Double.nextTowards(to: Double): Double = when {
public actual fun Double.nextTowards(to: Double): Double = when {
this.isNaN() || to.isNaN() -> Double.NaN
to == this -> to
to > this -> this.nextUp()
@@ -536,7 +528,7 @@ public fun Double.nextTowards(to: Double): Double = when {
* @throws IllegalArgumentException when this value is `NaN`
*/
@SinceKotlin("1.2")
public fun Double.roundToInt(): Int = when {
public actual fun Double.roundToInt(): Int = when {
isNaN() -> throw IllegalArgumentException("Cannot round NaN value.")
this > Int.MAX_VALUE -> Int.MAX_VALUE
this < Int.MIN_VALUE -> Int.MIN_VALUE
@@ -554,7 +546,7 @@ public fun Double.roundToInt(): Int = when {
* @throws IllegalArgumentException when this value is `NaN`
*/
@SinceKotlin("1.2")
public fun Double.roundToLong(): Long = when {
public actual fun Double.roundToLong(): Long = when {
isNaN() -> throw IllegalArgumentException("Cannot round NaN value.")
this > Long.MAX_VALUE -> Long.MAX_VALUE
this < Long.MIN_VALUE -> Long.MIN_VALUE
@@ -573,7 +565,7 @@ public fun Double.roundToLong(): Long = when {
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sin(x: Float): Float = nativeMath.sin(x.toDouble()).toFloat()
public actual inline fun sin(x: Float): Float = nativeMath.sin(x.toDouble()).toFloat()
/** Computes the cosine of the angle [x] given in radians.
*
@@ -582,7 +574,7 @@ public inline fun sin(x: Float): Float = nativeMath.sin(x.toDouble()).toFloat()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun cos(x: Float): Float = nativeMath.cos(x.toDouble()).toFloat()
public actual inline fun cos(x: Float): Float = nativeMath.cos(x.toDouble()).toFloat()
/** Computes the tangent of the angle [x] given in radians.
*
@@ -591,7 +583,7 @@ public inline fun cos(x: Float): Float = nativeMath.cos(x.toDouble()).toFloat()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun tan(x: Float): Float = nativeMath.tan(x.toDouble()).toFloat()
public actual inline fun tan(x: Float): Float = nativeMath.tan(x.toDouble()).toFloat()
/**
* Computes the arc sine of the value [x];
@@ -602,7 +594,7 @@ public inline fun tan(x: Float): Float = nativeMath.tan(x.toDouble()).toFloat()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun asin(x: Float): Float = nativeMath.asin(x.toDouble()).toFloat()
public actual inline fun asin(x: Float): Float = nativeMath.asin(x.toDouble()).toFloat()
/**
* Computes the arc cosine of the value [x];
@@ -613,7 +605,7 @@ public inline fun asin(x: Float): Float = nativeMath.asin(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun acos(x: Float): Float = nativeMath.acos(x.toDouble()).toFloat()
public actual inline fun acos(x: Float): Float = nativeMath.acos(x.toDouble()).toFloat()
/**
* Computes the arc tangent of the value [x];
@@ -624,7 +616,7 @@ public inline fun acos(x: Float): Float = nativeMath.acos(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atan(x: Float): Float = nativeMath.atan(x.toDouble()).toFloat()
public actual inline fun atan(x: Float): Float = nativeMath.atan(x.toDouble()).toFloat()
/**
* Returns the angle `theta` of the polar coordinates `(r, theta)` that correspond
@@ -644,7 +636,7 @@ public inline fun atan(x: Float): Float = nativeMath.atan(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atan2(y: Float, x: Float): Float = nativeMath.atan2(y.toDouble(), x.toDouble()).toFloat()
public actual inline fun atan2(y: Float, x: Float): Float = nativeMath.atan2(y.toDouble(), x.toDouble()).toFloat()
/**
* Computes the hyperbolic sine of the value [x].
@@ -656,7 +648,7 @@ public inline fun atan2(y: Float, x: Float): Float = nativeMath.atan2(y.toDouble
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sinh(x: Float): Float = nativeMath.sinh(x.toDouble()).toFloat()
public actual inline fun sinh(x: Float): Float = nativeMath.sinh(x.toDouble()).toFloat()
/**
* Computes the hyperbolic cosine of the value [x].
@@ -667,7 +659,7 @@ public inline fun sinh(x: Float): Float = nativeMath.sinh(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun cosh(x: Float): Float = nativeMath.cosh(x.toDouble()).toFloat()
public actual inline fun cosh(x: Float): Float = nativeMath.cosh(x.toDouble()).toFloat()
/**
* Computes the hyperbolic tangent of the value [x].
@@ -679,7 +671,7 @@ public inline fun cosh(x: Float): Float = nativeMath.cosh(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun tanh(x: Float): Float = nativeMath.tanh(x.toDouble()).toFloat()
public actual inline fun tanh(x: Float): Float = nativeMath.tanh(x.toDouble()).toFloat()
/**
* Computes the inverse hyperbolic sine of the value [x].
@@ -693,7 +685,7 @@ public inline fun tanh(x: Float): Float = nativeMath.tanh(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun asinh(x: Float): Float = nativeMath.asinh(x.toDouble()).toFloat()
public actual inline fun asinh(x: Float): Float = nativeMath.asinh(x.toDouble()).toFloat()
/**
* Computes the inverse hyperbolic cosine of the value [x].
@@ -707,7 +699,7 @@ public inline fun asinh(x: Float): Float = nativeMath.asinh(x.toDouble()).toFloa
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun acosh(x: Float): Float = nativeMath.acosh(x.toDouble()).toFloat()
public actual inline fun acosh(x: Float): Float = nativeMath.acosh(x.toDouble()).toFloat()
/**
* Computes the inverse hyperbolic tangent of the value [x].
@@ -722,7 +714,7 @@ public inline fun acosh(x: Float): Float = nativeMath.acosh(x.toDouble()).toFloa
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atanh(x: Float): Float = nativeMath.atanh(x.toDouble()).toFloat()
public actual inline fun atanh(x: Float): Float = nativeMath.atanh(x.toDouble()).toFloat()
/**
* Computes `sqrt(x^2 + y^2)` without intermediate overflow or underflow.
@@ -733,7 +725,7 @@ public inline fun atanh(x: Float): Float = nativeMath.atanh(x.toDouble()).toFloa
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun hypot(x: Float, y: Float): Float = nativeMath.hypot(x.toDouble(), y.toDouble()).toFloat()
public actual inline fun hypot(x: Float, y: Float): Float = nativeMath.hypot(x.toDouble(), y.toDouble()).toFloat()
/**
* Computes the positive square root of the value [x].
@@ -743,7 +735,7 @@ public inline fun hypot(x: Float, y: Float): Float = nativeMath.hypot(x.toDouble
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sqrt(x: Float): Float = nativeMath.sqrt(x.toDouble()).toFloat()
public actual inline fun sqrt(x: Float): Float = nativeMath.sqrt(x.toDouble()).toFloat()
/**
* Computes Euler's number `e` raised to the power of the value [x].
@@ -755,7 +747,7 @@ public inline fun sqrt(x: Float): Float = nativeMath.sqrt(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun exp(x: Float): Float = nativeMath.exp(x.toDouble()).toFloat()
public actual inline fun exp(x: Float): Float = nativeMath.exp(x.toDouble()).toFloat()
/**
* Computes `exp(x) - 1`.
@@ -771,7 +763,7 @@ public inline fun exp(x: Float): Float = nativeMath.exp(x.toDouble()).toFloat()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun expm1(x: Float): Float = nativeMath.expm1(x.toDouble()).toFloat()
public actual inline fun expm1(x: Float): Float = nativeMath.expm1(x.toDouble()).toFloat()
/**
* Computes the logarithm of the value [x] to the given [base].
@@ -787,7 +779,7 @@ public inline fun expm1(x: Float): Float = nativeMath.expm1(x.toDouble()).toFloa
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log(x: Float, base: Float): Float = log(x.toDouble(), base.toDouble()).toFloat()
public actual inline fun log(x: Float, base: Float): Float = log(x.toDouble(), base.toDouble()).toFloat()
/**
* Computes the natural logarithm (base `E`) of the value [x].
@@ -800,7 +792,7 @@ public inline fun log(x: Float, base: Float): Float = log(x.toDouble(), base.toD
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ln(x: Float): Float = nativeMath.log(x.toDouble()).toFloat()
public actual inline fun ln(x: Float): Float = nativeMath.log(x.toDouble()).toFloat()
/**
* Computes the common logarithm (base 10) of the value [x].
@@ -809,7 +801,7 @@ public inline fun ln(x: Float): Float = nativeMath.log(x.toDouble()).toFloat()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log10(x: Float): Float = nativeMath.log10(x.toDouble()).toFloat()
public actual inline fun log10(x: Float): Float = nativeMath.log10(x.toDouble()).toFloat()
/**
* Computes the binary logarithm (base 2) of the value [x].
@@ -818,7 +810,7 @@ public inline fun log10(x: Float): Float = nativeMath.log10(x.toDouble()).toFloa
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log2(x: Float): Float = nativeMath.log2(x.toDouble()).toFloat()
public actual inline fun log2(x: Float): Float = nativeMath.log2(x.toDouble()).toFloat()
/**
* Computes `ln(a + 1)`.
@@ -836,7 +828,7 @@ public inline fun log2(x: Float): Float = nativeMath.log2(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ln1p(x: Float): Float = nativeMath.log1p(x.toDouble()).toFloat()
public actual inline fun ln1p(x: Float): Float = nativeMath.log1p(x.toDouble()).toFloat()
/**
* Rounds the given value [x] to an integer towards positive infinity.
@@ -848,7 +840,7 @@ public inline fun ln1p(x: Float): Float = nativeMath.log1p(x.toDouble()).toFloat
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ceil(x: Float): Float = nativeMath.ceil(x.toDouble()).toFloat()
public actual inline fun ceil(x: Float): Float = nativeMath.ceil(x.toDouble()).toFloat()
/**
* Rounds the given value [x] to an integer towards negative infinity.
@@ -860,7 +852,7 @@ public inline fun ceil(x: Float): Float = nativeMath.ceil(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun floor(x: Float): Float = nativeMath.floor(x.toDouble()).toFloat()
public actual inline fun floor(x: Float): Float = nativeMath.floor(x.toDouble()).toFloat()
/**
* Rounds the given value [x] to an integer towards zero.
@@ -872,7 +864,7 @@ public inline fun floor(x: Float): Float = nativeMath.floor(x.toDouble()).toFloa
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun truncate(x: Float): Float = truncate(x.toDouble()).toFloat()
public actual inline fun truncate(x: Float): Float = truncate(x.toDouble()).toFloat()
/**
* Rounds the given value [x] towards the closest integer with ties rounded towards even integer.
@@ -882,7 +874,7 @@ public inline fun truncate(x: Float): Float = truncate(x.toDouble()).toFloat()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun round(x: Float): Float = round(x.toDouble()).toFloat()
public actual inline fun round(x: Float): Float = round(x.toDouble()).toFloat()
/**
@@ -895,7 +887,7 @@ public inline fun round(x: Float): Float = round(x.toDouble()).toFloat()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun abs(x: Float): Float = nativeMath.abs(x.toDouble()).toFloat()
public actual inline fun abs(x: Float): Float = nativeMath.abs(x.toDouble()).toFloat()
/**
* Returns the sign of the given value [x]:
@@ -908,7 +900,7 @@ public inline fun abs(x: Float): Float = nativeMath.abs(x.toDouble()).toFloat()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sign(x: Float): Float = nativeMath.sign(x.toDouble()).toFloat()
public actual inline fun sign(x: Float): Float = nativeMath.sign(x.toDouble()).toFloat()
@@ -919,7 +911,7 @@ public inline fun sign(x: Float): Float = nativeMath.sign(x.toDouble()).toFloat(
*/
@SinceKotlin("1.2")
@InlineOnly
public 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.
*
@@ -927,7 +919,7 @@ public inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun max(a: Float, b: Float): Float = nativeMath.max(a, b)
public actual inline fun max(a: Float, b: Float): Float = nativeMath.max(a, b)
// extensions
@@ -945,7 +937,7 @@ public inline fun max(a: Float, b: Float): Float = nativeMath.max(a, b)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.pow(x: Float): Float = nativeMath.pow(this.toDouble(), x.toDouble()).toFloat()
public actual inline fun Float.pow(x: Float): Float = nativeMath.pow(this.toDouble(), x.toDouble()).toFloat()
/**
* Raises this value to the integer power [n].
@@ -954,7 +946,7 @@ public inline fun Float.pow(x: Float): Float = nativeMath.pow(this.toDouble(), x
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.pow(n: Int): Float = nativeMath.pow(this.toDouble(), n.toDouble()).toFloat()
public actual inline fun Float.pow(n: Int): Float = nativeMath.pow(this.toDouble(), n.toDouble()).toFloat()
/**
* Returns the absolute value of this value.
@@ -966,7 +958,7 @@ public inline fun Float.pow(n: Int): Float = nativeMath.pow(this.toDouble(), n.t
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Float.absoluteValue: Float get() = nativeMath.abs(this.toDouble()).toFloat()
public actual inline val Float.absoluteValue: Float get() = nativeMath.abs(this.toDouble()).toFloat()
/**
* Returns the sign of this value:
@@ -979,7 +971,7 @@ public inline val Float.absoluteValue: Float get() = nativeMath.abs(this.toDoubl
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Float.sign: Float get() = nativeMath.sign(this.toDouble()).toFloat()
public actual inline val Float.sign: Float get() = nativeMath.sign(this.toDouble()).toFloat()
/**
* Returns this value with the sign bit same as of the [sign] value.
@@ -988,13 +980,13 @@ public inline val Float.sign: Float get() = nativeMath.sign(this.toDouble()).toF
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.withSign(sign: Float): Float = this.toDouble().withSign(sign.toDouble()).toFloat()
public actual inline fun Float.withSign(sign: Float): Float = this.toDouble().withSign(sign.toDouble()).toFloat()
/**
* Returns this value with the sign bit same as of the [sign] value.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.withSign(sign: Int): Float = this.toDouble().withSign(sign.toDouble()).toFloat()
public actual inline fun Float.withSign(sign: Int): Float = this.toDouble().withSign(sign.toDouble()).toFloat()
/**
@@ -1009,7 +1001,7 @@ public inline fun Float.withSign(sign: Int): Float = this.toDouble().withSign(si
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.roundToInt(): Int = toDouble().roundToInt()
public actual inline fun Float.roundToInt(): Int = toDouble().roundToInt()
/**
* Rounds this [Float] value to the nearest integer and converts the result to [Long].
@@ -1023,7 +1015,7 @@ public inline fun Float.roundToInt(): Int = toDouble().roundToInt()
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.roundToLong(): Long = toDouble().roundToLong()
public actual inline fun Float.roundToLong(): Long = toDouble().roundToLong()
@@ -1038,21 +1030,21 @@ public inline fun Float.roundToLong(): Long = toDouble().roundToLong()
*/
// TODO: remove manual 'or' when KT-19290 is fixed
@SinceKotlin("1.2")
public fun abs(n: Int): Int = if (n < 0) (-n or 0) else n
public actual fun abs(n: Int): Int = if (n < 0) (-n or 0) else n
/**
* Returns the smaller of two values.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun min(a: Int, b: Int): Int = nativeMath.min(a, b)
public actual inline fun min(a: Int, b: Int): Int = nativeMath.min(a, b)
/**
* Returns the greater of two values.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun max(a: Int, b: Int): Int = nativeMath.max(a, b)
public actual inline fun max(a: Int, b: Int): Int = nativeMath.max(a, b)
/**
* Returns the absolute value of this value.
@@ -1064,7 +1056,7 @@ public inline fun max(a: Int, b: Int): Int = nativeMath.max(a, b)
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Int.absoluteValue: Int get() = abs(this)
public actual inline val Int.absoluteValue: Int get() = abs(this)
/**
* Returns the sign of this value:
@@ -1073,7 +1065,7 @@ public inline val Int.absoluteValue: Int get() = abs(this)
* - `1` if the value is positive
*/
@SinceKotlin("1.2")
public val Int.sign: Int get() = when {
public actual val Int.sign: Int get() = when {
this < 0 -> -1
this > 0 -> 1
else -> 0
@@ -1090,21 +1082,21 @@ public val Int.sign: Int get() = when {
* @see absoluteValue extension property for [Long]
*/
@SinceKotlin("1.2")
public fun abs(n: Long): Long = if (n < 0) -n else n
public actual fun abs(n: Long): Long = if (n < 0) -n else n
/**
* Returns the smaller of two values.
*/
@SinceKotlin("1.2")
@Suppress("NOTHING_TO_INLINE")
public inline fun min(a: Long, b: Long): Long = if (a <= b) a else b
public actual inline fun min(a: Long, b: Long): Long = if (a <= b) a else b
/**
* Returns the greater of two values.
*/
@SinceKotlin("1.2")
@Suppress("NOTHING_TO_INLINE")
public inline fun max(a: Long, b: Long): Long = if (a >= b) a else b
public actual inline fun max(a: Long, b: Long): Long = if (a >= b) a else b
/**
* Returns the absolute value of this value.
@@ -1116,7 +1108,7 @@ public inline fun max(a: Long, b: Long): Long = if (a >= b) a else b
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Long.absoluteValue: Long get() = abs(this)
public actual inline val Long.absoluteValue: Long get() = abs(this)
/**
* Returns the sign of this value:
@@ -1125,7 +1117,7 @@ public inline val Long.absoluteValue: Long get() = abs(this)
* - `1` if the value is positive
*/
@SinceKotlin("1.2")
public val Long.sign: Int get() = when {
public actual val Long.sign: Int get() = when {
this < 0 -> -1
this > 0 -> 1
else -> 0
@@ -21,66 +21,66 @@ package kotlin.text
/**
* Returns `true` if the contents of this string is equal to the word "true", ignoring case, and `false` otherwise.
*/
public fun String.toBoolean(): Boolean = toLowerCase() == "true"
public actual fun String.toBoolean(): Boolean = toLowerCase() == "true"
/**
* Parses the string as a signed [Byte] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toByte(): Byte = toByteOrNull() ?: numberFormatError(this)
public actual fun String.toByte(): Byte = toByteOrNull() ?: numberFormatError(this)
/**
* Parses the string as a signed [Byte] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
public fun String.toByte(radix: Int): Byte = toByteOrNull(radix) ?: numberFormatError(this)
public actual fun String.toByte(radix: Int): Byte = toByteOrNull(radix) ?: numberFormatError(this)
/**
* Parses the string as a [Short] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toShort(): Short = toShortOrNull() ?: numberFormatError(this)
public actual fun String.toShort(): Short = toShortOrNull() ?: numberFormatError(this)
/**
* Parses the string as a [Short] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
public fun String.toShort(radix: Int): Short = toShortOrNull(radix) ?: numberFormatError(this)
public actual fun String.toShort(radix: Int): Short = toShortOrNull(radix) ?: numberFormatError(this)
/**
* Parses the string as an [Int] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toInt(): Int = toIntOrNull() ?: numberFormatError(this)
public actual fun String.toInt(): Int = toIntOrNull() ?: numberFormatError(this)
/**
* Parses the string as an [Int] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
public fun String.toInt(radix: Int): Int = toIntOrNull(radix) ?: numberFormatError(this)
public actual fun String.toInt(radix: Int): Int = toIntOrNull(radix) ?: numberFormatError(this)
/**
* Parses the string as a [Long] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toLong(): Long = toLongOrNull() ?: numberFormatError(this)
public actual fun String.toLong(): Long = toLongOrNull() ?: numberFormatError(this)
/**
* Parses the string as a [Long] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
public fun String.toLong(radix: Int): Long = toLongOrNull(radix) ?: numberFormatError(this)
public actual fun String.toLong(radix: Int): Long = toLongOrNull(radix) ?: numberFormatError(this)
/**
* Parses the string as a [Double] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toDouble(): Double = (+(this.asDynamic())).unsafeCast<Double>().also {
public actual fun String.toDouble(): Double = (+(this.asDynamic())).unsafeCast<Double>().also {
if (it.isNaN() && !this.isNaN() || it == 0.0 && this.isBlank())
numberFormatError(this)
}
@@ -90,13 +90,13 @@ public fun String.toDouble(): Double = (+(this.asDynamic())).unsafeCast<Double>(
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
@kotlin.internal.InlineOnly
public inline fun String.toFloat(): Float = toDouble().unsafeCast<Float>()
public actual inline fun String.toFloat(): Float = toDouble().unsafeCast<Float>()
/**
* Parses the string as a [Double] number and returns the result
* or `null` if the string is not a valid representation of a number.
*/
public fun String.toDoubleOrNull(): Double? = (+(this.asDynamic())).unsafeCast<Double>().takeIf {
public actual fun String.toDoubleOrNull(): Double? = (+(this.asDynamic())).unsafeCast<Double>().takeIf {
!(it.isNaN() && !this.isNaN() || it == 0.0 && this.isBlank())
}
@@ -105,7 +105,7 @@ public fun String.toDoubleOrNull(): Double? = (+(this.asDynamic())).unsafeCast<D
* or `null` if the string is not a valid representation of a number.
*/
@kotlin.internal.InlineOnly
public inline fun String.toFloatOrNull(): Float? = toDoubleOrNull().unsafeCast<Float?>()
public actual inline fun String.toFloatOrNull(): Float? = toDoubleOrNull().unsafeCast<Float?>()
private fun String.isNaN(): Boolean = when(this.toLowerCase()) {
@@ -117,14 +117,14 @@ private fun String.isNaN(): Boolean = when(this.toLowerCase()) {
* Checks whether the given [radix] is valid radix for string to number and number to string conversion.
*/
@PublishedApi
internal fun checkRadix(radix: Int): Int {
internal actual fun checkRadix(radix: Int): Int {
if(radix !in 2..36) {
throw IllegalArgumentException("radix $radix was not in valid range 2..36")
}
return radix
}
internal fun digitOf(char: Char, radix: Int): Int = when {
internal actual fun digitOf(char: Char, radix: Int): Int = when {
char >= '0' && char <= '9' -> char - '0'
char >= 'A' && char <= 'Z' -> char - 'A' + 10
char >= 'a' && char <= 'z' -> char - 'a' + 10
+12 -12
View File
@@ -4,33 +4,33 @@ package kotlin
* Returns `true` if the specified number is a
* Not-a-Number (NaN) value, `false` otherwise.
*/
public fun Double.isNaN(): Boolean = this != this
public actual fun Double.isNaN(): Boolean = this != this
/**
* Returns `true` if the specified number is a
* Not-a-Number (NaN) value, `false` otherwise.
*/
public fun Float.isNaN(): Boolean = this != this
public actual fun Float.isNaN(): Boolean = this != this
/**
* Returns `true` if this value is infinitely large in magnitude.
*/
public fun Double.isInfinite(): Boolean = this == Double.POSITIVE_INFINITY || this == Double.NEGATIVE_INFINITY
public actual fun Double.isInfinite(): Boolean = this == Double.POSITIVE_INFINITY || this == Double.NEGATIVE_INFINITY
/**
* Returns `true` if this value is infinitely large in magnitude.
*/
public fun Float.isInfinite(): Boolean = this == Float.POSITIVE_INFINITY || this == Float.NEGATIVE_INFINITY
public actual fun Float.isInfinite(): Boolean = this == Float.POSITIVE_INFINITY || this == Float.NEGATIVE_INFINITY
/**
* Returns `true` if the argument is a finite floating-point value; returns `false` otherwise (for `NaN` and infinity arguments).
*/
public fun Double.isFinite(): Boolean = !isInfinite() && !isNaN()
public actual fun Double.isFinite(): Boolean = !isInfinite() && !isNaN()
/**
* Returns `true` if the argument is a finite floating-point value; returns `false` otherwise (for `NaN` and infinity arguments).
*/
public fun Float.isFinite(): Boolean = !isInfinite() && !isNaN()
public actual fun Float.isFinite(): Boolean = !isInfinite() && !isNaN()
/**
* Returns a bit representation of the specified floating-point value as [Long]
@@ -38,7 +38,7 @@ public fun Float.isFinite(): Boolean = !isInfinite() && !isNaN()
*/
@SinceKotlin("1.2")
@library("doubleToBits")
public fun Double.toBits(): Long = definedExternally
public actual fun Double.toBits(): Long = definedExternally
/**
* Returns a bit representation of the specified floating-point value as [Long]
@@ -47,14 +47,14 @@ public fun Double.toBits(): Long = definedExternally
*/
@SinceKotlin("1.2")
@library("doubleToRawBits")
public fun Double.toRawBits(): Long = definedExternally
public actual fun Double.toRawBits(): Long = definedExternally
/**
* Returns the [Double] value corresponding to a given bit representation.
*/
@SinceKotlin("1.2")
@kotlin.internal.InlineOnly
public inline fun Double.Companion.fromBits(bits: Long): Double = js("Kotlin").doubleFromBits(bits).unsafeCast<Double>()
public actual inline fun Double.Companion.fromBits(bits: Long): Double = js("Kotlin").doubleFromBits(bits).unsafeCast<Double>()
/**
* Returns a bit representation of the specified floating-point value as [Int]
@@ -65,7 +65,7 @@ public inline fun Double.Companion.fromBits(bits: Long): Double = js("Kotlin").d
*/
@SinceKotlin("1.2")
@library("floatToBits")
public fun Float.toBits(): Int = definedExternally
public actual fun Float.toBits(): Int = definedExternally
/**
* Returns a bit representation of the specified floating-point value as [Int]
@@ -77,11 +77,11 @@ public fun Float.toBits(): Int = definedExternally
*/
@SinceKotlin("1.2")
@library("floatToRawBits")
public fun Float.toRawBits(): Int = definedExternally
public actual fun Float.toRawBits(): Int = definedExternally
/**
* Returns the [Float] value corresponding to a given bit representation.
*/
@SinceKotlin("1.2")
@kotlin.internal.InlineOnly
public inline fun Float.Companion.fromBits(bits: Int): Float = js("Kotlin").floatFromBits(bits).unsafeCast<Float>()
public actual inline fun Float.Companion.fromBits(bits: Int): Float = js("Kotlin").floatFromBits(bits).unsafeCast<Float>()
+20 -20
View File
@@ -21,7 +21,7 @@ import kotlin.js.RegExp
/**
* Provides enumeration values to use to set regular expression options.
*/
public enum class RegexOption(val value: String) {
public actual enum class RegexOption(val value: String) {
/** Enables case-insensitive matching. */
IGNORE_CASE("i"),
/** Enables multiline mode.
@@ -37,36 +37,36 @@ public enum class RegexOption(val value: String) {
*
* @param value The value of captured group.
*/
public data class MatchGroup(val value: String)
public actual data class MatchGroup(actual val value: String)
/** A compiled representation of a regular expression.
*
* For pattern syntax reference see [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp] and [http://www.w3schools.com/jsref/jsref_obj_regexp.asp]
*/
public class Regex(pattern: String, options: Set<RegexOption>) {
public actual class Regex actual constructor(pattern: String, options: Set<RegexOption>) {
/** Creates a regular expression from the specified [pattern] string and the specified single [option]. */
public constructor(pattern: String, option: RegexOption) : this(pattern, setOf(option))
public actual constructor(pattern: String, option: RegexOption) : this(pattern, setOf(option))
/** Creates a regular expression from the specified [pattern] string and the default options. */
public constructor(pattern: String) : this(pattern, emptySet())
public actual constructor(pattern: String) : this(pattern, emptySet())
/** The pattern string of this regular expression. */
public val pattern: String = pattern
public actual val pattern: String = pattern
/** The set of options that were used to create this regular expression. */
public val options: Set<RegexOption> = options.toSet()
public actual val options: Set<RegexOption> = options.toSet()
private val nativePattern: RegExp = RegExp(pattern, options.map { it.value }.joinToString(separator = "") + "g")
/** Indicates whether the regular expression matches the entire [input]. */
public infix fun matches(input: CharSequence): Boolean {
public actual infix fun matches(input: CharSequence): Boolean {
nativePattern.reset()
val match = nativePattern.exec(input.toString())
return match != null && match.index == 0 && nativePattern.lastIndex == input.length
}
/** Indicates whether the regular expression can find at least one match in the specified [input]. */
public fun containsMatchIn(input: CharSequence): Boolean {
public actual fun containsMatchIn(input: CharSequence): Boolean {
nativePattern.reset()
return nativePattern.test(input.toString())
}
@@ -76,18 +76,18 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
* @param startIndex An index to start search with, by default 0. Must be not less than zero and not greater than `input.length()`
* @return An instance of [MatchResult] if match was found or `null` otherwise.
*/
public fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.findNext(input.toString(), startIndex)
public actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.findNext(input.toString(), startIndex)
/** Returns a sequence of all occurrences of a regular expression within the [input] string, beginning at the specified [startIndex].
*/
public fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = generateSequence({ find(input, startIndex) }, { match -> match.next() })
public actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = generateSequence({ find(input, startIndex) }, { match -> match.next() })
/**
* Attempts to match the entire [input] CharSequence against the pattern.
*
* @return An instance of [MatchResult] if the entire input matches or `null` otherwise.
*/
public fun matchEntire(input: CharSequence): MatchResult? {
public actual fun matchEntire(input: CharSequence): MatchResult? {
if (pattern.startsWith('^') && pattern.endsWith('$'))
return find(input)
else
@@ -99,14 +99,14 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
*
* @param replacement A replacement expression that can include substitutions. See [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace] for details.
*/
public fun replace(input: CharSequence, replacement: String): String = input.toString().nativeReplace(nativePattern, replacement)
public actual fun replace(input: CharSequence, replacement: String): String = input.toString().nativeReplace(nativePattern, replacement)
/**
* Replaces all occurrences of this regular expression in the specified [input] string with the result of
* the given function [transform] that takes [MatchResult] and returns a string to be used as a
* replacement for that match.
*/
public inline fun replace(input: CharSequence, transform: (MatchResult) -> CharSequence): String {
public actual inline fun replace(input: CharSequence, transform: (MatchResult) -> CharSequence): String {
var match = find(input)
if (match == null) return input.toString()
@@ -134,7 +134,7 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
*
* @param replacement A replacement expression that can include substitutions. See [Matcher.appendReplacement] for details.
*/
public fun replaceFirst(input: CharSequence, replacement: String): String {
public actual fun replaceFirst(input: CharSequence, replacement: String): String {
val nonGlobalOptions = options.map { it.value }.joinToString(separator = "")
return input.toString().nativeReplace(RegExp(pattern, nonGlobalOptions), replacement)
}
@@ -144,7 +144,7 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
*
* @param limit The maximum number of times the split can occur.
*/
public 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" }
val matches = findAll(input).let { if (limit == 0) it else it.take(limit - 1) }
val result = mutableListOf<String>()
@@ -161,15 +161,15 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
/** Returns the string representation of this regular expression. */
public override fun toString(): String = nativePattern.toString()
companion object {
actual companion object {
/** Returns a literal regex for the specified [literal] string. */
public fun fromLiteral(literal: String): Regex = Regex(escape(literal))
public actual fun fromLiteral(literal: String): Regex = Regex(escape(literal))
/** Returns a literal pattern for the specified [literal] string. */
public fun escape(literal: String): String = literal.nativeReplace(patternEscape, "\\$&")
public actual fun escape(literal: String): String = literal.nativeReplace(patternEscape, "\\$&")
/** Returns a literal replacement exression for the specified [literal] string. */
public fun escapeReplacement(literal: String): String = literal.nativeReplace(replacementEscape, "$$$$")
public actual fun escapeReplacement(literal: String): String = literal.nativeReplace(replacementEscape, "$$$$")
private val patternEscape = RegExp("""[-\\^$*+?.()|[\]{}]""", "g")
private val replacementEscape = RegExp("""\$""", "g")
+2 -2
View File
@@ -16,10 +16,10 @@
package kotlin.sequences
internal class ConstrainedOnceSequence<T>(sequence: Sequence<T>) : Sequence<T> {
internal actual class ConstrainedOnceSequence<T> actual constructor(sequence: Sequence<T>) : Sequence<T> {
private var sequenceRef: Sequence<T>? = sequence
override fun iterator(): Iterator<T> {
actual override fun iterator(): Iterator<T> {
val sequence = sequenceRef ?: throw IllegalStateException("This sequence can be consumed only once.")
sequenceRef = null
return sequence.iterator()
+6 -6
View File
@@ -3,16 +3,16 @@ package kotlin.text
import kotlin.js.RegExp
@kotlin.internal.InlineOnly
public inline fun String.toUpperCase(): String = asDynamic().toUpperCase()
public actual inline fun String.toUpperCase(): String = asDynamic().toUpperCase()
@kotlin.internal.InlineOnly
public inline fun String.toLowerCase(): String = asDynamic().toLowerCase()
public actual inline fun String.toLowerCase(): String = asDynamic().toLowerCase()
@kotlin.internal.InlineOnly
internal inline fun String.nativeIndexOf(str: String, fromIndex: Int): Int = asDynamic().indexOf(str, fromIndex)
internal actual inline fun String.nativeIndexOf(str: String, fromIndex: Int): Int = asDynamic().indexOf(str, fromIndex)
@kotlin.internal.InlineOnly
internal inline fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = asDynamic().lastIndexOf(str, fromIndex)
internal actual inline fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = asDynamic().lastIndexOf(str, fromIndex)
@kotlin.internal.InlineOnly
internal inline fun String.nativeStartsWith(s: String, position: Int): Boolean = asDynamic().startsWith(s, position)
@@ -21,10 +21,10 @@ internal inline fun String.nativeStartsWith(s: String, position: Int): Boolean =
internal inline fun String.nativeEndsWith(s: String): Boolean = asDynamic().endsWith(s)
@kotlin.internal.InlineOnly
public inline fun String.substring(startIndex: Int): String = asDynamic().substring(startIndex)
public actual inline fun String.substring(startIndex: Int): String = asDynamic().substring(startIndex)
@kotlin.internal.InlineOnly
public inline fun String.substring(startIndex: Int, endIndex: Int): String = asDynamic().substring(startIndex, endIndex)
public actual inline fun String.substring(startIndex: Int, endIndex: Int): String = asDynamic().substring(startIndex, endIndex)
@kotlin.internal.InlineOnly
public inline fun String.concat(str: String): String = asDynamic().concat(str)
+12 -12
View File
@@ -3,9 +3,9 @@ package kotlin.text
import kotlin.js.RegExp
@kotlin.internal.InlineOnly
internal inline fun String.nativeIndexOf(ch: Char, fromIndex: Int): Int = nativeIndexOf(ch.toString(), fromIndex)
internal actual inline fun String.nativeIndexOf(ch: Char, fromIndex: Int): Int = nativeIndexOf(ch.toString(), fromIndex)
@kotlin.internal.InlineOnly
internal inline fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = nativeLastIndexOf(ch.toString(), fromIndex)
internal actual inline fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = nativeLastIndexOf(ch.toString(), fromIndex)
/**
* Returns `true` if this string starts with the specified prefix.
@@ -44,9 +44,9 @@ public fun String.matches(regex: String): Boolean {
return result != null && result.size != 0
}
public fun CharSequence.isBlank(): Boolean = length == 0 || (if (this is String) this else this.toString()).matches("^[\\s\\xA0]+$")
public actual fun CharSequence.isBlank(): Boolean = length == 0 || (if (this is String) this else this.toString()).matches("^[\\s\\xA0]+$")
public fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean =
public actual fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean =
if (this == null)
other == null
else if (!ignoreCase)
@@ -55,7 +55,7 @@ public fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean
other != null && this.toLowerCase() == other.toLowerCase()
public fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean
public actual fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean
= regionMatchesImpl(thisOffset, other, otherOffset, length, ignoreCase)
@@ -64,7 +64,7 @@ public fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, othe
*
* @includeFunctionBody ../../test/StringTest.kt capitalize
*/
public fun String.capitalize(): String {
public actual fun String.capitalize(): String {
return if (isNotEmpty()) substring(0, 1).toUpperCase() + substring(1) else this
}
@@ -73,7 +73,7 @@ public fun String.capitalize(): String {
*
* @includeFunctionBody ../../test/StringTest.kt decapitalize
*/
public fun String.decapitalize(): String {
public actual fun String.decapitalize(): String {
return if (isNotEmpty()) substring(0, 1).toLowerCase() + substring(1) else this
}
@@ -81,7 +81,7 @@ public fun String.decapitalize(): String {
* Returns a string containing this char sequence repeated [n] times.
* @throws [IllegalArgumentException] when n < 0.
*/
public 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." }
return when (n) {
0 -> ""
@@ -107,14 +107,14 @@ public fun CharSequence.repeat(n: Int): String {
}
}
public fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String =
public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String =
nativeReplace(RegExp(Regex.escape(oldValue), if (ignoreCase) "gi" else "g"), Regex.escapeReplacement(newValue))
public fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String =
public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String =
nativeReplace(RegExp(Regex.escape(oldChar.toString()), if (ignoreCase) "gi" else "g"), newChar.toString())
public fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean = false): String =
public actual fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean = false): String =
nativeReplace(RegExp(Regex.escape(oldValue), if (ignoreCase) "i" else ""), Regex.escapeReplacement(newValue))
public fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String =
public actual fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String =
nativeReplace(RegExp(Regex.escape(oldChar.toString()), if (ignoreCase) "i" else ""), newChar.toString())
+17 -15
View File
@@ -17,47 +17,49 @@
package kotlin.text
public interface Appendable {
fun append(csq: CharSequence?): Appendable
fun append(csq: CharSequence?, start: Int, end: Int): Appendable
fun append(c: Char): Appendable
public actual interface Appendable {
public actual fun append(csq: CharSequence?): Appendable
public actual fun append(csq: CharSequence?, start: Int, end: Int): Appendable
public actual fun append(c: Char): Appendable
}
public class StringBuilder(content: String = "") : Appendable, CharSequence {
constructor(@Suppress("UNUSED_PARAMETER") capacity: Int) : this() {}
public actual class StringBuilder(content: String) : Appendable, CharSequence {
actual constructor(@Suppress("UNUSED_PARAMETER") capacity: Int) : this() {}
constructor(content: CharSequence) : this(content.toString()) {}
actual constructor(content: CharSequence) : this(content.toString()) {}
actual constructor() : this("")
private var string: String = content
override val length: Int
actual override val length: Int
get() = string.asDynamic().length
override fun get(index: Int): Char = string[index]
actual override fun get(index: Int): Char = string[index]
override fun subSequence(start: Int, end: Int): CharSequence = string.substring(start, end)
actual override fun subSequence(startIndex: Int, endIndex: Int): CharSequence = string.substring(startIndex, endIndex)
override fun append(c: Char): StringBuilder {
actual override fun append(c: Char): StringBuilder {
string += c
return this
}
override fun append(csq: CharSequence?): StringBuilder {
actual override fun append(csq: CharSequence?): StringBuilder {
string += csq.toString()
return this
}
override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder {
actual override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder {
string += csq.toString().substring(start, end)
return this
}
fun append(obj: Any?): StringBuilder {
actual fun append(obj: Any?): StringBuilder {
string += obj.toString()
return this
}
fun reverse(): StringBuilder {
actual fun reverse(): StringBuilder {
string = string.asDynamic().split("").reverse().join("")
return this
}