scoop:scoop.std:0.1.0
src/text/unsigned_text.scoop
Selected production source · src/text/unsigned_text.scoop
1
package scoop.text3
import scoop.map5
/**6
* Parses a UByte in radix 2..36, returning None for invalid digits or out-of-range values. An7
* invalid radix throws IllegalArgumentException.8
*/9
public fun String.toUByteOrNone(radix: Int = 10): UByte? =10
parseUnsignedInteger(this, radix, UInt8.MAX_VALUE.toULong()).map<ULong, UInt8> { value -> value.toUByte() }12
/**13
* Parses a UByte in radix 2..36; invalid or out-of-range text throws NumberFormatException and an14
* invalid radix throws IllegalArgumentException.15
*/16
public fun String.toUByte(radix: Int = 10): UByte = requireParsedNumber<UInt8>(toUByteOrNone(radix))18
/**19
* Parses a UShort in radix 2..36, returning None for invalid digits or out-of-range values. An20
* invalid radix throws IllegalArgumentException.21
*/22
public fun String.toUShortOrNone(radix: Int = 10): UShort? =23
parseUnsignedInteger(this, radix, UInt16.MAX_VALUE.toULong()).map<ULong, UInt16> { value -> value.toUShort() }25
/**26
* Parses a UShort in radix 2..36; invalid or out-of-range text throws NumberFormatException and an27
* invalid radix throws IllegalArgumentException.28
*/29
public fun String.toUShort(radix: Int = 10): UShort = requireParsedNumber<UInt16>(toUShortOrNone(radix))31
/**32
* Parses a UInt in radix 2..36, returning None for invalid digits or out-of-range values. An33
* invalid radix throws IllegalArgumentException.34
*/35
public fun String.toUIntOrNone(radix: Int = 10): UInt? =36
parseUnsignedInteger(this, radix, UInt.MAX_VALUE.toULong()).map<ULong, UInt> { value -> value.toUInt() }38
/**39
* Parses a UInt in radix 2..36; invalid or out-of-range text throws NumberFormatException and an40
* invalid radix throws IllegalArgumentException.41
*/42
public fun String.toUInt(radix: Int = 10): UInt = requireParsedNumber<UInt>(toUIntOrNone(radix))44
/**45
* Parses a ULong in radix 2..36, returning None for invalid digits or out-of-range values. An46
* invalid radix throws IllegalArgumentException.47
*/48
public fun String.toULongOrNone(radix: Int = 10): ULong? =49
parseUnsignedInteger(this, radix, ULong.MAX_VALUE.toULong()).map<ULong, ULong> { value -> value.toULong() }51
/**52
* Parses a ULong in radix 2..36; invalid or out-of-range text throws NumberFormatException and an53
* invalid radix throws IllegalArgumentException.54
*/55
public fun String.toULong(radix: Int = 10): ULong = requireParsedNumber<ULong>(toULongOrNone(radix))