Function

GLibVariantnew_parsed

Declaration

GVariant*
g_variant_new_parsed (
  const gchar* format,
  ...
)

Description

Parses format and returns the result.

format must be a text format GVariant with one extension: at any point that a value may appear in the text, a ‘%’ character followed by a GVariant format string (as per g_variant_new()) may appear. In that case, the same arguments are collected from the argument list as g_variant_new() would have collected.

Note that the arguments must be of the correct width for their types specified in format. This can be achieved by casting them. See the [GVariant varargs documentation][gvariant-varargs].

Consider this simple example:

 g_variant_new_parsed ("[('one', 1), ('two', %i), (%s, 3)]", 2, "three");

In the example, the variable argument parameters are collected and filled in as if they were part of the original string to produce the result of

[('one', 1), ('two', 2), ('three', 3)]

This function is intended only to be used with format as a string literal. Any parse error is fatal to the calling process. If you want to parse data from untrusted sources, use g_variant_parse().

You may not use this function to return, unmodified, a single GVariant pointer from the argument list. ie: format may not solely be anything along the lines of “%*”, “%?”, “\%r”, or anything starting with “%@”.

Parameters

format const gchar*
 

A text format GVariant.

 The data is owned by the caller of the function.
 The string is a NUL terminated UTF-8 string.
... none
 

Arguments as per format.

Return value

Returns: GVariant
 

A new floating GVariant instance.

 The caller of the function takes ownership of the data, and is responsible for freeing it.