Class GString

All Implemented Interfaces:
PointerInterface

public class GString extends Record
The GString struct contains the public fields of a GString.

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

  • Field Details

    • 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.
      See Also:
    • LEN

      public static final String LEN
      contains the length of the string, not including the
      terminating nul byte.
      See Also:
    • 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.
      See Also:
  • Constructor Details

    • GString

      public GString(PointerContainer pointer)
    • GString

      public GString()
    • GString

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

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

      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.
      Parameters:
      init - initial contents of the string
      len - length of @init to use
      Returns:
      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.
      Parameters:
      init - initial contents of the string
      len - length of @init to use
      Returns:
      a 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.
      Parameters:
      dfl_size - the default size of the space allocated to hold the string
      Returns:
      the new #GString
    • append

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

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

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

      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().
      Parameters:
      val - bytes to append
      len - number of bytes of @val to use, or -1 for all of @val
      Returns:
      @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().
      Parameters:
      val - bytes to append
      len - number of bytes of @val to use, or -1 for all of @val
      Returns:
      @string
    • appendPrintf

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

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

      public GString appendUnichar(byte wc)
      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 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
      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 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
      Returns:
      @string
    • asciiDown

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

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

      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.
      Parameters:
      rval - the string to copy into @string
      Returns:
      @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.
      Parameters:
      rval - the string to copy into @string
      Returns:
      @string
    • equal

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

      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.
      Parameters:
      pos - the position of the content to remove
      len - the number of bytes to remove, or -1 to remove all following bytes
      Returns:
      @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().
      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

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

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

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

      public GString insertC(long pos, byte c)
      Inserts a byte into a #GString, expanding it if necessary.
      Parameters:
      pos - the position to insert the byte
      c - the byte to insert
      Returns:
      @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.
      Parameters:
      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
      Returns:
      @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.
      Parameters:
      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
      Returns:
      @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.
      Parameters:
      pos - the position at which to insert character, or -1 to append at the end of the string
      wc - a Unicode character
      Returns:
      @string
    • overwrite

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

      public GString overwrite(long pos, String val)
      Overwrites part of a string, lengthening it if necessary.
      Parameters:
      pos - the position at which to start overwriting
      val - the string that will overwrite the @string starting at @pos
      Returns:
      @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.
      Parameters:
      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
      Returns:
      @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.
      Parameters:
      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
      Returns:
      @string
    • prepend

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

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

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

      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().
      Parameters:
      val - bytes to prepend
      len - number of bytes in @val to prepend, or -1 for all of @val
      Returns:
      @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().
      Parameters:
      val - bytes to prepend
      len - number of bytes in @val to prepend, or -1 for all of @val
      Returns:
      @string
    • prependUnichar

      public GString prependUnichar(byte wc)
      Converts a Unicode character into UTF-8, and prepends it
      to the string.
      Parameters:
      wc - a Unicode character
      Returns:
      @string
    • printf

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

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

      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.
      Parameters:
      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
      Returns:
      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.
      Parameters:
      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
      Returns:
      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.)
      Parameters:
      len - the new length
      Returns:
      @string
    • truncate

      public GString truncate(long len)
      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

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()