Klasse GString

Alle implementierten Schnittstellen:
PointerInterface

public class GString extends Record
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.

https://docs.gtk.org/glib/struct.GString.html

  • Felddetails

    • STR

      public static final String 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

      public static final String LEN
      contains the length of the string, not including the
      terminating nul byte.
      Siehe auch:
    • ALLOCATED_LEN

      public static final String 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

      public GString(PointerContainer pointer)
    • GString

      public GString()
    • GString

      public GString(@Nullable Str init)
      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

      public GString(String init)
      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

      public static ClassHandler getClassHandler()
    • setFieldStr

      public void setFieldStr(Str 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.
    • getFieldStr

      public Str 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

      public static GString newLenGString(@Nonnull Str init, long 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.

      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 string
      len - length of @init to use
      Gibt zurück:
      a new #GString
    • newLenGString

      public static GString newLenGString(String init, long 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.

      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 string
      len - length of @init to use
      Gibt zurück:
      a new #GString
    • newTakeGString

      public static GString newTakeGString(@Nullable Str init)
      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

      public static GString sizedNewGString(long dfl_size)
      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

      public GString append(@Nonnull Str val)
      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

      public GString append(String val)
      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

      public GString appendC(byte c)
      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

      public GString appendLen(@Nonnull Str val, long len)
      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 append
      len - number of bytes of @val to use, or -1 for all of @val
      Gibt zurück:
      @string
    • appendLen

      public GString appendLen(String val, long len)
      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 append
      len - number of bytes of @val to use, or -1 for all of @val
      Gibt zurück:
      @string
    • appendPrintf

      public void appendPrintf(@Nonnull Str format, Object... _ellipsis)
      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

      public void appendPrintf(String format, Object... _ellipsis)
      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

      public GString appendUnichar(byte wc)
      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 string
      reserved_chars_allowed - a string of reserved characters allowed to be used, or %NULL
      allow_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 string
      reserved_chars_allowed - a string of reserved characters allowed to be used, or %NULL
      allow_utf8 - set %TRUE if the escaped string may include UTF8 characters
      Gibt zurück:
      @string
    • asciiDown

      public GString 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

      public GString 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

      public GString assign(@Nonnull Str 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.
      Parameter:
      rval - the string to copy into @string
      Gibt zurück:
      @string
    • assign

      public GString 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.
      Parameter:
      rval - the string to copy into @string
      Gibt zurück:
      @string
    • down

      @Deprecated public GString down()
      Veraltet.
      Converts a #GString to lowercase.
      Gibt zurück:
      the #GString
    • equal

      public boolean equal(@Nonnull GString v2)
      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

      public GString erase(long pos, long len)
      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 remove
      len - the number of bytes to remove, or -1 to remove all following bytes
      Gibt zurück:
      @string
    • free

      public Str free(boolean free_segment)
      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

      public Str 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

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

      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

      public GString insert(long pos, @Nonnull Str val)
      Inserts a copy of a string into a #GString,
      expanding it if necessary.
      Parameter:
      pos - the position to insert the copy of the string
      val - the string to insert
      Gibt zurück:
      @string
    • insert

      public GString insert(long pos, String val)
      Inserts a copy of a string into a #GString,
      expanding it if necessary.
      Parameter:
      pos - the position to insert the copy of the string
      val - the string to insert
      Gibt zurück:
      @string
    • insertC

      public GString insertC(long pos, byte c)
      Inserts a byte into a #GString, expanding it if necessary.
      Parameter:
      pos - the position to insert the byte
      c - the byte to insert
      Gibt zurück:
      @string
    • insertLen

      public GString insertLen(long pos, @Nonnull Str val, long len)
      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 end
      val - bytes to insert
      len - number of bytes of @val to insert, or -1 for all of @val
      Gibt zurück:
      @string
    • insertLen

      public GString insertLen(long pos, String val, long len)
      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 end
      val - bytes to insert
      len - number of bytes of @val to insert, or -1 for all of @val
      Gibt zurück:
      @string
    • insertUnichar

      public GString insertUnichar(long pos, byte wc)
      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 string
      wc - a Unicode character
      Gibt zurück:
      @string
    • overwrite

      public GString overwrite(long pos, @Nonnull Str val)
      Overwrites part of a string, lengthening it if necessary.
      Parameter:
      pos - the position at which to start overwriting
      val - the string that will overwrite the @string starting at @pos
      Gibt zurück:
      @string
    • overwrite

      public GString overwrite(long pos, String val)
      Overwrites part of a string, lengthening it if necessary.
      Parameter:
      pos - the position at which to start overwriting
      val - the string that will overwrite the @string starting at @pos
      Gibt zurück:
      @string
    • overwriteLen

      public GString overwriteLen(long pos, @Nonnull Str val, long len)
      Overwrites part of a string, lengthening it if necessary.
      This function will work with embedded nuls.
      Parameter:
      pos - the position at which to start overwriting
      val - the string that will overwrite the @string starting at @pos
      len - the number of bytes to write from @val
      Gibt zurück:
      @string
    • overwriteLen

      public GString overwriteLen(long pos, String val, long len)
      Overwrites part of a string, lengthening it if necessary.
      This function will work with embedded nuls.
      Parameter:
      pos - the position at which to start overwriting
      val - the string that will overwrite the @string starting at @pos
      len - the number of bytes to write from @val
      Gibt zurück:
      @string
    • prepend

      public GString prepend(@Nonnull Str val)
      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

      public GString prepend(String val)
      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

      public GString prependC(byte c)
      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

      public GString prependLen(@Nonnull Str val, long len)
      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 prepend
      len - number of bytes in @val to prepend, or -1 for all of @val
      Gibt zurück:
      @string
    • prependLen

      public GString prependLen(String val, long len)
      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 prepend
      len - number of bytes in @val to prepend, or -1 for all of @val
      Gibt zurück:
      @string
    • prependUnichar

      public GString prependUnichar(byte wc)
      Converts a Unicode character into UTF-8, and prepends it
      to the string.
      Parameter:
      wc - a Unicode character
      Gibt zurück:
      @string
    • printf

      public void printf(@Nonnull Str format, Object... _ellipsis)
      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

      public void printf(String format, Object... _ellipsis)
      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

      public int replace(@Nonnull Str find, @Nonnull Str replace, int 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.

      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 @string
      replace - the string to insert in place of @find
      limit - 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

      public int replace(String find, String replace, int 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.

      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 @string
      replace - the string to insert in place of @find
      limit - 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

      public GString setSize(long 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.)
      Parameter:
      len - the new length
      Gibt zurück:
      @string
    • truncate

      public GString truncate(long len)
      Cuts off the end of the GString, leaving the first @len bytes.
      Parameter:
      len - the new size of @string
      Gibt zurück:
      @string
    • up

      @Deprecated public GString up()
      Veraltet.
      Converts a #GString to uppercase.
      Gibt zurück:
      @string
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()