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.String
struct contains the public fields of aGLib.String
.-
append
(val)[source]¶ Parameters: val ( str
) – the string to append onto the end of selfReturns: 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 selfReturns: 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 toGLib.String.append
().
-
append_unichar
(wc)[source]¶ Parameters: wc ( str
) – a Unicode characterReturns: 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 selfReturns: 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.String
to 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
() orGLib.utf8_strdown
() instead.
-
equal
(v2)[source]¶ Parameters: v2 ( GLib.String
) – anotherGLib.String
Returns: True
if the strings are the same length and contain the same bytesReturn type: bool
Compares two strings for equality, returning
True
if they are equal. For use withGLib.HashTable
.
-
erase
(pos, len)[source]¶ Parameters: Returns: self
Return type: Removes len bytes from a
GLib.String
, starting at position pos. The rest of theGLib.String
is shifted down to fill the gap.
-
free
(free_segment)[source]¶ Parameters: free_segment ( bool
) – ifTrue
, the actual character data is freed as wellReturns: the character data of self (i.e. None
if free_segment isTrue
)Return type: str
orNone
Frees the memory allocated for the
GLib.String
. If free_segment isTrue
it also frees the character data. If it’sFalse
, the caller gains ownership of the buffer and must free it after use withGLib.free
().
-
free_to_bytes
()[source]¶ Returns: A newly allocated GLib.Bytes
containing contents of self; self itself is freedReturn type: GLib.Bytes
Transfers ownership of the contents of self to a newly allocated
GLib.Bytes
. TheGLib.String
structure itself is deallocated, and it is therefore invalid to use self after invoking this function.Note that while
GLib.String
ensures that its buffer always has a trailing nul character (not reflected in its “len”), the returnedGLib.Bytes
does 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 selfReturns: 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 theGLib.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 toGLib.String.prepend
().
-
prepend_unichar
(wc)[source]¶ Parameters: wc ( str
) – a Unicode characterReturns: 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 lengthReturns: 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 selfReturns: 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.String
to 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
() orGLib.utf8_strup
() instead.
-