* mu-str: add mu_str_remove_ctrl_in_place

This commit is contained in:
djcb 2013-06-24 22:41:34 +03:00
parent 6ac32efd6d
commit 6783e448aa
2 changed files with 40 additions and 0 deletions

View File

@ -996,3 +996,31 @@ errexit:
g_hash_table_destroy (hash);
return NULL;
}
char *
mu_str_remove_ctrl_in_place (char *str)
{
char *cur;
g_return_val_if_fail (str, NULL);
for (cur = str; *cur; ++cur) {
GString *gstr;
if (!iscntrl(*cur))
continue;
/* control char detected... */
gstr = g_string_sized_new (strlen (str));
for (cur = str; *cur; ++cur)
if (!iscntrl (*cur))
g_string_append_c (gstr, *cur);
memcpy (str, gstr->str, gstr->len); /* fits */
break;
}
return str;
}

View File

@ -342,6 +342,18 @@ const gchar* mu_str_subject_normalize (const gchar* str);
gchar* mu_str_quoted_from_strv (const gchar **params);
/**
* Remove control characters from a string
*
* @param str a string
*
* @return the str with control characters removed
*/
char* mu_str_remove_ctrl_in_place (char *str);
/** @} */
G_END_DECLS