Package org.gnome.glib
Class StrvBuilder
java.lang.Object
org.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 }));
- Since:
- 2.68
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newGStrvBuilderwith a reference count of 1.StrvBuilder(MemorySegment address) Create a StrvBuilder proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a string to the end of the array.voidAppends all the given strings to the builder.voidAppends 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 @Nullable TypegetType()Get the GType of the StrvBuilder classref()Atomically increments the reference count of this StrvBuilder by one.voidAdd a string to the end of the array.voidunref()Decreases the reference count onbuilder.String[]Decreases the reference count on the string vector builder, and returns its contents as aNULL-terminated string array.Methods inherited from class org.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 newGStrvBuilderwith a reference count of 1. Use g_strv_builder_unref() on the returned value when no longer needed.- Since:
- 2.68
-
-
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 - Since:
- 2.68
-
take
Add a string to the end of the array. Aftervaluebelongs to theGStrvBuilderand 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 onbuilder.In the event that there are no more references, releases all memory associated with the
GStrvBuilder.- Since:
- 2.68
-
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
- Since:
- 2.82
-