Lyric v2.11.0

std.string

concat function

pub fn concat(a: string, b: string): string

The two joined — what + on strings compiles to.

stdlib/std/string.lyr:15

fromInt function

pub fn fromInt(value: int): string

The decimal text of the value.

stdlib/std/string.lyr:18

fromUint function

pub fn fromUint(value: uint): string

The decimal text of an unsigned value.

stdlib/std/string.lyr:23

fromFloat function

pub fn fromFloat(value: float): string

The decimal text of the value.

stdlib/std/string.lyr:25

fromBool function

pub fn fromBool(value: bool): string

"true" or "false".

stdlib/std/string.lyr:27

fromChar function

pub fn fromChar(value: char): string

The character as a one-character string.

stdlib/std/string.lyr:29

repeat function

pub fn repeat(value: string, count: int): string

The string repeated count times — what s * n compiles to.

stdlib/std/string.lyr:34

fromChars function

pub fn fromChars(chars: char[]): string

The characters joined back into one string — the inverse of toChars. Native since v1.14: one call instead of one string per character.

stdlib/std/string.lyr:46

utf8Decode function

pub fn utf8Decode(bytes: uint8[]): ?string

The bytes as a string, STRICTLY: invalid UTF-8 answers null rather than a U+FFFD quietly standing in for the data — the difference to readText, whose replacement decoding is documented there.

stdlib/std/string.lyr:56

isDigit function

pub fn isDigit(c: char): bool

'0' through '9'.

stdlib/std/string.lyr:365

isAlpha function

pub fn isAlpha(c: char): bool

An ASCII letter.

stdlib/std/string.lyr:371

isAlphanumeric function

pub fn isAlphanumeric(c: char): bool

An ASCII letter or a digit.

stdlib/std/string.lyr:376

isWhitespace function

pub fn isWhitespace(c: char): bool

Space, tab, \n or \r.

stdlib/std/string.lyr:381

isUpper function

pub fn isUpper(c: char): bool

'A' through 'Z'.

stdlib/std/string.lyr:386

isLower function

pub fn isLower(c: char): bool

'a' through 'z'.

stdlib/std/string.lyr:391

charToDigit function

pub fn charToDigit(c: char): ?int

The numeric value of a digit, or null when it is not one.

?int rather than -1: a failure the caller has to handle belongs in the type.

stdlib/std/string.lyr:398

digitToChar function

pub fn digitToChar(value: int): ?char

The digit as a character, or null outside 0..9.

stdlib/std/string.lyr:406

join function

pub fn join(parts: string[], separator: string): string

Joins the parts with a separator: the inverse of split. One native call — a left fold would copy the whole result once per part.

stdlib/std/string.lyr:433

parseInt function

pub fn parseInt(value: string): ?int

"-42" becomes -42, anything else null.

No overflow protection: a number beyond int64 wraps rather than yielding null. Detecting it would need a division per digit.

stdlib/std/string.lyr:448

parseIntRadix function

pub fn parseIntRadix(value: string, radix: int): ?int

From a base of 2 to 36. Letters continue from a/A.

stdlib/std/string.lyr:482

parseBool function

pub fn parseBool(value: string): ?bool

Exactly "true" or "false"; anything else is null.

stdlib/std/string.lyr:527

parseFloat function

pub fn parseFloat(value: string): ?float

"3.5", "-0.25" and "42" become floating point; everything else is null.

Without exponent notation (1e9), which would need a state machine of its own.

stdlib/std/string.lyr:540

StringBuilder class

pub class StringBuilder

Builds a string piece by piece.

s = s + part in a loop is quadratic: every step copies the whole string so far. The builder collects the parts and joins them once.

The backing is a doubling string[], written by hand because this module must not import std.collections.

parts: string[]

The collected pieces; count says how many are filled.

count: int

How many entries of parts are real.

pub static fn new(): StringBuilder

An empty builder.

pub mut fn append(value: string): void

Adds a piece; the backing array doubles when full.

pub mut fn appendLine(value: string): void

Adds the piece and a \n.

pub mut fn appendChar(value: char): void

Adds one character.

pub fn build(): string

The pieces joined once — the point of collecting them. One native call over the filled slice; a left fold would copy the whole result once per piece, the exact cost the builder exists to avoid. Reads and never consumes: building twice yields the same string.

stdlib/std/string.lyr:604