StringBuilder
Object Hierarchy:
GLib.StringBuilder
GLib.StringBuilder
GLib.StringBuilder
Description:
[ Compact ] [ GIR ( name = "String" ) ] [ CCode ( cname = "GString" , cprefix = "g_string_" , free_function = "g_string_free" , type_id = "G_TYPE_GSTRING" ) ]public class StringBuilder
A `GString` is an object that handles the memory management of a C string.
The emphasis of `GString` is on text, typically UTF-8. Crucially, the "str" member of a `GString` 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 `GString` can also hold arbitrary binary data, because it has a "len" member, which includes any possible embedded nul characters in
the data. Conceptually then, `GString` is like a `GByteArray` with the addition of many convenience methods for text, and a guaranteed nul
terminator.
Content:
Properties:
Static methods:
public static Bytes free_to_bytes (owned StringBuilder str)
Transfers ownership of the contents of this
to a newly allocated Bytes .
Creation methods:
Methods:
public unowned StringBuilder append (string val)
Adds a string onto the end of a StringBuilder ,
expanding it if necessary.
public unowned StringBuilder append_c (char c)
Adds a byte onto the end of a StringBuilder ,
expanding it if necessary.
public unowned StringBuilder append_len (string val, ssize_t len)
Appends len
bytes of val
to
this .
public void append_printf (string format, ...)
Appends a formatted string onto the end of a
StringBuilder .
public unowned StringBuilder append_unichar (unichar wc)
Converts a Unicode character into UTF-8, and appends it to the string.
public void append_vprintf (string format, va_list args)
Appends a formatted string onto the end of a
StringBuilder .
public unowned StringBuilder assign (string rval)
Copies the bytes from a string into a StringBuilder
, destroying any previous contents.
public unowned StringBuilder erase (ssize_t pos = 0 , ssize_t len = -1 )
Removes len
bytes from a StringBuilder
, starting at position pos
.
public string free_and_steal ()
Frees the memory allocated for the StringBuilder .
public unowned StringBuilder insert (ssize_t pos, string val)
Inserts a copy of a string into a StringBuilder ,
expanding it if necessary.
public unowned StringBuilder insert_len (ssize_t pos, string val, ssize_t len)
Inserts len
bytes of val
into
this at pos
.
public unowned StringBuilder insert_unichar (ssize_t pos, unichar wc)
Converts a Unicode character into UTF-8, and insert it into the string at
the given position.
public unowned StringBuilder overwrite (size_t pos, string val)
Overwrites part of a string, lengthening it if necessary.
public unowned StringBuilder overwrite_len (size_t pos, string val, ssize_t len)
Overwrites part of a string, lengthening it if necessary.
public unowned StringBuilder prepend (string val)
Adds a string on to the start of a StringBuilder ,
expanding it if necessary.
public unowned StringBuilder prepend_c (char c)
Adds a byte onto the start of a StringBuilder ,
expanding it if necessary.
public unowned StringBuilder prepend_len (string val, ssize_t len)
Prepends len
bytes of val
to
this .
public unowned StringBuilder prepend_unichar (unichar wc)
Converts a Unicode character into UTF-8, and prepends it to the string.
public void printf (string format, ...)
Writes a formatted string into a StringBuilder .
public uint replace (string find, string replace, uint limit = 0 )
Replaces the string find
with the string replace
in a StringBuilder up to limit
times.
public unowned StringBuilder truncate (size_t len = 0 )
Cuts off the end of the GString, leaving the first len
bytes.
public void vprintf (string format, va_list args)
Writes a formatted string into a StringBuilder .
Fields: