diff --git a/src/mu-str.c b/src/mu-str.c index d88e9647..6a04fd45 100644 --- a/src/mu-str.c +++ b/src/mu-str.c @@ -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) { diff --git a/src/mu-str.h b/src/mu-str.h index e0c30bdc..92af523f 100644 --- a/src/mu-str.h +++ b/src/mu-str.h @@ -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 *