mirror of https://github.com/djcb/mu.git
* mu-str: add mu_str_remove_ctrl_in_place
This commit is contained in:
parent
6ac32efd6d
commit
6783e448aa
28
lib/mu-str.c
28
lib/mu-str.c
|
@ -996,3 +996,31 @@ errexit:
|
||||||
g_hash_table_destroy (hash);
|
g_hash_table_destroy (hash);
|
||||||
return NULL;
|
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;
|
||||||
|
}
|
||||||
|
|
12
lib/mu-str.h
12
lib/mu-str.h
|
@ -342,6 +342,18 @@ const gchar* mu_str_subject_normalize (const gchar* str);
|
||||||
gchar* mu_str_quoted_from_strv (const gchar **params);
|
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
|
G_END_DECLS
|
||||||
|
|
Loading…
Reference in New Issue