Package ch.bailu.gtk.glib
Class GString
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.glib.GString
- All Implemented Interfaces:
PointerInterface
The GString struct contains the public fields of a GString.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds 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... _elipse) Appends a formatted string onto the end of a #GString.void
appendPrintf
(String format, Object... _elipse) 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.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.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.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.Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
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.- See Also:
-
LEN
contains the length of the string, not including the
terminating nul byte.- See Also:
-
ALLOCATED_LEN
the number of bytes that can be stored in the
string before it needs to be reallocated. May be larger than @len.- See Also:
-
-
Constructor Details
-
GString
-
GString
public GString() -
GString
Creates a new #GString, initialized with the given string.- Parameters:
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.- Parameters:
init
- the initial text to copy into the string, or %NULL to start with an empty string
-
-
Method Details
-
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.- Parameters:
init
- initial contents of the stringlen
- length of @init to use- Returns:
- 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.- Parameters:
init
- initial contents of the stringlen
- length of @init to use- Returns:
- a 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.- Parameters:
dfl_size
- the default size of the space allocated to hold the string- Returns:
- the new #GString
-
append
Adds a string onto the end of a #GString, expanding
it if necessary.- Parameters:
val
- the string to append onto the end of @string- Returns:
- @string
-
append
Adds a string onto the end of a #GString, expanding
it if necessary.- Parameters:
val
- the string to append onto the end of @string- Returns:
- @string
-
appendC
Adds a byte onto the end of a #GString, expanding
it if necessary.- Parameters:
c
- the byte to append onto the end of @string- Returns:
- @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().- Parameters:
val
- bytes to appendlen
- number of bytes of @val to use, or -1 for all of @val- Returns:
- @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().- Parameters:
val
- bytes to appendlen
- number of bytes of @val to use, or -1 for all of @val- Returns:
- @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.- Parameters:
format
- the string format. See the printf() documentation_elipse
- 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.- Parameters:
format
- the string format. See the printf() documentation_elipse
- the parameters to insert into the format string
-
appendUnichar
Converts a Unicode character into UTF-8, and appends it
to the string.- Parameters:
wc
- a Unicode character- Returns:
- @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.- Parameters:
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- Returns:
- @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.- Parameters:
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- Returns:
- @string
-
asciiDown
Converts all uppercase ASCII letters to lowercase ASCII letters.- Returns:
- 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.- Returns:
- 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.- Parameters:
rval
- the string to copy into @string- Returns:
- @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.- Parameters:
rval
- the string to copy into @string- Returns:
- @string
-
equal
Compares two strings for equality, returning %TRUE if they are equal.
For use with #GHashTable.- Parameters:
v2
- another #GString- Returns:
- %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.- Parameters:
pos
- the position of the content to removelen
- the number of bytes to remove, or -1 to remove all following bytes- Returns:
- @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().- Parameters:
free_segment
- if %TRUE, the actual character data is freed as well- Returns:
- the character data of @string (i.e. %NULL if @free_segment is %TRUE)
-
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.- Returns:
- 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.- Returns:
- hash code for @str
-
insert
Inserts a copy of a string into a #GString,
expanding it if necessary.- Parameters:
pos
- the position to insert the copy of the stringval
- the string to insert- Returns:
- @string
-
insert
Inserts a copy of a string into a #GString,
expanding it if necessary.- Parameters:
pos
- the position to insert the copy of the stringval
- the string to insert- Returns:
- @string
-
insertC
Inserts a byte into a #GString, expanding it if necessary.- Parameters:
pos
- the position to insert the bytec
- the byte to insert- Returns:
- @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.- Parameters:
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- Returns:
- @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.- Parameters:
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- Returns:
- @string
-
insertUnichar
Converts a Unicode character into UTF-8, and insert it
into the string at the given position.- Parameters:
pos
- the position at which to insert character, or -1 to append at the end of the stringwc
- a Unicode character- Returns:
- @string
-
overwrite
Overwrites part of a string, lengthening it if necessary.- Parameters:
pos
- the position at which to start overwritingval
- the string that will overwrite the @string starting at @pos- Returns:
- @string
-
overwrite
Overwrites part of a string, lengthening it if necessary.- Parameters:
pos
- the position at which to start overwritingval
- the string that will overwrite the @string starting at @pos- Returns:
- @string
-
overwriteLen
Overwrites part of a string, lengthening it if necessary.
This function will work with embedded nuls.- Parameters:
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- Returns:
- @string
-
overwriteLen
Overwrites part of a string, lengthening it if necessary.
This function will work with embedded nuls.- Parameters:
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- Returns:
- @string
-
prepend
Adds a string on to the start of a #GString,
expanding it if necessary.- Parameters:
val
- the string to prepend on the start of @string- Returns:
- @string
-
prepend
Adds a string on to the start of a #GString,
expanding it if necessary.- Parameters:
val
- the string to prepend on the start of @string- Returns:
- @string
-
prependC
Adds a byte onto the start of a #GString,
expanding it if necessary.- Parameters:
c
- the byte to prepend on the start of the #GString- Returns:
- @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().- Parameters:
val
- bytes to prependlen
- number of bytes in @val to prepend, or -1 for all of @val- Returns:
- @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().- Parameters:
val
- bytes to prependlen
- number of bytes in @val to prepend, or -1 for all of @val- Returns:
- @string
-
prependUnichar
Converts a Unicode character into UTF-8, and prepends it
to the string.- Parameters:
wc
- a Unicode character- Returns:
- @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.- Parameters:
format
- the string format. See the printf() documentation_elipse
- 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.- Parameters:
format
- the string format. See the printf() documentation_elipse
- 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.- Parameters:
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- Returns:
- 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.- Parameters:
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- Returns:
- 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.)- Parameters:
len
- the new length- Returns:
- @string
-
truncate
Cuts off the end of the GString, leaving the first @len bytes.- Parameters:
len
- the new size of @string- Returns:
- @string
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-