scoop:scoop.std:0.1.0
src/text/signed_text.scoop
Selected production source · src/text/signed_text.scoop
1
package scoop.text3
import scoop.map5
/**6
* Parses a Byte in radix 2..36, returning None for invalid digits or out-of-range values. An7
* invalid radix throws IllegalArgumentException.8
*/9
public fun String.toByteOrNone(radix: Int = 10): Byte? =10
parseSignedInteger(this, radix, Int8.MAX_VALUE.toULong()).map<Long, Int8> { value -> value.toByte() }12
/**13
* Parses a Byte in radix 2..36; invalid or out-of-range text throws NumberFormatException and an14
* invalid radix throws IllegalArgumentException.15
*/16
public fun String.toByte(radix: Int = 10): Byte = requireParsedNumber<Int8>(toByteOrNone(radix))18
/**19
* Parses a Short in radix 2..36, returning None for invalid digits or out-of-range values. An20
* invalid radix throws IllegalArgumentException.21
*/22
public fun String.toShortOrNone(radix: Int = 10): Short? =23
parseSignedInteger(this, radix, Int16.MAX_VALUE.toULong()).map<Long, Int16> { value -> value.toShort() }25
/**26
* Parses a Short in radix 2..36; invalid or out-of-range text throws NumberFormatException and an27
* invalid radix throws IllegalArgumentException.28
*/29
public fun String.toShort(radix: Int = 10): Short = requireParsedNumber<Int16>(toShortOrNone(radix))31
/**32
* Parses a Int in radix 2..36, returning None for invalid digits or out-of-range values. An33
* invalid radix throws IllegalArgumentException.34
*/35
public fun String.toIntOrNone(radix: Int = 10): Int? =36
parseSignedInteger(this, radix, Int.MAX_VALUE.toULong()).map<Long, Int> { value -> value.toInt() }38
/**39
* Parses a Int in radix 2..36; invalid or out-of-range text throws NumberFormatException and an40
* invalid radix throws IllegalArgumentException.41
*/42
public fun String.toInt(radix: Int = 10): Int = requireParsedNumber<Int>(toIntOrNone(radix))44
/**45
* Parses a Long in radix 2..36, returning None for invalid digits or out-of-range values. An46
* invalid radix throws IllegalArgumentException.47
*/48
public fun String.toLongOrNone(radix: Int = 10): Long? =49
parseSignedInteger(this, radix, Long.MAX_VALUE.toULong()).map<Long, Long> { value -> value.toLong() }51
/**52
* Parses a Long in radix 2..36; invalid or out-of-range text throws NumberFormatException and an53
* invalid radix throws IllegalArgumentException.54
*/55
public fun String.toLong(radix: Int = 10): Long = requireParsedNumber<Long>(toLongOrNone(radix))