abla/text
Generated from source.
Import with import "abla/text".
Source: abla/text/entry.ab
Utf8Info (class)
class Utf8Info(
val valid: bool,
val codePoints: int,
val errorOffset: int
)
UTF-8 scan result. valid means the whole input passed, codePoints counts the valid prefix, and errorOffset is the first invalid sequence's byte offset or -1 on success.
ablaUtf8EncodeScalar (extern)
noescape extern:"intrinsic" fun ablaUtf8EncodeScalar(scalar: int): string
Returns the UTF-8 bytes for scalar or an empty string for a surrogate or out-of-range value.
ablaTextFindSequence (extern)
noescape extern:"intrinsic" fun ablaTextFindSequence(
text: string,
sequence: string,
begin: int,
end: int
): int
Returns the first byte offset of sequence in [begin, end), begin for an empty sequence within valid bounds, or -1 for invalid bounds or no match.
ablaTextFindByte (extern)
noescape extern:"intrinsic" fun ablaTextFindByte(
text: string,
byte: int,
begin: int,
end: int
): int
Returns the first offset of byte in [begin, end) or -1 for invalid bounds, an invalid byte, or no match.
ablaTextAsciiEqualInsensitive (extern)
noescape extern:"intrinsic" fun ablaTextAsciiEqualInsensitive(
left: string,
right: string
): bool
Returns true when the inputs match byte for byte after folding ASCII letters to the same case.
ablaTextReadU32LittleEndian (extern)
noescape extern:"intrinsic" fun ablaTextReadU32LittleEndian(
text: string,
offset: int
): int
Returns a little-endian unsigned 32-bit value as an int or -1 if four bytes cannot be read at offset.
ablaTextIsValidUtf8 (extern)
noescape extern:"intrinsic" fun ablaTextIsValidUtf8(text: string): bool
Returns true if every byte in text belongs to a valid UTF-8 encoding of a Unicode scalar.
utf8Encode (fun)
fun utf8Encode(scalar: int): string
Encodes the Unicode scalar scalar as UTF-8. Returns an empty string for surrogate values or values outside the Unicode range.
textFindSequence (fun)
fun textFindSequence(
text: string,
sequence: string,
begin: int = 0,
end: int = text.size
): int
Searches text in the byte interval [begin, end) for sequence. Returns the first byte offset, begin for an empty sequence within valid bounds, or -1 for invalid bounds or no match.
textFindByte (fun)
fun textFindByte(
text: string,
byte: int,
begin: int = 0,
end: int = text.size
): int
Searches text in the byte interval [begin, end) for byte. Returns the first byte offset or -1 for no match, invalid bounds, or a byte outside 0–255.
textAsciiEqualInsensitive (fun)
fun textAsciiEqualInsensitive(left: string, right: string): bool
Compares left and right byte by byte, ignoring case for ASCII letters. All other bytes must match exactly.
textReadU32LittleEndian (fun)
fun textReadU32LittleEndian(text: string, offset: int): int
Reads four little-endian bytes of text at byte offset. Returns the unsigned 32-bit value as an int or -1 if four bytes are unavailable.
utf8SequenceLength (fun)
fun utf8SequenceLength(lead: int): int
Returns the expected UTF-8 sequence length for leading byte lead, or 0 if it cannot start a sequence.
utf8SequenceValid (fun)
fun utf8SequenceValid(text: string, offset: int, length: int): bool
Checks that a candidate sequence in text at byte offset fits, has valid continuation bytes, and meets the boundary rules for three- and four-byte sequences. Supply length from utf8SequenceLength for the leading byte. Returns false when these checks fail.
utf8Info (fun)
fun utf8Info(text: string): Utf8Info
Scans text and reports UTF-8 validity, the number of complete scalars before any error, and the first invalid sequence's byte offset (-1 when valid).
string.isValidUtf8 (extension fun)
fun string.isValidUtf8(): bool
The x86-64 validator scans long ASCII prefixes with SSE2. For shorter inputs and other targets, the local word loop checks ASCII and the intrinsic validates any input containing a multibyte sequence.
utf8DecodeAt (fun)
fun utf8DecodeAt(text: string, offset: int): int
Decodes a Unicode scalar from text at byte offset. Returns -1 if the offset is out of bounds or a valid sequence does not start there.
string.codePointAt (extension fun)
fun string.codePointAt(position: int): int
Returns the Unicode scalar at zero-based scalar position, or -1 if it is out of range or invalid UTF-8 is encountered while reaching or decoding it.
utf8ByteOffset (fun)
fun utf8ByteOffset(text: string, position: int): int
Returns the byte offset reached after advancing position Unicode scalars from the start of text. Returns -1 for a negative position, insufficient scalars, or invalid UTF-8 in the traversed prefix.
string.codePointSlice (extension fun)
fun string.codePointSlice(begin: int, end: int): string
Returns the substring between Unicode scalar positions begin (inclusive) and end (exclusive). Returns an empty string for invalid or reversed bounds, including bounds that cannot be reached through valid UTF-8.
string.startsWith (extension fun)
fun string.startsWith(prefix: string): bool
Returns true if the string begins with the exact bytes of prefix. An empty prefix always matches.
string.endsWith (extension fun)
fun string.endsWith(suffix: string): bool
Returns true if the string ends with the exact bytes of suffix. An empty suffix always matches.
string.contains (extension fun)
fun string.contains(needle: string): bool
Returns true if the exact bytes of needle occur in the string. An empty needle always matches.
string.indexOf (extension fun)
fun string.indexOf(needle: string, from: int = 0): int
The first position of needle at or after from, or -1.
string.lastIndexOf (extension fun)
fun string.lastIndexOf(needle: string): int
The last position of needle, or -1.
string.split (extension fun)
fun string.split(separator: string): array<string>
The pieces between the occurrences of separator: n occurrences give n + 1 pieces, empty ones included. An empty separator leaves it whole.
textJoin (fun)
fun textJoin(parts: array<string>, separator: string = ""): string
The parts, in order, with separator between each two.
array<string>.join (extension fun)
fun array<string>.join(separator: string = ""): string
Joins the strings in order, inserting separator between them.
string.trimStart (extension fun)
fun string.trimStart(): string
Returns the string with leading ASCII whitespace removed (space and bytes 9–13).
string.trimEnd (extension fun)
fun string.trimEnd(): string
Returns the string with trailing ASCII whitespace removed (space and bytes 9–13).
string.trim (extension fun)
fun string.trim(): string
Returns the string with ASCII whitespace removed from both ends (space and bytes 9–13).
string.replace (extension fun)
fun string.replace(old: string, replacement: string): string
Every occurrence of old replaced by replacement, left to right. An empty old replaces nothing.
string.uppercase (extension fun)
fun string.uppercase(): string
Returns the string with ASCII a–z mapped to A–Z. Other bytes are preserved.
string.lowercase (extension fun)
fun string.lowercase(): string
Returns the string with ASCII A–Z mapped to a–z. Other bytes are preserved.
string.repeat (extension fun)
fun string.repeat(count: int): string
Returns count concatenated copies of the string, or an empty string when count is zero or negative.
string.padStart (extension fun)
fun string.padStart(length: int, pad: string = " "): string
Padded at the start (or end) with pad repeated, to length bytes (whole code points only: see textPadding); a longer text is left as it is.
string.padEnd (extension fun)
fun string.padEnd(length: int, pad: string = " "): string
Appends repeated pad bytes until reaching length bytes or the next UTF-8 scalar would not fit. An invalid pad byte counts as a single unit. An empty pad or an already long enough string leaves the string unchanged.
sortedStrings (fun)
fun sortedStrings(values: array<string>): array<string>
A copy of values in byte order (a stable merge sort, O(n log n)).
array<string>.sorted (extension fun)
fun array<string>.sorted(): array<string>
A copy of the strings in byte order (stable merge sort, O(n log n)).
string.codePointCount (extension fun)
fun string.codePointCount(): int
Returns the number of Unicode scalars in the string, or -1 if the string contains invalid UTF-8.
percentDecode (fun)
fun percentDecode(value: string, query: bool = false): string?
Decodes percent escapes in value. With query enabled, unescaped plus signs become spaces. Returns null when an escape is malformed or the decoded bytes are invalid UTF-8.
percentEncode (fun)
fun percentEncode(value: string, query: bool = false): string
Encodes the bytes of value using uppercase percent escapes, preserving ASCII letters, digits, hyphen, period, underscore, and tilde. With query enabled, spaces become plus signs.
Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.