util_ensure_gdbus_string


Description:


[ Version ( since = "3.0" ) ]
public unowned string util_ensure_gdbus_string (string? str, string gdbus_str)

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

Parameters:

str

a possibly invalid UTF-8 string, or null

gdbus_str

return location for the corrected string

Returns:

a valid UTF-8 string


Namespace: E