From 0701e570aaf7fe4a4148c623200f1edca28c8220 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Wed, 28 May 2003 21:32:52 +0000 Subject: bump libtool version for api addition new, utf8 in/out 2003-05-28 Mike Kestner * configure.in : bump libtool version for api addition * gal/util/e-util.c (e_utf8_strftime): new, utf8 in/out (e_utf8_strftime_fix_am_pm): new, utf8 in/out 2003-05-28 Mike Kestner * e-cell-date.c (ecd_get_text): use e_utf8_strftime_fix_am_pm and remove locale to utf8 conversion at end. [43485] svn path=/trunk/; revision=21343 --- e-util/e-util.c | 43 +++++++++++++++++++++++++++++++++++++++++++ e-util/e-util.h | 10 ++++++++++ 2 files changed, 53 insertions(+) (limited to 'e-util') diff --git a/e-util/e-util.c b/e-util/e-util.c index 46be2143f7..03fda380e1 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -768,6 +768,27 @@ size_t e_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) #endif } +size_t +e_utf8_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) +{ + size_t sz; + char *locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL); + size_t ret = e_strftime(s, max, locale_fmt, tm); + char *buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL); + if (sz >= max) { + char *tmp = buf + max - 1; + tmp = g_utf8_find_prev_char(buf, tmp); + if (tmp) + sz = tmp - buf; + else + sz = 0; + } + memcpy(s, buf, sz); + s[sz] = '\0'; + g_free(locale_fmt); + g_free(buf); + return sz; +} /** * Function to do a last minute fixup of the AM/PM stuff if the locale @@ -830,6 +851,28 @@ size_t e_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct t return(ret); } +size_t +e_utf8_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm) +{ + size_t sz; + char *locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL); + size_t ret = e_strftime_fix_am_pm(s, max, locale_fmt, tm); + char *buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL); + if (sz >= max) { + char *tmp = buf + max - 1; + tmp = g_utf8_find_prev_char(buf, tmp); + if (tmp) + sz = tmp - buf; + else + sz = 0; + } + memcpy(s, buf, sz); + s[sz] = '\0'; + g_free(locale_fmt); + g_free(buf); + return sz; +} + /** * e_flexible_strtod: * @nptr: the string to convert to a numeric value. diff --git a/e-util/e-util.h b/e-util/e-util.h index 2937265f6b..d9d51967d1 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -196,6 +196,16 @@ size_t e_strftime (char *s, const char *fmt, const struct tm *tm); +size_t e_utf8_strftime_fix_am_pm (char *s, + size_t max, + const char *fmt, + const struct tm *tm); + +size_t e_utf8_strftime (char *s, + size_t max, + const char *fmt, + const struct tm *tm); + /* String to/from double conversion functions */ gdouble e_flexible_strtod (const gchar *nptr, gchar **endptr); -- cgit v1.2.3