* mu-str.c: convert strftime output to utf8 if needed
This commit is contained in:
21
src/mu-str.c
21
src/mu-str.c
@ -50,6 +50,10 @@ mu_str_date_s (const char* frm, time_t t)
|
|||||||
{
|
{
|
||||||
struct tm *tmbuf;
|
struct tm *tmbuf;
|
||||||
static char buf[128];
|
static char buf[128];
|
||||||
|
static int is_utf8 = -1;
|
||||||
|
|
||||||
|
if (G_UNLIKELY(is_utf8 == -1))
|
||||||
|
is_utf8 = mu_util_locale_is_utf8 () ? 1 : 0;
|
||||||
|
|
||||||
g_return_val_if_fail (frm, NULL);
|
g_return_val_if_fail (frm, NULL);
|
||||||
|
|
||||||
@ -57,6 +61,23 @@ mu_str_date_s (const char* frm, time_t t)
|
|||||||
|
|
||||||
strftime (buf, sizeof(buf), frm, tmbuf);
|
strftime (buf, sizeof(buf), frm, tmbuf);
|
||||||
|
|
||||||
|
if (!is_utf8) {
|
||||||
|
/* charset is _not_ utf8, so we need to convert it, so
|
||||||
|
* the date could contain locale-specific characters*/
|
||||||
|
gchar *conv;
|
||||||
|
GError *err;
|
||||||
|
err = NULL;
|
||||||
|
conv = g_locale_to_utf8 (buf, -1, NULL, NULL, &err);
|
||||||
|
if (err) {
|
||||||
|
g_warning ("conversion failed: %s", err->message);
|
||||||
|
g_error_free (err);
|
||||||
|
strcpy (buf, "<error>");
|
||||||
|
} else
|
||||||
|
strncpy (buf, conv, sizeof(buf));
|
||||||
|
|
||||||
|
g_free (conv);
|
||||||
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -161,6 +161,7 @@ char* mu_str_normalize (const char *str, gboolean downcase)
|
|||||||
*/
|
*/
|
||||||
char* mu_str_normalize_in_place (char *str, gboolean downcase);
|
char* mu_str_normalize_in_place (char *str, gboolean downcase);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* escape the string for use with xapian matching. in practice, if the
|
* escape the string for use with xapian matching. in practice, if the
|
||||||
* string contains an '@', replace '@', single-'.' with '_'. Also,
|
* string contains an '@', replace '@', single-'.' with '_'. Also,
|
||||||
|
|||||||
Reference in New Issue
Block a user