* mu-str: add mu_str_utf8ify

This commit is contained in:
djcb 2012-01-12 00:19:35 +02:00
parent eef777a604
commit 15f7be5f1c
2 changed files with 31 additions and 0 deletions

View File

@ -534,6 +534,9 @@ char*
mu_str_asciify_in_place (char *buf)
{
char *c;
g_return_val_if_fail (buf, NULL);
for (c = buf; c && *c; ++c)
if (!isascii(*c))
c[0] = '.';
@ -541,6 +544,23 @@ mu_str_asciify_in_place (char *buf)
return buf;
}
char*
mu_str_utf8ify (const char *buf)
{
char *utf8;
g_return_val_if_fail (buf, NULL);
utf8 = g_strdup (buf);
if (!g_utf8_validate (buf, -1, NULL))
mu_str_asciify_in_place (utf8);
return utf8;
}
gchar*
mu_str_convert_to_utf8 (const char* buffer, const char *charset)
{

View File

@ -220,6 +220,17 @@ char* mu_str_escape_c_literal (const gchar* str, gboolean in_quotes)
char* mu_str_asciify_in_place (char *buf);
/**
* turn string in buf into valid utf8. If this string is not valid
* utf8 already, the function massages the offending characters.
*
* @param buf a buffer to utf8ify
*
* @return a newly allocated utf8 string
*/
char* mu_str_utf8ify (const char *buf);
/**
* convert a string in a certain charset into utf8
*