1.27 <GStrvBuilder>

Structure: <GStrvBuilder>

<GStrvBuilder> is a helper object to build a #f-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 }));

Procedures

Method: strv-builder:add self value
Method: add self value

Add a string to the end of the array.

Since 2.68

self

Passed: a <GStrvBuilder>.

a <GStrvBuilder>

value

Passed: a string.

a string.

Method: strv-builder:addv self value
Method: addv self value

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

Since 2.70

self

Passed: a <GStrvBuilder>.

a <GStrvBuilder>

value

Passed: a list or vector, each a string.

the vector of strings to add

Method: strv-builder:end self ⇒ %return
Method: end self ⇒ %return

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

self

Passed: a <GStrvBuilder>.

a <GStrvBuilder>

%return

Returned: a vector, each a string.

the constructed string array.

Since 2.68

Procedure: strv-builder:new ⇒ %return

Creates a new <GStrvBuilder> with a reference count of 1. Use strv-builder:unref on the returned value when no longer needed.

%return

Returned: a <GStrvBuilder>.

the new <GStrvBuilder>

Method: strv-builder:ref self ⇒ %return
Method: ref self ⇒ %return

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

self

Passed: a <GStrvBuilder>.

a <GStrvBuilder>

%return

Returned: a <GStrvBuilder>.

The passed in <GStrvBuilder>

Method: strv-builder:take self value
Method: take self value

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

Since 2.80

self

Passed: a <GStrvBuilder>.

a <GStrvBuilder>

value

Passed: a string.

a string. Ownership of the string is transferred to the <GStrvBuilder>

Method: strv-builder:unref self
Method: unref self

Decreases the reference count on self.

In the event that there are no more references, releases all memory associated with the <GStrvBuilder>.

self

Passed: a <GStrvBuilder>.

a <GStrvBuilder> allocated by strv-builder:new

Method: strv-builder:unref-to-strv self ⇒ %return
Method: unref-to-strv self ⇒ %return

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

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);
self

Passed: a <GStrvBuilder>.

a <GStrvBuilder>

%return

Returned: a vector, each a string.

the constructed string array