std.text
std.text: byte strings (`[]u8`, UTF-8 by convention).
Case functions and `trim` know ASCII only. Floats are formatted with C's `ecvt` (6 significant digits, laid out as printf's `%g`, the same text as `@print`; `appendFloatExact` writes the shortest digits that read back, from `aye_std_ecvt`) and parsed with C's `strtod` after Aye checks the syntax.
ParseError
pub error ParseError { Invalid, Overflow }
eql
pub fn eql(a: []u8, b: []u8) bool
Do `a` and `b` have the same bytes?
eqlIgnoreCase
pub fn eqlIgnoreCase(a: []u8, b: []u8) bool
Like `eql`, but ASCII letters match either case.
startsWith
pub fn startsWith(s: []u8, prefix: []u8) bool
Does `s` start with `prefix`?
endsWith
pub fn endsWith(s: []u8, suffix: []u8) bool
Does `s` end with `suffix`?
indexOf
pub fn indexOf(s: []u8, needle: []u8) ?usize
The index of the first `needle` in `s`; an empty needle is at 0.
trim
pub fn trim(s: []u8) []u8
`s` without ASCII whitespace (space, `\t`, `\n`, `\r`) at either end.
toLower
pub fn toLower(s: []mut u8)
Changes the ASCII letters of `s` to lower case, in place.
split
pub fn split(s: []u8, sep: []u8) Split
The pieces of `s` between the separators `sep`: `split("a,,b", ",")` gives "a", "", "b". An empty `sep` gives `s` as the only piece.
Split
pub struct Split {
rest: []u8
sep: []u8
done: bool
pub fn next(self: *mut Self) ?[]u8
}
The iterator of `split`.
pub fn next(self: *mut Self) ?[]u8-
The next piece; null after the last one.
parseInt
pub fn parseInt(s: []u8) ParseError!i64
A decimal integer with an optional sign: "42", "-7", "+3".
parseFloat
pub fn parseFloat(s: []u8) ParseError!f64
A decimal float: an optional sign, digits with an optional `.` (digits on at least one side), and an optional exponent `e`/`E` with an optional sign. At most 63 bytes. Too large a value is `Overflow`.
Decoded
pub struct Decoded {
code: u32
len: usize
}
A Unicode code point and the number of bytes it took.
decode
pub fn decode(s: []u8) Decoded
Decodes the first UTF-8 sequence of `s`. An invalid sequence gives U+FFFD with `len` 1; an empty `s` gives U+FFFD with `len` 0.
encode
pub fn encode(code: u32, out: []mut u8) usize
Writes the UTF-8 bytes of `code` to the start of `out` and returns how many (1 to 4; panics if `out` is too short). A surrogate or a value above U+10FFFF is written as U+FFFD.
Builder
pub struct Builder {
buf: []mut u8
count: usize
alloc: Allocator
pub fn init(alloc: Allocator) Builder
pub fn deinit(self: *mut Self)
pub fn bytes(self: *Self) []u8
pub fn len(self: *Self) usize
pub fn clear(self: *mut Self)
pub fn append(self: *mut Self, s: []u8) AllocError!void
pub fn appendByte(self: *mut Self, b: u8) AllocError!void
pub fn appendChar(self: *mut Self, code: u32) AllocError!void
pub fn appendInt(self: *mut Self, v: i64) AllocError!void
pub fn appendUint(self: *mut Self, v: u64) AllocError!void
pub fn appendFloat(self: *mut Self, v: f64) AllocError!void
pub fn appendFloatExact(self: *mut Self, v: f64) AllocError!void
pub fn toOwned(self: *mut Self) AllocError![]mut u8
}
Builds a byte string in memory from `alloc`.
pub fn init(alloc: Allocator) Builder-
An empty builder; nothing is allocated until the first append.
pub fn deinit(self: *mut Self)-
Frees the bytes.
pub fn bytes(self: *Self) []u8-
The bytes so far; valid until the next append.
pub fn len(self: *Self) usize-
The number of bytes so far.
pub fn clear(self: *mut Self)-
Removes the bytes; keeps the memory.
pub fn append(self: *mut Self, s: []u8) AllocError!void-
Appends the bytes of `s`.
pub fn appendByte(self: *mut Self, b: u8) AllocError!void-
Appends the byte `b`.
pub fn appendChar(self: *mut Self, code: u32) AllocError!void-
Appends the UTF-8 bytes of the code point `code` (see `encode`).
pub fn appendInt(self: *mut Self, v: i64) AllocError!void-
Appends `v` in decimal (with a `-` when negative).
pub fn appendUint(self: *mut Self, v: u64) AllocError!void-
Appends `v` in decimal.
pub fn appendFloat(self: *mut Self, v: f64) AllocError!void-
Appends `v` as printf's `%g` (and `@print`) writes it: 6 significant digits, trailing zeros removed, an exponent below 1e-4 and from 1e6.
pub fn appendFloatExact(self: *mut Self, v: f64) AllocError!void-
Appends `v` with the shortest digits that read back as the same `f64`, laid out as `JSON.stringify` does: a whole number below 2^53 in size has no fraction or exponent (`-0` stays `-0`); sizes from 1e-6 up to below 1e21 are plain decimal (`0.1`, `123456.789`, `1e20` as 100000000000000000000); the rest are digits with an exponent (`1e+21`, `5e-324`, `-1.5e-10`). NaN and the infinities are written as `nan`, `inf` and `-inf`.
pub fn toOwned(self: *mut Self) AllocError![]mut u8-
The bytes in new memory of exactly their length, from the builder's allocator (free them with `alloc.free`). The builder is empty after.