Class (GI Struct)

GLib-2.0GLibStrvBuilderSince 2.68

GLib.StrvBuilder 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 }));

2.68

Index

Constructors

Properties

Methods

Constructors

Properties

Methods

  • Add a string to the end of the array.

    Since 2.68

    Parameters

    • value: string

      a string.

    Returns void

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

    Since 2.70

    Parameters

    • value: string[]

      the vector of strings to add

    Returns void

  • 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 string[]

    the constructed string array. Since 2.68

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

    Since 2.80

    Parameters

    • value: string

      a string. Ownership of the string is transferred to the GLib.StrvBuilder

    Returns void

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

    Returns string[]

    the constructed string array