glib.string_
Module for [String] class
class String
Types 1
classString : gobject.boxed.Boxed
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.
Methods
String self()Returns `this`, for use in `with` statements.string str() @propertyGet `str` field. Returns: 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.void str(string propval) @propertySet `str` field. Params: propval = 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.size_t len() @propertyGet `len` field. Returns: contains the length of the string, not including the terminating nul byte.void len(size_t propval) @propertySet `len` field. Params: propval = contains the length of the string, not including the terminating nul byte.size_t allocatedLen() @propertyGet `allocatedLen` field. Returns: the number of bytes that can be stored in the string before it needs to be reallocated. May be larger than @len.void allocatedLen(size_t propval) @propertySet `allocatedLen` field. Params: propval = the number of bytes that can be stored in the string before it needs to be reallocated. May be larger than @len.glib.string_.String newLen(string init_, ptrdiff_t len)Creates a new #GString with len bytes of the init buffer. Because a length is provided, init need not be nul-terminated, and can contain embedded nul bytes.glib.string_.String newTake(string init_ = null)Creates a new #GString, initialized with the given string.glib.string_.String sizedNew(size_t dflSize)Creates a new #GString, with enough space for dfl_size bytes. This is useful if you are going to add a lot of text to the string and don't want it to be reallocated too often.glib.string_.String append(string val)Adds a string onto the end of a #GString, expanding it if necessary.glib.string_.String appendC(char c)Adds a byte onto the end of a #GString, expanding it if necessary.glib.string_.String appendLen(string val, ptrdiff_t len)Appends len bytes of val to string.glib.string_.String appendUnichar(dchar wc)Converts a Unicode character into UTF-8, and appends it to the string.glib.string_.String appendUriEscaped(string unescaped, string reservedCharsAllowed, bool allowUtf8)Appends unescaped to string, escaping any characters that are reserved in URIs using URI-style escape sequences.glib.string_.String asciiDown()Converts all uppercase ASCII letters to lowercase ASCII letters. Returns: passed-in string pointer, with all the uppercase characters converted to lowercase in place, with semantics that exactly ma...glib.string_.String asciiUp()Converts all lowercase ASCII letters to uppercase ASCII letters. Returns: passed-in string pointer, with all the lowercase characters converted to uppercase in place, with semantics that exactly ma...glib.string_.String assign(string rval)Copies the bytes from a string into a #GString, destroying any previous contents. It is rather like the standard strcpy() function, except that you do not have to worry about having enough space to...glib.string_.String down()Converts a #GString to lowercase. Returns: the #GStringbool equal(glib.string_.String v2)Compares two strings for equality, returning true if they are equal. For use with #GHashTable.glib.string_.String erase(ptrdiff_t pos, ptrdiff_t len)Removes len bytes from a #GString, starting at position pos. The rest of the #GString is shifted down to fill the gap.string freeAndSteal()Frees the memory allocated for the #GString.glib.bytes.Bytes freeToBytes()Transfers ownership of the contents of string to a newly allocated #GBytes. The #GString structure itself is deallocated, and it is therefore invalid to use string after invoking this function.uint hash()Creates a hash code for str; for use with #GHashTable. Returns: hash code for strglib.string_.String insert(ptrdiff_t pos, string val)Inserts a copy of a string into a #GString, expanding it if necessary.glib.string_.String insertC(ptrdiff_t pos, char c)Inserts a byte into a #GString, expanding it if necessary.glib.string_.String insertLen(ptrdiff_t pos, string val, ptrdiff_t len)Inserts len bytes of val into string at pos.glib.string_.String insertUnichar(ptrdiff_t pos, dchar wc)Converts a Unicode character into UTF-8, and insert it into the string at the given position.glib.string_.String overwrite(size_t pos, string val)Overwrites part of a string, lengthening it if necessary.glib.string_.String overwriteLen(size_t pos, string val, ptrdiff_t len)Overwrites part of a string, lengthening it if necessary. This function will work with embedded nuls.glib.string_.String prepend(string val)Adds a string on to the start of a #GString, expanding it if necessary.glib.string_.String prependC(char c)Adds a byte onto the start of a #GString, expanding it if necessary.glib.string_.String prependLen(string val, ptrdiff_t len)Prepends len bytes of val to string.glib.string_.String prependUnichar(dchar wc)Converts a Unicode character into UTF-8, and prepends it to the string.uint replace(string find, string replace, uint limit)Replaces the string find with the string replace in a #GString up to limit times. If the number of instances of find in the #GString is less than limit, all instances are replaced. If limit is `0`,...glib.string_.String setSize(size_t len)Sets the length of a #GString. If the length is less than the current length, the string will be truncated. If the length is greater than the current length, the contents of the newly added area ar...glib.string_.String truncate(size_t len)Cuts off the end of the GString, leaving the first len bytes.glib.string_.String up()Converts a #GString to uppercase. Returns: string