Data v0.1.0

Source
Returns the pointer to the underlying bytes.

Package: Text

Signature

func Data(self) -> *char8;

Returns

A pointer to the first byte of the block, or null for the empty string.

The block stays the string's to free — this hands out the bytes, not ownership of them. It carries no null terminator, so pair it with Length rather than letting anything scan for a terminator that is not there.

The string is immutable, and the pointer stays valid until the string is passed to Free.

Example

import Text::String;

func Main() -> int {
    var text = String::From("Rux");

    let bytes = text.Data();
    let count = text.Length(); // 3 -- the bytes end here, not at a null

    text.Free();               // `bytes` is now dangling
    return 0;
}

See also

  • String — the string type
  • Length — how many bytes the pointer covers
  • At — read one byte with a bounds check