Char
Char module: character classification and conversion utilities.
Wraps the built-in char_* primitives for idiomatic use. All predicates return Bool; conversions preserve the char type.
March has no separate Char type or 'c' literal: a "char" here is a one-byte String such as "a". Every function taking a char except to_string expects exactly one byte; the interpreter raises a runtime error for an empty or longer string, while compiled code inspects only the first byte. Classification is ASCII-only.
Functions
Returns the numeric value of a digit character (0-9). Panics if not a digit — use digit_value_opt for the fallible variant when the input may not be a digit.
Examples
march> Char.digit_value("9")
9Returns the numeric value of a digit character (0-9) as Some(n), or None if c is not an ASCII digit. Prefer this safe variant when the input comes from user data (file, network, form) — it's the "lookup-miss → Option" arm of the stdlib error-signaling policy.
Examples
march> Char.digit_value_opt("7")
Some(7)
march> Char.digit_value_opt("x")
NoneReturns the one-byte string for byte value n, taken modulo 256 (so 256 yields byte 0, and -1 yields byte 255). A byte, not a code point: use String.from_codepoint to build a Unicode character.
Examples
march> Char.from_int(97)
"a"
march> Char.from_int(353)
"a"Returns the hex value of a hex digit (0-9, a-f, A-F). Panics if not a hex digit — use hex_digit_value_opt when the input might not be hex.
Examples
march> Char.hex_digit_value("B")
11
march> Char.hex_digit_value("3")
3Returns the hex value of a hex digit (0-9, a-f, A-F) as Some(n), or None if c is not a hex digit. Safe variant for parsing untrusted hex strings. Upper and lower case letters give the same value.
Examples
march> Char.hex_digit_value_opt("f")
Some(15)
march> Char.hex_digit_value_opt("A")
Some(10)
march> Char.hex_digit_value_opt("g")
NoneReturns true if c is an ASCII letter (a-z or A-Z).
Examples
march> Char.is_alpha("q")
true
march> Char.is_alpha("1")
falseReturns true if c is an ASCII letter or digit. Underscore and other punctuation are not alphanumeric.
Examples
march> Char.is_alphanumeric("Z")
true
march> Char.is_alphanumeric("_")
falseReturns true if c is an ASCII byte (0-127).
Examples
march> Char.is_ascii("~")
true
march> Char.is_ascii(Char.from_int(200))
falseReturns true if c is an ASCII digit (0-9).
Examples
march> Char.is_digit("7")
true
march> Char.is_digit("x")
falseReturns true if c is a hex digit (0-9, a-f, A-F).
Examples
march> Char.is_hex_digit("e")
true
march> Char.is_hex_digit("x")
falseReturns true if c is an ASCII lowercase letter (a-z).
Examples
march> Char.is_lower("a")
true
march> Char.is_lower("1")
falseReturns true if c is a printable ASCII character (byte 32-126, space included). Control characters such as newline and tab are not printable.
Examples
march> Char.is_printable(" ")
true
march> Char.is_printable("\n")
falseReturns true if c is an ASCII uppercase letter (A-Z).
Examples
march> Char.is_upper("A")
true
march> Char.is_upper("a")
falseReturns true if c is a space, tab, newline or carriage return. Other control characters (form feed, vertical tab) are not whitespace here.
Examples
march> Char.is_whitespace("\t")
true
march> Char.is_whitespace("x")
falseReturns the byte value (0-255) of the one-byte string c. A byte, not a code point: use String.to_codepoints for Unicode text. On an empty or multi-byte string the interpreter raises a runtime error, while compiled code returns the leading byte (0 for "").
Examples
march> Char.to_int("A")
65
march> Char.to_int("0")
48Converts an ASCII uppercase letter to lowercase. Any other char is returned unchanged.
Examples
march> Char.to_lower("Q")
"q"
march> Char.to_lower("!")
"!"Returns c as a String. Since a char already is a String this returns it unchanged (any length; no check that c is a single character).
Examples
march> Char.to_string("x")
"x"Converts an ASCII lowercase letter to uppercase. Any other char is returned unchanged.
Examples
march> Char.to_upper("q")
"Q"
march> Char.to_upper("3")
"3"