Byte
import "std/types" (included in import "std") · namespace std.types
Indexing a string gives a byte (s[i]). Byte holds the ASCII tests and case changes for them, as methods of any byte (which also has Integer's).
grav
import "std"
fn main() {
let s = "a1 B"
print("${s[0].isLetter()} ${s[1].isDigit()} ${s[2].isSpace()} ${s[3].isUpper()}")
print(s[0].toUpper().toChar() + " " + s[3].toLower().toChar() + " " + s[0].toHex())
print("f"[0].digitValue())
}true true true true
A b 61
15The tests are ASCII only: the bytes of other UTF-8 characters are none of them.
API
class Byte
Bytes (see the top of this file).
Static members
static readonly MAX: int = 255static readonly MIN: int = 0static fn isDigit(b: byte) -> bool— ASCII tests (false for bytes of other UTF-8 characters).static fn isLetter(b: byte) -> boolstatic fn isLetterOrDigit(b: byte) -> boolstatic fn isUpper(b: byte) -> boolstatic fn isLower(b: byte) -> boolstatic fn isSpace(b: byte) -> bool— A space, tab, newline, carriage return, vertical tab or form feed.static fn isHexDigit(b: byte) -> boolstatic fn isPunctuation(b: byte) -> boolstatic fn isAscii(b: byte) -> bool— Below 128: a whole character in itself.static fn toUpper(b: byte) -> byte— The ASCII letter in the other case (other bytes as they are).static fn toLower(b: byte) -> bytestatic fn digitValue(b: byte) -> int— The digit's value: 0..9 for '0'..'9', 10..35 for letters (either case); -1 otherwise.static fn compare(a: byte, b: byte) -> int— Comparators for sorting: by value; and ignoring ASCII case.static fn compareIgnoreCase(a: byte, b: byte) -> intstatic fn toChar(b: byte) -> string— The byte as a one-byte string ("A" for 65).static fn toHex(b: byte) -> string— Two hex digits ("0a", "ff").