std/utf8

March 13, 2026 · View on GitHub

The std/utf8 module provides utilities for working with Unicode code points (rune type) and UTF-8 encoding.

Usage

import "std/utf8.zc"

fn main() {
    let r = 'ñ';
    
    if (Utf8::is_alpha(r)) {
        println "{r} is a letter";
    }
}

Methods

Query & Identification

MethodSignatureDescription
is_digitis_digit(r: rune) -> boolReturns true if the rune is a decimal digit (0-9).
is_alphais_alpha(r: rune) -> boolReturns true if the rune is an alphabetic character.
is_whitespaceis_whitespace(r: rune) -> boolReturns true if the rune is a whitespace character.
is_upperis_upper(r: rune) -> boolReturns true if the rune is an uppercase letter.
is_loweris_lower(r: rune) -> boolReturns true if the rune is a lowercase letter.
is_validis_valid(data: char*, len: usize) -> boolReturns true if the buffer contains valid UTF-8 data.

Transformation

MethodSignatureDescription
to_upperto_upper(r: rune) -> runeReturns the uppercase version of the rune.
to_lowerto_lower(r: rune) -> runeReturns the lowercase version of the rune.

Encoding & Decoding

MethodSignatureDescription
encodeencode(r: rune, buf: char*) -> usizeEncodes a rune into UTF-8. Returns bytes written (1-4).
rune_lenrune_len(r: rune) -> usizeReturns number of bytes required to encode the rune.
decodedecode(data: char*, len: usize, consumed: usize*) -> runeDecodes the first UTF-8 sequence from data.