Table of Contents

Class Utf8Buffer

Namespace
Terminal.Gui.Drivers
Assembly
Terminal.Gui.dll

PERF: UTF-8 byte buffer — replaces StringBuilder in the output hot path. ANSI sequences (CSI/SGR/OSC) are pure ASCII and appended via fast path (no encoding). Unicode graphemes are UTF-8 encoded on append. Zero allocation in stable state (internal buffer grows as needed).

public sealed class Utf8Buffer
Inheritance
Utf8Buffer
Inherited Members

Constructors

Utf8Buffer()

Properties

Length

Gets the number of bytes written.

Methods

Append(ReadOnlySpan<char>)

Appends a char span as UTF-8 encoded bytes.

Append(string)

Appends a string, auto-detecting ASCII vs Unicode. ASCII strings use a fast truncation path; Unicode strings are UTF-8 encoded.

Append(Utf8Buffer)

Appends the contents of another Utf8Buffer.

AppendAscii(string)

Appends an ASCII string as raw bytes. Caller must ensure text is pure ASCII. No UTF-8 encoding is performed — each char is truncated to byte directly.

AppendByte(byte)

Appends a single ASCII byte directly.

AppendBytes(ReadOnlySpan<byte>)

Appends raw UTF-8 bytes directly (e.g. from another buffer or pre-encoded span).

AppendInt(int)

Appends an integer as ASCII digits directly (no string allocation).

AsSpan()

Gets a read-only span over the written bytes.

Clear()

Resets the buffer for reuse without releasing the backing array.