GLib.StrvBuilder

Fields

None

Methods

class

new ()

add (value)

addv (value)

end ()

ref ()

take (value)

unref ()

unref_to_strv ()

Details

class GLib.StrvBuilder

GStrvBuilder is a helper object to build a None-terminated string arrays.

The following example shows how to build a two element array:

```c g_autoptr(GLib.StrvBuilder) builder = GLib.StrvBuilder.new (); GLib.StrvBuilder.add (builder, “hello”); GLib.StrvBuilder.add (builder, “world”);

g_auto(GStrv) array = GLib.StrvBuilder.end (builder);

g_assert_true (GLib.strv_equal (array, (const str *[]) { “hello”, “world”, None })); ```

New in version 2.68.

classmethod new()[source]
Returns:

the new GLib.StrvBuilder

Return type:

GLib.StrvBuilder

Creates a new GLib.StrvBuilder with a reference count of 1. Use GLib.StrvBuilder.unref() on the returned value when no longer needed.

New in version 2.68.

add(value)[source]
Parameters:

value (str) – a string.

Add a string to the end of the array.

New in version 2.68.

addv(value)[source]
Parameters:

value ([str]) – the vector of strings to add

Appends all the strings in the given vector to the builder.

New in version 2.70.

end()[source]
Returns:

the constructed string array.

Return type:

[str]

Ends the builder process and returns the constructed None-terminated string array. The returned value should be freed with GLib.strfreev() when no longer needed.

ref()[source]
Returns:

The passed in GLib.StrvBuilder

Return type:

GLib.StrvBuilder

Atomically increments the reference count of self by one. This function is thread-safe and may be called from any thread.

New in version 2.68.

take(value)[source]
Parameters:

value (str) – a string. Ownership of the string is transferred to the GLib.StrvBuilder

Add a string to the end of the array. After value belongs to the GLib.StrvBuilder and may no longer be modified by the caller.

New in version 2.80.

unref()[source]

Decreases the reference count on self.

In the event that there are no more references, releases all memory associated with the GLib.StrvBuilder.

New in version 2.68.

unref_to_strv()[source]
Returns:

the constructed string array

Return type:

[str]

Decreases the reference count on the string vector builder, and returns its contents as a NULL-terminated string array.

This function is especially useful for cases where it’s not possible to use g_autoptr().

```c GLib.StrvBuilder *builder = GLib.StrvBuilder.new (); GLib.StrvBuilder.add (builder, “hello”); GLib.StrvBuilder.add (builder, “world”);

GStrv array = GLib.StrvBuilder.unref_to_strv (builder);

g_assert_true (GLib.strv_equal (array, (const str *[]) { “hello”, “world”, None }));

GLib.strfreev (array); ```

New in version 2.82.