GString

A glib.string_.String is an object that handles the memory management of a C string.

The emphasis of glib.string_.String is on text, typically UTF-8. Crucially, the "str" member of a glib.string_.String is guaranteed to have a trailing nul character, and it is therefore always safe to call functions such as strchr() or strdup() on it.

However, a glib.string_.String can also hold arbitrary binary data, because it has a "len" member, which includes any possible embedded nul characters in the data. Conceptually then, glib.string_.String is like a glib.byte_array.ByteArray with the addition of many convenience methods for text, and a guaranteed nul terminator.

Members

Variables

allocatedLen
size_t allocatedLen;

the number of bytes that can be stored in the string before it needs to be reallocated. May be larger than @len.

len
size_t len;

contains the length of the string, not including the terminating nul byte.

str
char* str;

points to the character data. It may move as text is added. The @str field is null-terminated and so can be used as an ordinary C string.