GLib.String¶
Fields¶
| Name | Type | Access | Description | 
|---|---|---|---|
| allocated_len | int | r/w | the number of bytes that can be stored in the string before it needs to be reallocated. May be larger than len. | 
| len | int | r/w | contains the length of the string, not including the terminating nul byte. | 
| str | str | r/w | 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. | 
Methods¶
| append(val) | |
| append_c(c) | |
| append_len(val, len) | |
| append_unichar(wc) | |
| append_uri_escaped(unescaped, reserved_chars_allowed, allow_utf8) | |
| ascii_down() | |
| ascii_up() | |
| assign(rval) | |
| down() | |
| equal(v2) | |
| erase(pos, len) | |
| free(free_segment) | |
| free_to_bytes() | |
| hash() | |
| insert(pos, val) | |
| insert_c(pos, c) | |
| insert_len(pos, val, len) | |
| insert_unichar(pos, wc) | |
| overwrite(pos, val) | |
| overwrite_len(pos, val, len) | |
| prepend(val) | |
| prepend_c(c) | |
| prepend_len(val, len) | |
| prepend_unichar(wc) | |
| set_size(len) | |
| truncate(len) | |
| up() | 
Details¶
- 
class GLib.String¶
- The - GLib.Stringstruct contains the public fields of a- GLib.String.- 
append(val)[source]¶
- Parameters: - val ( - str) – the string to append onto the end of self- Returns: - self - Return type: - GLib.String- Adds a string onto the end of a - GLib.String, expanding it if necessary.
 - 
append_c(c)[source]¶
- Parameters: - c ( - int) – the byte to append onto the end of self- Returns: - self - Return type: - GLib.String- Adds a byte onto the end of a - GLib.String, expanding it if necessary.
 - 
append_len(val, len)[source]¶
- Parameters: - Returns: - self - Return type: - Appends len bytes of val to self. - If len is positive, val may contain embedded nuls and need not be nul-terminated. It is the caller’s responsibility to ensure that val has at least len addressable bytes. - If len is negative, val must be nul-terminated and len is considered to request the entire string length. This makes - GLib.String.append_len() equivalent to- GLib.String.append().
 - 
append_unichar(wc)[source]¶
- Parameters: - wc ( - str) – a Unicode character- Returns: - self - Return type: - GLib.String- Converts a Unicode character into UTF-8, and appends it to the string. 
 - 
append_uri_escaped(unescaped, reserved_chars_allowed, allow_utf8)[source]¶
- Parameters: - Returns: - self - Return type: - Appends unescaped to self, escaping any characters that are reserved in URIs using URI-style escape sequences. - New in version 2.16. 
 - 
ascii_down()[source]¶
- Returns: - passed-in self pointer, with all the uppercase characters converted to lowercase in place, with semantics that exactly match - GLib.ascii_tolower().- Return type: - GLib.String- Converts all uppercase ASCII letters to lowercase ASCII letters. 
 - 
ascii_up()[source]¶
- Returns: - passed-in self pointer, with all the lowercase characters converted to uppercase in place, with semantics that exactly match - GLib.ascii_toupper().- Return type: - GLib.String- Converts all lowercase ASCII letters to uppercase ASCII letters. 
 - 
assign(rval)[source]¶
- Parameters: - rval ( - str) – the string to copy into self- Returns: - self - Return type: - GLib.String- Copies the bytes from a string into a - GLib.String, 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()[source]¶
- Returns: - the - GLib.String- Return type: - GLib.String- Converts a - GLib.Stringto lowercase.- Deprecated since version 2.2: This function uses the locale-specific tolower() function, which is almost never the right thing. Use - GLib.String.ascii_down() or- GLib.utf8_strdown() instead.
 - 
equal(v2)[source]¶
- Parameters: - v2 ( - GLib.String) – another- GLib.String- Returns: - Trueif the strings are the same length and contain the same bytes- Return type: - bool- Compares two strings for equality, returning - Trueif they are equal. For use with- GLib.HashTable.
 - 
erase(pos, len)[source]¶
- Parameters: - Returns: - self - Return type: - Removes len bytes from a - GLib.String, starting at position pos. The rest of the- GLib.Stringis shifted down to fill the gap.
 - 
