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 std.io.file.text, whose replacement decoding is
documented there.
stdlib/std/string.lyr:56
Utf8Error class
pub class Utf8Error :: [Throwable]
Where a byte sequence stopped being UTF-8: the 0-based offset of the byte that broke it.
offset: int
pub fn message(): string
stdlib/std/string.lyr:59
utf8DecodeOrThrow function
pub fn utf8DecodeOrThrow(bytes: uint8[]): string throws Utf8Error
utf8Decode, with the reason when the bytes are not UTF-8: which byte broke the sequence.
stdlib/std/string.lyr:72
isDigit function
pub fn isDigit(c: char): bool
'0' through '9'.
stdlib/std/string.lyr:387
isAlpha function
pub fn isAlpha(c: char): bool
An ASCII letter.
stdlib/std/string.lyr:393
isAlphanumeric function
pub fn isAlphanumeric(c: char): bool
An ASCII letter or a digit.
stdlib/std/string.lyr:398
isWhitespace function
pub fn isWhitespace(c: char): bool
Space, tab, \n or \r.
stdlib/std/string.lyr:403
isUpper function
pub fn isUpper(c: char): bool
'A' through 'Z'.
stdlib/std/string.lyr:408
isLower function
pub fn isLower(c: char): bool
'a' through 'z'.
stdlib/std/string.lyr:413
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:420
digitToChar function
pub fn digitToChar(value: int): ?char
The digit as a character, or null outside 0..9.
stdlib/std/string.lyr:428
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:455
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:470
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:504
parseBool function
pub fn parseBool(value: string): ?bool
Exactly "true" or "false"; anything else is null.
stdlib/std/string.lyr:549
parseFloat function
pub fn parseFloat(value: string): ?float
The closest float to the decimal the text spells — "3.5", "-0.25", ".5", "42",
exponent notation included ("1e-6", "2.5E3") — or null when the text spells none.
Strict about shape: no whitespace, no separators, and the words NaN and Infinity are not
numbers. A magnitude beyond the type rounds to the infinities, as IEEE 754 prescribes.
Native because the conversion is CORRECTLY ROUNDED, which needs arbitrary-precision
arithmetic in the worst cases; an approximate parser hands back a float the text did not
say. parseFloat(fromFloat(x)) is x again, for every finite x.
stdlib/std/string.lyr:567
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:578