March Docs

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

fndigit_valuedigit_value(c : String) : Int#

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")
9
fndigit_value_optdigit_value_opt(c : String) : Option(Int)#

Returns 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")
None
fnfrom_intfrom_int(n : Int) : String#

Returns 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"
fnhex_digit_valuehex_digit_value(c : String) : Int#

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")
3
fnhex_digit_value_opthex_digit_value_opt(c : String) : Option(Int)#

Returns 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")
None
fnis_alphais_alpha(c : String) : Bool#

Returns true if c is an ASCII letter (a-z or A-Z).

Examples

march> Char.is_alpha("q")
true
march> Char.is_alpha("1")
false
fnis_alphanumericis_alphanumeric(c : String) : Bool#

Returns 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("_")
false
fnis_asciiis_ascii(c : String) : Bool#

Returns true if c is an ASCII byte (0-127).

Examples

march> Char.is_ascii("~")
true
march> Char.is_ascii(Char.from_int(200))
false
fnis_digitis_digit(c : String) : Bool#

Returns true if c is an ASCII digit (0-9).

Examples

march> Char.is_digit("7")
true
march> Char.is_digit("x")
false
fnis_hex_digitis_hex_digit(c : String) : Bool#

Returns 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")
false
fnis_loweris_lower(c : String) : Bool#

Returns true if c is an ASCII lowercase letter (a-z).

Examples

march> Char.is_lower("a")
true
march> Char.is_lower("1")
false
fnis_printableis_printable(c : String) : Bool#

Returns 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")
false
fnis_upperis_upper(c : String) : Bool#

Returns true if c is an ASCII uppercase letter (A-Z).

Examples

march> Char.is_upper("A")
true
march> Char.is_upper("a")
false
fnis_whitespaceis_whitespace(c : String) : Bool#

Returns 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")
false
fnto_intto_int(c : String) : Int#

Returns 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")
48
fnto_lowerto_lower(c : String) : String#

Converts an ASCII uppercase letter to lowercase. Any other char is returned unchanged.

Examples

march> Char.to_lower("Q")
"q"
march> Char.to_lower("!")
"!"
fnto_stringto_string(c : String) : String#

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"
fnto_upperto_upper(c : String) : String#

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"