free(free_segment)[source]¶
- Parameters: - free_segment ( - bool) – if- True, the actual character data is freed as well- Returns: - the character data of self (i.e. - Noneif free_segment is- True)- Return type: - stror- None- Frees the memory allocated for the - GLib.String. If free_segment is- Trueit also frees the character data. If it’s- False, the caller gains ownership of the buffer and must free it after use with- GLib.free().
 - 
free_to_bytes()[source]¶
- Returns: - A newly allocated - GLib.Bytescontaining contents of self; self itself is freed- Return type: - GLib.Bytes- Transfers ownership of the contents of self to a newly allocated - GLib.Bytes. The- GLib.Stringstructure itself is deallocated, and it is therefore invalid to use self after invoking this function.- Note that while - GLib.Stringensures that its buffer always has a trailing nul character (not reflected in its “len”), the returned- GLib.Bytesdoes not include this extra nul; i.e. it has length exactly equal to the “len” member.- New in version 2.34. 
 - 
hash()[source]¶
- Returns: - hash code for self - Return type: - int- Creates a hash code for self; for use with - GLib.HashTable.
 - 
insert(pos, val)[source]¶
- Parameters: - Returns: - self - Return type: - Inserts a copy of a string into a - GLib.String, expanding it if necessary.
 - 
insert_c(pos, c)[source]¶
- Parameters: - Returns: - self - Return type: - Inserts a byte into a - GLib.String, expanding it if necessary.
 - 
insert_len(pos, val, len)[source]¶
- Parameters: - Returns: - self - Return type: - Inserts len bytes of val into self at pos. - If len is positive, val may contain embedded nuls and need not be nul-terminated. It is the caller’s responsibility to ensure that val has at least len addressable bytes. - If len is negative, val must be nul-terminated and len is considered to request the entire string length. - If pos is -1, bytes are inserted at the end of the string. 
 - 
insert_unichar(pos, wc)[source]¶
- Parameters: - Returns: - self - Return type: - Converts a Unicode character into UTF-8, and insert it into the string at the given position. 
 - 
overwrite(pos, val)[source]¶
- Parameters: - Returns: - self - Return type: - Overwrites part of a string, lengthening it if necessary. - New in version 2.14. 
 - 
overwrite_len(pos, val, len)[source]¶
- Parameters: - Returns: - self - Return type: - Overwrites part of a string, lengthening it if necessary. This function will work with embedded nuls. - New in version 2.14. 
 - 
prepend(val)[source]¶
- Parameters: - val ( - str) – the string to prepend on the start of self- Returns: - self - Return type: - GLib.String- Adds a string on to the start of a - GLib.String, expanding it if necessary.
 - 
prepend_c(c)[source]¶
- Parameters: - c ( - int) – the byte to prepend on the start of the- GLib.String- Returns: - self - Return type: - GLib.String- Adds a byte onto the start of a - GLib.String, expanding it if necessary.
 - 
prepend_len(val, len)[source]¶
- Parameters: - Returns: - self - Return type: - Prepends len bytes of val to self. - If len is positive, val may contain embedded nuls and need not be nul-terminated. It is the caller’s responsibility to ensure that val has at least len addressable bytes. - If len is negative, val must be nul-terminated and len is considered to request the entire string length. This makes - GLib.String.prepend_len() equivalent to- GLib.String.prepend().
 - 
prepend_unichar(wc)[source]¶
- Parameters: - wc ( - str) – a Unicode character- Returns: - self - Return type: - GLib.String- Converts a Unicode character into UTF-8, and prepends it to the string. 
 - 
set_size(len)[source]¶
- Parameters: - len ( - int) – the new length- Returns: - self - Return type: - GLib.String- Sets the length of a - GLib.String. 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(len)[source]¶
- Parameters: - len ( - int) – the new size of self- Returns: - self - Return type: - GLib.String- Cuts off the end of the - GLib.String, leaving the first len bytes.
 - 
up()[source]¶
- Returns: - self - Return type: - GLib.String- Converts a - GLib.Stringto uppercase.- Deprecated since version 2.2: This function uses the locale-specific toupper() function, which is almost never the right thing. Use - GLib.String.ascii_up() or- GLib.utf8_strup() instead.
 
-