UTF-8 text utilities, string views, owned strings, and formatting helpers.
Single Unicode code point wrapper used by UTF-8 decoding and string construction helpers.
codepoint: stored Unicode code point as Int32.equal, greater, less: comparison helpers against another Char or one-character Text.hash: hash value derived from the code point.REPLACEMENT_CHARACTER: Unicode replacement character.isHeadUnit (unit -- valid): tests whether a UTF-8 code unit can start a sequence.isValidCodepoint (codepoint -- valid): tests whether a code point is valid for UTF-8 encoding.toChar (codepoint -- char): constructs Char from a valid Int32 code point.toChar (text -- char): decodes the first character from one-character text input."String" use
"control" use
{} () {} [
65i32 toChar .codepoint printStack _:;
] "main" exportFunction
65 Cref
Non-owning UTF-8 view built from item data and item count.
data (-- data): returns the first UTF-8 code unit as Nat8 Cref.size (-- size): returns the UTF-8 code-unit count as Int32.hash (-- hash): returns the view hash.iter (-- iter): returns a UTF-8 character iterator.slice (offset size -- view): returns a subview by code-unit range.span (-- span): returns a byte span over the same storage.toStringView ((Nat8 Cref Int32) -- view): constructs StringView from data and size.makeStringView (StringView -- view): copies an existing view.makeStringView (Text -- view): builds a view over UTF-8 storage of Text.makeStringView (String -- view): builds a view over the owned string contents.makeStringViewByAddress (address -- view): builds a view over zero-terminated text at address."String" use
"control" use
{} () {} [
view: "hi" makeStringView;
view.size printStack _:;
] "main" exportFunction
2
Owned mutable UTF-8 string built on Nat8 Array.
chars: underlying Nat8 Array storage including the trailing terminator when present.data (-- data): returns the first UTF-8 code unit.hash (-- hash): returns the string hash.iter (-- iter): returns byte iteration over current storage.size (-- size): returns the logical text size without the trailing terminator.slice (offset size -- view): returns a StringView over the selected code-unit range.span (-- span): returns a byte span over the same storage.getStringView (-- view): returns a StringView over the current contents.resize (size --): resizes the underlying storage and restores the trailing terminator.catAsciiSymbolCodeNZ (codePoint --): appends one ASCII code point.catCharNZ (char --): appends one Char.catStringNZ (string --): appends text or string contents.catIntNZ (number --): appends signed integer text.catNatNZ (number --): appends unsigned integer text.catHexNZ (number --): appends hexadecimal text.catFloatNZ (number --): appends floating-point text.catBy3NZ (number --): appends decimal text grouped by three digits.catCondNZ (condition --): appends TRUE or FALSE.catNZ (arg --): generic non-terminating append helper over supported text, numeric, condition, and span inputs.catSymbolCode (codePoint --): appends one code point through toChar.catAsciiSymbolCode (codePoint --): appends one ASCII code point.catChar (char --): appends one Char.catString (string --): appends text or string contents.catInt (number --): appends signed integer text.catUint (number --): appends unsigned integer text.catHex (number --): appends hexadecimal text.catFloat (number --): appends floating-point text.cat (arg --): generic terminating append helper over supported inputs.catMany (list --): concatenates items from an index or list and recognizes By3 and Hex markers in the following slot.By3: marker used by catMany for grouped decimal formatting.Hex: marker used by catMany for hexadecimal formatting.makeNZ: removes the trailing zero terminator when present.makeZ: restores the trailing zero terminator when missing.STRING: deprecated marker field."String" use
"control" use
{} () {} [
text: "abc" toString;
text.size printStack _:;
@text.getStringView.size printStack _:;
] "main" exportFunction
Int32
Int32
"String" use
"control" use
{} Int32 {} [
text: String;
(123456 By3 ", " 255 Hex) @text.catMany
@text.getStringView print
0
] "main" exportFunction
123,456, FF
addTerminator (source -- string): returns text with a trailing zero terminator.assembleString (list -- string): concatenates many items into one String.decode (source -- iter): decodes UTF-8 into character iteration.hash (text -- hash): returns text hash through StringView hashing.print: prints String, StringView, or other supported text inputs.printList (list --): assembles then prints a string from many items.toString (arg -- string): converts supported input to String.splitString (string -- result): splits a string into one-character StringView items and reports success, errorOffset, and chars.success: TRUE on valid UTF-8 input and FALSE on the first decoding error.errorOffset: byte offset of the first decoding error, or -1 on success.chars: one-character StringView items in source order."String" use
"control" use
{} () {} [
parts: "你好" splitString;
parts.success printStack _:;
parts.chars.size printStack _:;
] "main" exportFunction
Cond Cref
Int32
"String" use
"control" use
{} Int32 {} [
("left=" 42) printList
0
] "main" exportFunction
left=42
Utf8DecoderMode provides the modes REPORT, TRUST, and REPLACE.REPORT: produces Int32 code points and reports -1 on the first error.TRUST: produces Char values and assumes the source is valid UTF-8.REPLACE: produces Char values and replaces maximal ill-formed subsequences with REPLACEMENT_CHARACTER.decodeUtf8 (mode source -- decoder): low-level UTF-8 decoder.getCodePointAndSize, getCodePointSize, and makeStringIter2 are lower-level helpers retained in the module.