Data v0.1.0

Source
Returns the pointer to the bytes written so far.

Package: Text

Signature

func Data(self) -> *char8;

Returns

A pointer to the first byte of the block, or null for a builder that has not taken one yet.

Unlike String::Data, this points at memory a later append may move: growing the block reallocates it. Do not hold the pointer across an Append, a Reserve, a Grow, or a Shrink — read it again afterwards.

Only the first Length bytes have been written; the rest of the capacity is uninitialized. There is no null terminator, so pair the pointer with Length.

Example

import Text::StringBuilder;

func Main() -> int {
    var builder = StringBuilder::New();
    builder.Append("Rux");

    let bytes = builder.Data(); // valid for Length() bytes

    builder.Append(" rocks");   // may reallocate -- `bytes` is now suspect

    builder.Free();
    return 0;
}

See also