String
1 type1 value17 functionsFunctions on Strings, which are UTF-8 byte sequences. Lengths and offsets
count bytes; UTF8.codePoints reads a string as characters.
== compares strings byte for byte, as eq does.
Types
@Builder
A string being built by appending, each append amortized constant time:
append writes into a buffer that grows to the next power
of two when it runs out of room, rather than copying the string so far, and build makes the
String. A builder is a value like any other: appending to one gives a new
builder and leaves the old one as it was, so it may be appended to again.
Values
builder
The builder holding no bytes yet.
Functions
concat
The two strings one after the other.
eq
Byte equality. A string-literal pattern compares through this too.
ne
true when the strings differ in any byte.
split
Every piece between occurrences of the separator, in order: split("a,b,", ",") is ["a", "b", ""]. An empty separator does not split at all, so
split(s, "") is [s], and split("", ",") is [""].
join
The strings with the separator between each two of them.
trim
Without leading and trailing ASCII whitespace: space, tab, \n, \r, form
feed and vertical tab. Other whitespace, such as a no-break space, stays.
lowercaseAscii
Each ASCII letter A to Z as its lowercase a to z; every other byte,
a non-ASCII letter's included, is left as it is.
contains
Every string contains the empty string.
startsWith
Every string starts with the empty string.
endsWith
Every string ends with the empty string.
byteLength
The length in UTF-8 bytes, not in code points.
sliceBytes
The bytes from offset start up to, not including, offset end. Both are
held to 0 … byteLength(s) first, and an end at or before start is the
empty string. The offsets count bytes, so a cut inside a code point leaves
part of its UTF-8 sequence on either side.
fromCodePoint
The one-code-point string encoding a code point in UTF-8. A value outside
0 … 0x10FFFF is U+FFFD; a surrogate is encoded as it is. The inverse of
UTF8.codePoints.
append
The builder holding the bytes of b followed by those of s. The bytes
are written in place when b is the newest builder on its buffer and the
buffer has room. Otherwise they are copied, after b's own bytes, into a
new buffer: the smallest power of two that holds both.
appendSlice
append of the bytes of s from offset start up to, not including,
offset end, held to s as sliceBytes holds them,
without building the slice.
appendWrapped
append of open, s and close, one after the other, as one step:
appendWrapped(b, "\"", s, "\"") appends s in quotes.
build
The string of every byte appended so far. Appending to the builder afterwards leaves it as it is. Building from the newest builder on a buffer copies nothing; the string then holds the buffer, room to grow included.