### Function

# EDataServer util_ensure_gdbus_string

since: 3.0

#### Declaration [src]

    const gchar*
    e_util_ensure_gdbus_string (
      const gchar* str,
      gchar** gdbus_str
    )

#### Description [src]

If `str` is a valid UTF-8 string, the function returns `str` and does not set `gdbus_str`.

If `str` is an invalid UTF-8 string, the function calls `e_util_utf8_make_valid()` and points `gdbus_str` to the newly-allocated, valid UTF-8 string, and also returns it. The caller should free the string pointed to by `gdbus_str` with g_free().

If `str` is `NULL`, the function returns an empty string and does not set `gdbus_str`.

Admittedly, the function semantics are a little awkward. The example below illustrates the easiest way to cope with the `gdbus_str` argument:

        const gchar *trusted_utf8;
        gchar *allocated = NULL;

        trusted_utf8 = e_util_ensure_gdbus_string (untrusted_utf8, &allocated);

        Do stuff with trusted_utf8, then clear it.

        trusted_utf8 = NULL;

        g_free (allocated);
        allocated = NULL;

Available since: 3.0

#### Parameters

`str`

  Type: `const gchar*`

  A possibly invalid UTF-8 string, or `NULL`.

  The argument can be `NULL`.
  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`gdbus_str`

  Type: `gchar**`

  Return location for the corrected string.

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

#### Return value

Type: `const gchar*`

A valid UTF-8 string.

The data is owned by the called function.
The value is a NUL terminated UTF-8 string.