Package org.gnome.glib
Class StrvBuilder
java.lang.Object
io.github.jwharm.javagi.base.ProxyInstance
org.gnome.glib.StrvBuilder
- All Implemented Interfaces:
Proxy
GStrvBuilder
is a helper object to build a null
-terminated string arrays.
The following example shows how to build a two element array:
g_autoptr(GStrvBuilder) builder = g_strv_builder_new ();
g_strv_builder_add (builder, "hello");
g_strv_builder_add (builder, "world");
g_auto(GStrv) array = g_strv_builder_end (builder);
g_assert_true (g_strv_equal (array, (const char *[]) { "hello", "world", NULL }));
-
Constructor Summary
ConstructorDescriptionCreates a newGStrvBuilder
with a reference count of 1.StrvBuilder
(MemorySegment address) Create a StrvBuilder proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a string to the end of the array.void
Appends all the given strings to the builder.void
Appends all the strings in the given vector to the builder.String[]
end()
Ends the builder process and returns the constructed NULL-terminated string array.static Type
getType()
Get the GType of the StrvBuilder classref()
Atomically increments the reference count of this StrvBuilder by one.void
Add a string to the end of the array.void
unref()
Decreases the reference count on this StrvBuilder.String[]
Decreases the reference count on the string vector builder, and returns its contents as aNULL
-terminated string array.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
StrvBuilder
Create a StrvBuilder proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
StrvBuilder
public StrvBuilder()Creates a newGStrvBuilder
with a reference count of 1. Use g_strv_builder_unref() on the returned value when no longer needed.
-
-
Method Details
-
getType
-
add
Add a string to the end of the array.Since 2.68
- Parameters:
value
- a string.
-
addMany
Appends all the given strings to the builder.Since 2.70
- Parameters:
varargs
- one or more strings followed bynull
-
addv
Appends all the strings in the given vector to the builder.Since 2.70
- Parameters:
value
- the vector of strings to add
-
end
Ends the builder process and returns the constructed NULL-terminated string array. The returned value should be freed with g_strfreev() when no longer needed.- Returns:
- the constructed string array.
Since 2.68
-
ref
Atomically increments the reference count of this StrvBuilder by one. This function is thread-safe and may be called from any thread.- Returns:
- The passed in
GStrvBuilder
-
take
Add a string to the end of the array. Aftervalue
belongs to theGStrvBuilder
and may no longer be modified by the caller.Since 2.80
- Parameters:
value
- a string. Ownership of the string is transferred to theGStrvBuilder
-
unref
public void unref()Decreases the reference count on this StrvBuilder.In the event that there are no more references, releases all memory associated with the
GStrvBuilder
. -
unrefToStrv
Decreases the reference count on the string vector builder, and returns its contents as aNULL
-terminated string array.This function is especially useful for cases where it's not possible to use
g_autoptr()
.GStrvBuilder *builder = g_strv_builder_new (); g_strv_builder_add (builder, "hello"); g_strv_builder_add (builder, "world"); GStrv array = g_strv_builder_unref_to_strv (builder); g_assert_true (g_strv_equal (array, (const char *[]) { "hello", "world", NULL })); g_strfreev (array);
- Returns:
- the constructed string array
-