Skip to content

UXStrItem

UXStrItem is one string, boxed so it can go in a collection.

#use <UXKit> // or #import "UXText.xc"
class UXStrItem : Object {
u8* s; // the string, NUL-terminated
}

The class has one field.

Array holds Objects, and a bare u8* is not one, so a list of strings needs a wrapper. UXStrItem is that wrapper.

UXPathComp and UXKVEntry exist for the same reason. Boxing is explicit in xtc, not automatic, so the wrapper appears in signatures:

static Array<UXStrItem>* split(u8* s, u8 delim)

UXText.partAt unwraps for you, so the common loop never names the type:

Array<UXStrItem>* parts = UXText.split(line, (u8)',');
for (i32 i = 0; i < (i32)parts.count(); i = i + 1) {
Stdio.printf(" [%s]\n", UXText.partAt(parts, i));
}

UXText.join takes the whole array back, so a split → filter → join never builds one by hand.

Two cases need it: making a list to hand to join, and holding strings that did not come from a split.

Array<UXStrItem>* items = new Array();
UXStrItem* it = new UXStrItem();
it.s = UXStr.dup(name); // copy if `name` is borrowed
items.add(it);

init sets s to "", not null, so a new item is safe to print before it is filled in. join relies on this because it walks every element.

u8* s

The string. Never null after init.

  • UXText: split, join, and everything else that produces or consumes these
  • UXStr: dup, for when the string is borrowed
  • UXPathComp: the same boxing for a path component