Rename ByteArray getters

This commit is contained in:
Pavel Punegov
2018-09-28 16:15:47 +03:00
committed by Pavel Punegov
parent 5d1c1c89a6
commit 366bb0c5e6
3 changed files with 23 additions and 23 deletions
@@ -12,13 +12,13 @@ import kotlin.test.*
val array = ByteArray(42) val array = ByteArray(42)
array.setLongAt(5, 0x1234_5678_9abc_def0) array.setLongAt(5, 0x1234_5678_9abc_def0)
expect(0xdef0.toInt()) { array.charAt(5).toInt() } expect(0xdef0.toInt()) { array.getCharAt(5).toInt() }
expect(0x9abc.toShort()) { array.shortAt(7) } expect(0x9abc.toShort()) { array.getShortAt(7) }
expect(0x1234_5678) { array.intAt(9) } expect(0x1234_5678) { array.getIntAt(9) }
expect(0xdef0_0000u) { array.uintAt(3) } expect(0xdef0_0000u) { array.getUIntAt(3) }
expect(0xf0_00u) { array.ushortAt(4) } expect(0xf0_00u) { array.getUShortAt(4) }
expect(0xf0u) { array.ubyteAt(5) } expect(0xf0u) { array.getUByteAt(5) }
expect(0x1234_5678_9abcuL) { array.ulongAt(7) } expect(0x1234_5678_9abcuL) { array.getULongAt(7) }
println("OK") println("OK")
} }
@@ -12,32 +12,32 @@ import kotlin.test.*
val results = mutableSetOf<Any>() val results = mutableSetOf<Any>()
var counter = 0 var counter = 0
try { try {
results += array.shortAt(16) results += array.getShortAt(16)
} catch (e: ArrayIndexOutOfBoundsException) { } catch (e: ArrayIndexOutOfBoundsException) {
counter++ counter++
} }
try { try {
results += array.charAt(22) results += array.getCharAt(22)
} catch (e: ArrayIndexOutOfBoundsException) { } catch (e: ArrayIndexOutOfBoundsException) {
counter++ counter++
} }
try { try {
results += array.intAt(15) results += array.getIntAt(15)
} catch (e: ArrayIndexOutOfBoundsException) { } catch (e: ArrayIndexOutOfBoundsException) {
counter++ counter++
} }
try { try {
results += array.longAt(14) results += array.getLongAt(14)
} catch (e: ArrayIndexOutOfBoundsException) { } catch (e: ArrayIndexOutOfBoundsException) {
counter++ counter++
} }
try { try {
results += array.floatAt(14) results += array.getFloatAt(14)
} catch (e: ArrayIndexOutOfBoundsException) { } catch (e: ArrayIndexOutOfBoundsException) {
counter++ counter++
} }
try { try {
results += array.doubleAt(13) results += array.getDoubleAt(13)
} catch (e: ArrayIndexOutOfBoundsException) { } catch (e: ArrayIndexOutOfBoundsException) {
counter++ counter++
} }
@@ -17,21 +17,21 @@ import kotlin.native.SymbolName
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries. * @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
*/ */
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public fun ByteArray.ubyteAt(index: Int): UByte = UByte(get(index)) public fun ByteArray.getUByteAt(index: Int): UByte = UByte(get(index))
/** /**
* Gets [Char] out of the [ByteArray] byte buffer at specified index [index] * Gets [Char] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries. * @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
*/ */
@SymbolName("Kotlin_ByteArray_getCharAt") @SymbolName("Kotlin_ByteArray_getCharAt")
public external fun ByteArray.charAt(index: Int): Char public external fun ByteArray.getCharAt(index: Int): Char
/** /**
* Gets [Short] out of the [ByteArray] byte buffer at specified index [index] * Gets [Short] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries. * @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
*/ */
@SymbolName("Kotlin_ByteArray_getShortAt") @SymbolName("Kotlin_ByteArray_getShortAt")
public external fun ByteArray.shortAt(index: Int): Short public external fun ByteArray.getShortAt(index: Int): Short
/** /**
* Gets [UShort] out of the [ByteArray] byte buffer at specified index [index] * Gets [UShort] out of the [ByteArray] byte buffer at specified index [index]
@@ -39,14 +39,14 @@ public external fun ByteArray.shortAt(index: Int): Short
*/ */
@SymbolName("Kotlin_ByteArray_getShortAt") @SymbolName("Kotlin_ByteArray_getShortAt")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public external fun ByteArray.ushortAt(index: Int): UShort public external fun ByteArray.getUShortAt(index: Int): UShort
/** /**
* Gets [Int] out of the [ByteArray] byte buffer at specified index [index] * Gets [Int] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries. * @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
*/ */
@SymbolName("Kotlin_ByteArray_getIntAt") @SymbolName("Kotlin_ByteArray_getIntAt")
public external fun ByteArray.intAt(index: Int): Int public external fun ByteArray.getIntAt(index: Int): Int
/** /**
* Gets [UInt] out of the [ByteArray] byte buffer at specified index [index] * Gets [UInt] out of the [ByteArray] byte buffer at specified index [index]
@@ -54,14 +54,14 @@ public external fun ByteArray.intAt(index: Int): Int
*/ */
@SymbolName("Kotlin_ByteArray_getIntAt") @SymbolName("Kotlin_ByteArray_getIntAt")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public external fun ByteArray.uintAt(index: Int): UInt public external fun ByteArray.getUIntAt(index: Int): UInt
/** /**
* Gets [Long] out of the [ByteArray] byte buffer at specified index [index] * Gets [Long] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries. * @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
*/ */
@SymbolName("Kotlin_ByteArray_getLongAt") @SymbolName("Kotlin_ByteArray_getLongAt")
public external fun ByteArray.longAt(index: Int): Long public external fun ByteArray.getLongAt(index: Int): Long
/** /**
* Gets [ULong] out of the [ByteArray] byte buffer at specified index [index] * Gets [ULong] out of the [ByteArray] byte buffer at specified index [index]
@@ -69,21 +69,21 @@ public external fun ByteArray.longAt(index: Int): Long
*/ */
@SymbolName("Kotlin_ByteArray_getLongAt") @SymbolName("Kotlin_ByteArray_getLongAt")
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
public external fun ByteArray.ulongAt(index: Int): ULong public external fun ByteArray.getULongAt(index: Int): ULong
/** /**
* Gets [Float] out of the [ByteArray] byte buffer at specified index [index] * Gets [Float] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries. * @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
*/ */
@SymbolName("Kotlin_ByteArray_getFloatAt") @SymbolName("Kotlin_ByteArray_getFloatAt")
public external fun ByteArray.floatAt(index: Int): Float public external fun ByteArray.getFloatAt(index: Int): Float
/** /**
* Gets [Double] out of the [ByteArray] byte buffer at specified index [index] * Gets [Double] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries. * @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
*/ */
@SymbolName("Kotlin_ByteArray_getDoubleAt") @SymbolName("Kotlin_ByteArray_getDoubleAt")
public external fun ByteArray.doubleAt(index: Int): Double public external fun ByteArray.getDoubleAt(index: Int): Double
/** /**
* Sets [UByte] out of the [ByteArray] byte buffer at specified index [index] * Sets [UByte] out of the [ByteArray] byte buffer at specified index [index]