Function

GLibstrcanon

Declaration

gchar*
g_strcanon (
  gchar* string,
  const gchar* valid_chars,
  gchar substitutor
)

Description

For each character in string, if the character is not in valid_chars, replaces the character with substitutor.

Modifies string in place, and return string itself, not a copy. The return value is to allow nesting such as:

g_ascii_strup (g_strcanon (str, "abc", '?'))

In order to modify a copy, you may use g_strdup():

reformatted = g_strcanon (g_strdup (const_str), "abc", '?');

g_free (reformatted);

Parameters

string

Type: gchar*

A nul-terminated array of bytes.

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

Type: const gchar*

Bytes permitted in string.

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

Type: gchar

Replacement character for disallowed bytes.

Return value

Type: gchar*

The modified string.

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.