Function

GLibstrcanon

Declaration [src]

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

Description [src]

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 gchar*
 

A nul-terminated array of bytes.

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

Bytes permitted in string.

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

Replacement character for disallowed bytes.

Return value

Returns: gchar*
 

The modified string.

 The caller of the function takes ownership of the data, and is responsible for freeing it.
 The string is a NUL terminated UTF-8 string.