String

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.

Constructors

this
this(string init_)

Creates a new #GString, initialized with the given string.

Members

Functions

append
glib.string_.String append(string val)

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

appendC
glib.string_.String appendC(char c)

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

appendLen
glib.string_.String appendLen(string val, ptrdiff_t len)

Appends len bytes of val to string.

appendUnichar
glib.string_.String appendUnichar(dchar wc)

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

appendUriEscaped
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.

asciiDown
glib.string_.String asciiDown()

Converts all uppercase ASCII letters to lowercase ASCII letters.

asciiUp
glib.string_.String asciiUp()

Converts all lowercase ASCII letters to uppercase ASCII letters.

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

down
glib.string_.String down()

Converts a #GString to lowercase.

equal
bool equal(glib.string_.String v2)

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

erase
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.

freeAndSteal
string freeAndSteal()

Frees the memory allocated for the #GString.

freeToBytes
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.

hash
uint hash()

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

insert
glib.string_.String insert(ptrdiff_t pos, string val)

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

insertC
glib.string_.String insertC(ptrdiff_t pos, char c)

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

insertLen
glib.string_.String insertLen(ptrdiff_t pos, string val, ptrdiff_t len)

Inserts len bytes of val into string at pos.

insertUnichar
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.

overwrite
glib.string_.String overwrite(size_t pos, string val)

Overwrites part of a string, lengthening it if necessary.

overwriteLen
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.

prepend
glib.string_.String prepend(string val)

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

prependC
glib.string_.String prependC(char c)

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

prependLen
glib.string_.String prependLen(string val, ptrdiff_t len)

Prepends len bytes of val to string.

prependUnichar
glib.string_.String prependUnichar(dchar wc)

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

replace
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, all instances of find are replaced.

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

truncate
glib.string_.String truncate(size_t len)

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

up
glib.string_.String up()

Converts a #GString to uppercase.

Static functions

newLen
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.

newTake
glib.string_.String newTake(string init_)

Creates a new #GString, initialized with the given string.

sizedNew
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.

Inherited Members

From Boxed

cInstancePtr
void* cInstancePtr;

Pointer to the C boxed value

getType
GType getType()

Get the GType of this boxed type.

gType
GType gType [@property getter]

Boxed GType property.

self
Boxed self()

Convenience method to return this cast to a type. For use in D with statements.

copy_
void* copy_()

Make a copy of the wrapped C boxed data.

boxedCopy
void* boxedCopy(void* cBoxed)

Copy a C boxed value using g_boxed_copy.

boxedFree
void boxedFree(void* cBoxed)

Free a C boxed value using g_boxed_free.