Scoop API

scoop:scoop.std:0.1.0

src/text/unsigned_text.scoop

Selected production source · src/text/unsigned_text.scoop

1package scoop.text
3import scoop.map
5/**
6 * Parses a UByte in radix 2..36, returning None for invalid digits or out-of-range values. An
7 * invalid radix throws IllegalArgumentException.
8 */
9public 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 an
14 * invalid radix throws IllegalArgumentException.
15 */
16public 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. An
20 * invalid radix throws IllegalArgumentException.
21 */
22public 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 an
27 * invalid radix throws IllegalArgumentException.
28 */
29public 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. An
33 * invalid radix throws IllegalArgumentException.
34 */
35public 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 an
40 * invalid radix throws IllegalArgumentException.
41 */
42public 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. An
46 * invalid radix throws IllegalArgumentException.
47 */
48public 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 an
53 * invalid radix throws IllegalArgumentException.
54 */
55public fun String.toULong(radix: Int = 10): ULong = requireParsedNumber<ULong>(toULongOrNone(radix))