### Function

# Gimp any_to_utf8

#### Declaration [src]

    gchar*
    gimp_any_to_utf8 (
      const gchar* str,
      gssize len,
      const gchar* warning_format,
      ...
    )

#### Description [src]

This function takes any string (UTF-8 or not) and always returns a valid UTF-8 string.

If `str` is valid UTF-8, a copy of the string is returned.

If UTF-8 validation fails, `g_locale_to_utf8()` is tried and if it succeeds the resulting string is returned.

Otherwise, the portion of `str` that is UTF-8, concatenated with “(invalid UTF-8 string)” is returned. If not even the start of `str` is valid UTF-8, only “(invalid UTF-8 string)” is returned.

This function is not directly available to language bindings

#### Parameters

`str` | An array of `gchar`
| The string to be converted to UTF-8.
| The length of the array is specified in the `len` argument.
| The data is owned by the caller of the function.
| Each element is a NUL terminated UTF-8 string.
`len` | `gssize`
| The length of the string, or -1 if the string is nul-terminated.
`warning_format` | `const gchar*`
| The message format for the warning message if conversion to UTF-8 fails. See the printf() documentation.
| The data is owned by the caller of the function.
| The value is a NUL terminated UTF-8 string.
`...` | ``
| The parameters to insert into the format string.

#### Return value

Returns: | `gchar*`
| The UTF-8 string as described above.
| The caller of the function takes ownership of the data, and is responsible for freeing it.
| The value is a NUL terminated UTF-8 string.