mirror of https://github.com/djcb/mu.git
* mu-str.c: convert strftime output to utf8 if needed
This commit is contained in:
parent
7019bd9b86
commit
4629e26609
23
src/mu-str.c
23
src/mu-str.c
|
@ -50,13 +50,34 @@ mu_str_date_s (const char* frm, time_t t)
|
|||
{
|
||||
struct tm *tmbuf;
|
||||
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);
|
||||
|
||||
tmbuf = localtime(&t);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,6 +161,7 @@ char* mu_str_normalize (const 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
|
||||
* string contains an '@', replace '@', single-'.' with '_'. Also,
|
||||
|
|
Loading…
Reference in New Issue