encoding::utf8+x86_64 +linux

encoding::utf8 provides helper functions for working with runes, strings, and UTF-8-encoded slices.

Index

Types

type more = void;

// Undocumented types:
type decoder = struct {
	offs: size,
	src: []u8,
};

Errors

type invalid = !void;

Functions

fn decode(src: []u8) decoder;
fn encoderune(r: rune) []u8;
fn next(d: *decoder) (rune | done | more | invalid);
fn prev(d: *decoder) (rune | done | more | invalid);
fn runesz(r: rune) size;
fn strerror(err: invalid) str;
fn utf8sz(c: u8) (size | invalid);
fn validate(src: []u8) (void | invalid);

Types

type more[link]

type more = void;

Returned when more data is needed, i.e. when an incomplete UTF-8 sequence is encountered.

type decoder[link]

Show undocumented member
type decoder = struct {
	offs: size,
	src: []u8,
};

Errors

type invalid[link]

type invalid = !void;

Returned when an invalid UTF-8 sequence was found.

Functions

fn decode[link]

fn decode(src: []u8) decoder;

Initializes a new UTF-8 decoder.

fn encoderune[link]

fn encoderune(r: rune) []u8;

Encodes a rune as UTF-8 and returns the result as a slice. The return value is statically allocated, and will not be consistent after subsequent calls to encoderune.

fn next[link]

fn next(d: *decoder) (rune | done | more | invalid);

Returns the next rune from a decoder. done is returned when there are no remaining codepoints.

fn prev[link]

fn prev(d: *decoder) (rune | done | more | invalid);

Returns the previous rune from a decoder. done is returned when there are no previous codepoints.

fn runesz[link]

fn runesz(r: rune) size;

Returns the size of a rune, in octets, when encoded as UTF-8.

fn strerror[link]

fn strerror(err: invalid) str;

Converts an error into a human-friendly string.

fn utf8sz[link]

fn utf8sz(c: u8) (size | invalid);

Returns the expected length of a UTF-8 codepoint in bytes given its first byte, or invalid if the given byte doesn't begin a valid UTF-8 sequence.

fn validate[link]

fn validate(src: []u8) (void | invalid);

Returns void if a given byte slice contains only valid UTF-8 sequences, otherwise returns invalid.