mirror of https://github.com/djcb/mu.git
* mu-str: add mu_str_utf8ify
This commit is contained in:
parent
eef777a604
commit
15f7be5f1c
20
src/mu-str.c
20
src/mu-str.c
|
@ -534,6 +534,9 @@ char*
|
||||||
mu_str_asciify_in_place (char *buf)
|
mu_str_asciify_in_place (char *buf)
|
||||||
{
|
{
|
||||||
char *c;
|
char *c;
|
||||||
|
|
||||||
|
g_return_val_if_fail (buf, NULL);
|
||||||
|
|
||||||
for (c = buf; c && *c; ++c)
|
for (c = buf; c && *c; ++c)
|
||||||
if (!isascii(*c))
|
if (!isascii(*c))
|
||||||
c[0] = '.';
|
c[0] = '.';
|
||||||
|
@ -541,6 +544,23 @@ mu_str_asciify_in_place (char *buf)
|
||||||
return 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*
|
gchar*
|
||||||
mu_str_convert_to_utf8 (const char* buffer, const char *charset)
|
mu_str_convert_to_utf8 (const char* buffer, const char *charset)
|
||||||
{
|
{
|
||||||
|
|
11
src/mu-str.h
11
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);
|
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
|
* convert a string in a certain charset into utf8
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue