Text And Data

std.ascii

ASCII byte predicates, case conversion, and digit value helpers.

When To Use std.ascii

In Zerolang, use std.ascii when a program needs byte-level ASCII predicates, case conversion, or digit values without Unicode normalization.

Runnable today:

APIReturnNotes
std.ascii.isDigit(byte)BoolChecks 0 through 9.
std.ascii.isAlpha(byte)BoolChecks A through Z or a through z.
std.ascii.isAlnum(byte)BoolChecks ASCII alphabetic or digit bytes.
std.ascii.isWhitespace(byte)BoolChecks space, tab, line feed, and carriage return.
std.ascii.isLower(byte) / std.ascii.isUpper(byte)BoolChecks ASCII case ranges.
std.ascii.isHexDigit(byte)BoolChecks decimal digits and a-f / A-F.
std.ascii.toLower(byte) / std.ascii.toUpper(byte)u8Converts ASCII letters and leaves other bytes unchanged.
std.ascii.digitValue(byte)Maybe<u8>Converts an ASCII decimal digit to 0..9.
std.ascii.hexValue(byte)Maybe<u8>Converts an ASCII hexadecimal digit to 0..15.

Example

pub fn main(world: World) -> Void raises {    let digit: Maybe<u8> = std.ascii.digitValue(55_u8)    let hex: Maybe<u8> = std.ascii.hexValue(70_u8)    if std.ascii.isAlpha(65_u8) && std.ascii.toLower(90_u8) == 122_u8 && digit.has && digit.value == 7_u8 && hex.has && hex.value == 15_u8 {        check world.out.write("ascii ok\n")    }}

Effects: none.

Allocation behavior: no allocation.

Error behavior: value helpers return null when the byte is outside the accepted range.

Target support: current compiler targets.