String

class String(pointer: <Error class: unknown class><<Error class: unknown class>>) : ProxyInstance

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.

Skipped during bindings generation

  • method append_printf: Varargs parameter is not supported

  • parameter args: va_list

  • method printf: Varargs parameter is not supported

  • parameter args: va_list

Constructors

Link copied to clipboard
constructor(pointer: <Error class: unknown class><<Error class: unknown class>>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
var allocatedLen: <Error class: unknown class>

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

Link copied to clipboard
val glibStringPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open override val handle: <Error class: unknown class>?
Link copied to clipboard
var len: <Error class: unknown class>

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

Link copied to clipboard
var str: String?

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.

Functions

Link copied to clipboard
fun append(val: String): String

Adds a string onto the end of a #GString, expanding it if necessary.

Link copied to clipboard

Adds a byte onto the end of a #GString, expanding it if necessary.

Link copied to clipboard
fun appendLen(val: String, len: Long): String

Appends @len bytes of @val to @string.

Link copied to clipboard
fun appendUnichar(wc: <Error class: unknown class>): String

Converts a Unicode character into UTF-8, and appends it to the string.

Link copied to clipboard
fun appendUriEscaped(unescaped: String, reservedCharsAllowed: String, allowUtf8: Boolean): String

Appends @unescaped to @string, escaping any characters that are reserved in URIs using URI-style escape sequences.

Link copied to clipboard

Converts all uppercase ASCII letters to lowercase ASCII letters.

Link copied to clipboard

Converts all lowercase ASCII letters to uppercase ASCII letters.

Link copied to clipboard
fun assign(rval: String): String

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 copy the string.

Link copied to clipboard
fun down(): String

Converts a #GString to lowercase.

Link copied to clipboard
fun equal(v2: String): Boolean

Compares two strings for equality, returning true if they are equal. For use with #GHashTable.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Compare two proxy instances for equality. This will compare both the type of the instances, and their memory addresses.

Link copied to clipboard
fun erase(pos: Long, len: Long): String

Removes @len bytes from a #GString, starting at position @pos. The rest of the #GString is shifted down to fill the gap.

Link copied to clipboard
fun free(freeSegment: Boolean): String?

Frees the memory allocated for the #GString. If @free_segment is true it also frees the character data. If it's false, the caller gains ownership of the buffer and must free it after use with g_free().

Link copied to clipboard

Frees the memory allocated for the #GString.

Link copied to clipboard

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.

Link copied to clipboard
fun hash(): <Error class: unknown class>

Creates a hash code for @str; for use with #GHashTable.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun insert(pos: Long, val: String): String

Inserts a copy of a string into a #GString, expanding it if necessary.

Link copied to clipboard
fun insertC(pos: Long, c: Char): String

Inserts a byte into a #GString, expanding it if necessary.

Link copied to clipboard
fun insertLen(pos: Long, val: String, len: Long): String

Inserts @len bytes of @val into @string at @pos.

Link copied to clipboard
fun insertUnichar(pos: Long, wc: <Error class: unknown class>): String

Converts a Unicode character into UTF-8, and insert it into the string at the given position.

Link copied to clipboard
fun overwrite(pos: <Error class: unknown class>, val: String): String

Overwrites part of a string, lengthening it if necessary.

Link copied to clipboard
fun overwriteLen(pos: <Error class: unknown class>, val: String, len: Long): String

Overwrites part of a string, lengthening it if necessary. This function will work with embedded nuls.

Link copied to clipboard
fun prepend(val: String): String

Adds a string on to the start of a #GString, expanding it if necessary.

Link copied to clipboard

Adds a byte onto the start of a #GString, expanding it if necessary.

Link copied to clipboard
fun prependLen(val: String, len: Long): String

Prepends @len bytes of @val to @string.

Link copied to clipboard
fun prependUnichar(wc: <Error class: unknown class>): String

Converts a Unicode character into UTF-8, and prepends it to the string.

Link copied to clipboard
fun replace(find: String, replace: String, limit: <Error class: unknown class>): <Error class: unknown class>

Replaces the string @find with the string @replace in a #GString up to

Link copied to clipboard
fun setSize(len: <Error class: unknown class>): String

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 are undefined. (However, as always, string->strstring->len will be a nul byte.)

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun truncate(len: <Error class: unknown class>): String

Cuts off the end of the GString, leaving the first @len bytes.

Link copied to clipboard
fun up(): String

Converts a #GString to uppercase.