Package ch.bailu.gtk.glib
Klasse GString
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.glib.GString
- Alle implementierten Schnittstellen:
PointerInterface
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.
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.
-
Feldübersicht
Felder -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungAdds a string onto the end of a #GString, expanding
it if necessary.Adds a string onto the end of a #GString, expanding
it if necessary.appendC
(byte c) Adds a byte onto the end of a #GString, expanding
it if necessary.Appends @len bytes of @val to @string.Appends @len bytes of @val to @string.void
appendPrintf
(Str format, Object... _ellipsis) Appends a formatted string onto the end of a #GString.void
appendPrintf
(String format, Object... _ellipsis) Appends a formatted string onto the end of a #GString.appendUnichar
(byte wc) Converts a Unicode character into UTF-8, and appends it
to the string.appendUriEscaped
(Str unescaped, Str reserved_chars_allowed, boolean allow_utf8) Appends @unescaped to @string, escaping any characters that
are reserved in URIs using URI-style escape sequences.appendUriEscaped
(String unescaped, String reserved_chars_allowed, boolean allow_utf8) Appends @unescaped to @string, escaping any characters that
are reserved in URIs using URI-style escape sequences.Converts all uppercase ASCII letters to lowercase ASCII letters.asciiUp()
Converts all lowercase ASCII letters to uppercase ASCII letters.Copies the bytes from a string into a #GString,
destroying any previous contents.Copies the bytes from a string into a #GString,
destroying any previous contents.down()
Veraltet.boolean
Compares two strings for equality, returning %TRUE if they are equal.erase
(long pos, long len) Removes @len bytes from a #GString, starting at position @pos.free
(boolean free_segment) Frees the memory allocated for the #GString.Frees the memory allocated for the #GString.Transfers ownership of the contents of @string to a newly allocated
#GBytes.static ClassHandler
long
the number of bytes that can be stored in the
string before it needs to be reallocated.long
contains the length of the string, not including the
terminating nul byte.points to the character data.static int
static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
int
hash()
Creates a hash code for @str; for use with #GHashTable.Inserts a copy of a string into a #GString,
expanding it if necessary.Inserts a copy of a string into a #GString,
expanding it if necessary.insertC
(long pos, byte c) Inserts a byte into a #GString, expanding it if necessary.Inserts @len bytes of @val into @string at @pos.Inserts @len bytes of @val into @string at @pos.insertUnichar
(long pos, byte wc) Converts a Unicode character into UTF-8, and insert it
into the string at the given position.static GString
newLenGString
(Str init, long len) Creates a new #GString with @len bytes of the @init buffer.static GString
newLenGString
(String init, long len) Creates a new #GString with @len bytes of the @init buffer.static GString
newTakeGString
(Str init) Creates a new #GString, initialized with the given string.Overwrites part of a string, lengthening it if necessary.Overwrites part of a string, lengthening it if necessary.overwriteLen
(long pos, Str val, long len) Overwrites part of a string, lengthening it if necessary.overwriteLen
(long pos, String val, long len) Overwrites part of a string, lengthening it if necessary.Adds a string on to the start of a #GString,
expanding it if necessary.Adds a string on to the start of a #GString,
expanding it if necessary.prependC
(byte c) Adds a byte onto the start of a #GString,
expanding it if necessary.prependLen
(Str val, long len) Prepends @len bytes of @val to @string.prependLen
(String val, long len) Prepends @len bytes of @val to @string.prependUnichar
(byte wc) Converts a Unicode character into UTF-8, and prepends it
to the string.void
Writes a formatted string into a #GString.void
Writes a formatted string into a #GString.int
Replaces the string @find with the string @replace in a #GString up to
@limit times.int
Replaces the string @find with the string @replace in a #GString up to
@limit times.void
setFieldAllocatedLen
(long allocated_len) the number of bytes that can be stored in the
string before it needs to be reallocated.void
setFieldLen
(long len) contains the length of the string, not including the
terminating nul byte.void
setFieldStr
(Str str) points to the character data.setSize
(long len) Sets the length of a #GString.static GString
sizedNewGString
(long dfl_size) Creates a new #GString, with enough space for @dfl_size
bytes.truncate
(long len) Cuts off the end of the GString, leaving the first @len bytes.up()
Veraltet.Von Klasse geerbte Methoden ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Von Klasse geerbte Methoden ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Von Klasse geerbte Methoden java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Von Schnittstelle geerbte Methoden ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Felddetails
-
STR
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.- Siehe auch:
-
LEN
contains the length of the string, not including the
terminating nul byte.- Siehe auch:
-
ALLOCATED_LEN
the number of bytes that can be stored in the
string before it needs to be reallocated. May be larger than @len.- Siehe auch:
-
-
Konstruktordetails
-
GString
-
GString
public GString() -
GString
Creates a new #GString, initialized with the given string.- Parameter:
init
- the initial text to copy into the string, or %NULL to start with an empty string
-
GString
Creates a new #GString, initialized with the given string.- Parameter:
init
- the initial text to copy into the string, or %NULL to start with an empty string
-
-
Methodendetails
-
getClassHandler
-
setFieldStr
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. -
getFieldStr
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. -
setFieldLen
public void setFieldLen(long len) contains the length of the string, not including the
terminating nul byte. -
getFieldLen
public long getFieldLen()contains the length of the string, not including the
terminating nul byte. -
setFieldAllocatedLen
public void setFieldAllocatedLen(long allocated_len) the number of bytes that can be stored in the
string before it needs to be reallocated. May be larger than @len. -
getFieldAllocatedLen
public long getFieldAllocatedLen()the number of bytes that can be stored in the
string before it needs to be reallocated. May be larger than @len. -
newLenGString
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.
Since this function does not stop at nul bytes, it is the caller's
responsibility to ensure that @init has at least @len addressable
bytes.- Parameter:
init
- initial contents of the stringlen
- length of @init to use- Gibt zurück:
- a new #GString
-
newLenGString
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.
Since this function does not stop at nul bytes, it is the caller's
responsibility to ensure that @init has at least @len addressable
bytes.- Parameter:
init
- initial contents of the stringlen
- length of @init to use- Gibt zurück:
- a new #GString
-
newTakeGString
Creates a new #GString, initialized with the given string.
After this call, @init belongs to the #GString and may no longer be
modified by the caller. The memory of @data has to be dynamically
allocated and will eventually be freed with g_free().- Parameter:
init
- initial text used as the string. Ownership of the string is transferred to the #GString. Passing %NULL creates an empty string.- Gibt zurück:
- the new #GString
-
sizedNewGString
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.- Parameter:
dfl_size
- the default size of the space allocated to hold the string- Gibt zurück:
- the new #GString
-
append
Adds a string onto the end of a #GString, expanding
it if necessary.- Parameter:
val
- the string to append onto the end of @string- Gibt zurück:
- @string
-
append
Adds a string onto the end of a #GString, expanding
it if necessary.- Parameter:
val
- the string to append onto the end of @string- Gibt zurück:
- @string
-
appendC
Adds a byte onto the end of a #GString, expanding
it if necessary.- Parameter:
c
- the byte to append onto the end of @string- Gibt zurück:
- @string
-
appendLen
Appends @len bytes of @val to @string.
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 g_string_append_len() equivalent to g_string_append().- Parameter:
val
- bytes to appendlen
- number of bytes of @val to use, or -1 for all of @val- Gibt zurück:
- @string
-
appendLen
Appends @len bytes of @val to @string.
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 g_string_append_len() equivalent to g_string_append().- Parameter:
val
- bytes to appendlen
- number of bytes of @val to use, or -1 for all of @val- Gibt zurück:
- @string
-
appendPrintf
Appends a formatted string onto the end of a #GString.
This function is similar to g_string_printf() except
that the text is appended to the #GString.- Parameter:
format
- the string format. See the printf() documentation_ellipsis
- the parameters to insert into the format string
-
appendPrintf
Appends a formatted string onto the end of a #GString.
This function is similar to g_string_printf() except
that the text is appended to the #GString.- Parameter:
format
- the string format. See the printf() documentation_ellipsis
- the parameters to insert into the format string
-
appendUnichar
Converts a Unicode character into UTF-8, and appends it
to the string.- Parameter:
wc
- a Unicode character- Gibt zurück:
- @string
-
appendUriEscaped
public GString appendUriEscaped(@Nonnull Str unescaped, @Nonnull Str reserved_chars_allowed, boolean allow_utf8) Appends @unescaped to @string, escaping any characters that
are reserved in URIs using URI-style escape sequences.- Parameter:
unescaped
- a stringreserved_chars_allowed
- a string of reserved characters allowed to be used, or %NULLallow_utf8
- set %TRUE if the escaped string may include UTF8 characters- Gibt zurück:
- @string
-
appendUriEscaped
public GString appendUriEscaped(String unescaped, String reserved_chars_allowed, boolean allow_utf8) Appends @unescaped to @string, escaping any characters that
are reserved in URIs using URI-style escape sequences.- Parameter:
unescaped
- a stringreserved_chars_allowed
- a string of reserved characters allowed to be used, or %NULLallow_utf8
- set %TRUE if the escaped string may include UTF8 characters- Gibt zurück:
- @string
-
asciiDown
Converts all uppercase ASCII letters to lowercase ASCII letters.- Gibt zurück:
- passed-in @string pointer, with all the uppercase characters converted to lowercase in place, with semantics that exactly match g_ascii_tolower().
-
asciiUp
Converts all lowercase ASCII letters to uppercase ASCII letters.- Gibt zurück:
- passed-in @string pointer, with all the lowercase characters converted to uppercase in place, with semantics that exactly match g_ascii_toupper().
-
assign
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.- Parameter:
rval
- the string to copy into @string- Gibt zurück:
- @string
-
assign
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.- Parameter:
rval
- the string to copy into @string- Gibt zurück:
- @string
-
down
Veraltet.Converts a #GString to lowercase.- Gibt zurück:
- the #GString
-
equal
Compares two strings for equality, returning %TRUE if they are equal.
For use with #GHashTable.- Parameter:
v2
- another #GString- Gibt zurück:
- %TRUE if the strings are the same length and contain the same bytes
-
erase
Removes @len bytes from a #GString, starting at position @pos.
The rest of the #GString is shifted down to fill the gap.- Parameter:
pos
- the position of the content to removelen
- the number of bytes to remove, or -1 to remove all following bytes- Gibt zurück:
- @string
-
free
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().
Instead of passing %FALSE to this function, consider using
g_string_free_and_steal().- Parameter:
free_segment
- if %TRUE, the actual character data is freed as well- Gibt zurück:
- the character data of @string (i.e. %NULL if @free_segment is %TRUE)
-
freeAndSteal
Frees the memory allocated for the #GString.
The caller gains ownership of the buffer and
must free it after use with g_free().- Gibt zurück:
- the character data of @string
-
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.
Note that while #GString ensures that its buffer always has a
trailing nul character (not reflected in its "len"), the returned
#GBytes does not include this extra nul; i.e. it has length exactly
equal to the "len" member.- Gibt zurück:
- A newly allocated #GBytes containing contents of @string; @string itself is freed
-
hash
public int hash()Creates a hash code for @str; for use with #GHashTable.- Gibt zurück:
- hash code for @str
-
insert
Inserts a copy of a string into a #GString,
expanding it if necessary.- Parameter:
pos
- the position to insert the copy of the stringval
- the string to insert- Gibt zurück:
- @string
-
insert
Inserts a copy of a string into a #GString,
expanding it if necessary.- Parameter:
pos
- the position to insert the copy of the stringval
- the string to insert- Gibt zurück:
- @string
-
insertC
Inserts a byte into a #GString, expanding it if necessary.- Parameter:
pos
- the position to insert the bytec
- the byte to insert- Gibt zurück:
- @string
-
insertLen
Inserts @len bytes of @val into @string 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.- Parameter:
pos
- position in @string where insertion should happen, or -1 for at the endval
- bytes to insertlen
- number of bytes of @val to insert, or -1 for all of @val- Gibt zurück:
- @string
-
insertLen
Inserts @len bytes of @val into @string 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.- Parameter:
pos
- position in @string where insertion should happen, or -1 for at the endval
- bytes to insertlen
- number of bytes of @val to insert, or -1 for all of @val- Gibt zurück:
- @string
-
insertUnichar
Converts a Unicode character into UTF-8, and insert it
into the string at the given position.- Parameter:
pos
- the position at which to insert character, or -1 to append at the end of the stringwc
- a Unicode character- Gibt zurück:
- @string
-
overwrite
Overwrites part of a string, lengthening it if necessary.- Parameter:
pos
- the position at which to start overwritingval
- the string that will overwrite the @string starting at @pos- Gibt zurück:
- @string
-
overwrite
Overwrites part of a string, lengthening it if necessary.- Parameter:
pos
- the position at which to start overwritingval
- the string that will overwrite the @string starting at @pos- Gibt zurück:
- @string
-
overwriteLen
Overwrites part of a string, lengthening it if necessary.
This function will work with embedded nuls.- Parameter:
pos
- the position at which to start overwritingval
- the string that will overwrite the @string starting at @poslen
- the number of bytes to write from @val- Gibt zurück:
- @string
-
overwriteLen
Overwrites part of a string, lengthening it if necessary.
This function will work with embedded nuls.- Parameter:
pos
- the position at which to start overwritingval
- the string that will overwrite the @string starting at @poslen
- the number of bytes to write from @val- Gibt zurück:
- @string
-
prepend
Adds a string on to the start of a #GString,
expanding it if necessary.- Parameter:
val
- the string to prepend on the start of @string- Gibt zurück:
- @string
-
prepend
Adds a string on to the start of a #GString,
expanding it if necessary.- Parameter:
val
- the string to prepend on the start of @string- Gibt zurück:
- @string
-
prependC
Adds a byte onto the start of a #GString,
expanding it if necessary.- Parameter:
c
- the byte to prepend on the start of the #GString- Gibt zurück:
- @string
-
prependLen
Prepends @len bytes of @val to @string.
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 g_string_prepend_len() equivalent to g_string_prepend().- Parameter:
val
- bytes to prependlen
- number of bytes in @val to prepend, or -1 for all of @val- Gibt zurück:
- @string
-
prependLen
Prepends @len bytes of @val to @string.
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 g_string_prepend_len() equivalent to g_string_prepend().- Parameter:
val
- bytes to prependlen
- number of bytes in @val to prepend, or -1 for all of @val- Gibt zurück:
- @string
-
prependUnichar
Converts a Unicode character into UTF-8, and prepends it
to the string.- Parameter:
wc
- a Unicode character- Gibt zurück:
- @string
-
printf
Writes a formatted string into a #GString.
This is similar to the standard sprintf() function,
except that the #GString buffer automatically expands
to contain the results. The previous contents of the
#GString are destroyed.- Parameter:
format
- the string format. See the printf() documentation_ellipsis
- the parameters to insert into the format string
-
printf
Writes a formatted string into a #GString.
This is similar to the standard sprintf() function,
except that the #GString buffer automatically expands
to contain the results. The previous contents of the
#GString are destroyed.- Parameter:
format
- the string format. See the printf() documentation_ellipsis
- the parameters to insert into the format string
-
replace
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.
If @find is the empty string, since versions 2.69.1 and 2.68.4 the
replacement will be inserted no more than once per possible position
(beginning of string, end of string and between characters). This did
not work correctly in earlier versions.- Parameter:
find
- the string to find in @stringreplace
- the string to insert in place of @findlimit
- the maximum instances of @find to replace with @replace, or `0` for no limit- Gibt zurück:
- the number of find and replace operations performed.
-
replace
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.
If @find is the empty string, since versions 2.69.1 and 2.68.4 the
replacement will be inserted no more than once per possible position
(beginning of string, end of string and between characters). This did
not work correctly in earlier versions.- Parameter:
find
- the string to find in @stringreplace
- the string to insert in place of @findlimit
- the maximum instances of @find to replace with @replace, or `0` for no limit- Gibt zurück:
- the number of find and replace operations performed.
-
setSize
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.)- Parameter:
len
- the new length- Gibt zurück:
- @string
-
truncate
Cuts off the end of the GString, leaving the first @len bytes.- Parameter:
len
- the new size of @string- Gibt zurück:
- @string
-
up
Veraltet.Converts a #GString to uppercase.- Gibt zurück:
- @string
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-