changeset 13215:15b3926e2147

[gaim-migrate @ 15579] gaim_utf8_strftime() should take the format in UTF-8 and convert as necessary. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Fri, 10 Feb 2006 21:17:00 +0000
parents 812e2de69c90
children 0ce20e0a1396
files src/util.c src/util.h
diffstat 2 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/util.c	Fri Feb 10 21:16:18 2006 +0000
+++ b/src/util.c	Fri Feb 10 21:17:00 2006 +0000
@@ -583,7 +583,7 @@
 
 	return strftime(s, max, format, tm);
 }
-#else /* !HAVE_STRFTIME_Z_FORMAT */
+#else /* HAVE_STRFTIME_Z_FORMAT */
 #define gaim_internal_strftime strftime
 #endif
 
@@ -591,6 +591,9 @@
 gaim_utf8_strftime(const char *format, const struct tm *tm)
 {
 	static char buf[128];
+	char *locale;
+	GError *err = NULL;
+	int len;
 	char *utf8;
 
 	g_return_val_if_fail(format != NULL, NULL);
@@ -601,17 +604,31 @@
 		tm = localtime(&now);
 	}
 
+	locale = g_locale_from_utf8(format, -1, NULL, NULL, &err);
+	if (err != NULL)
+	{
+		gaim_debug_error("util", "Format conversion failed in gaim_utf8_strftime(): %s", err->message);
+		g_error_free(err);
+		locale = g_strdup(format);
+	}
+
 	/* A return value of 0 is either an error (in
 	 * which case, the contents of the buffer are
 	 * undefined) or the empty string (in which
 	 * case, no harm is done here). */
-	if (gaim_internal_strftime(buf, sizeof(buf), format, tm) == 0)
+	if ((len = gaim_internal_strftime(buf, sizeof(buf), locale, tm)) == 0)
 	{
-		buf[0] = '\0';
-		return buf;
+		g_free(locale);
+		return "";
 	}
 
-	if ((utf8 = gaim_utf8_try_convert(buf)))
+	utf8 = g_locale_to_utf8(buf, len, NULL, NULL, &err);
+	if (err != NULL)
+	{
+		gaim_debug_error("util", "Result conversion failed in gaim_utf8_strftime(): %s", err->message);
+		g_error_free(err);
+	}
+	else
 	{
 		gaim_strlcpy(buf, utf8);
 		g_free(utf8);
--- a/src/util.h	Fri Feb 10 21:16:18 2006 +0000
+++ b/src/util.h	Fri Feb 10 21:17:00 2006 +0000
@@ -223,10 +223,13 @@
  * GMT.  Required to emit RFC822-conformant dates
  * (using "%a, %d %b %Y %H:%M:%S %z"). (GNU)'
  *
- * @param format The format string
+ * @param format The format string, in UTF-8
  * @param tm     The time to format, or @c NULL to use the current local time
  *
  * @return The formatted time, in UTF-8.
+ *
+ * @note @a format is required to be in UTF-8.  This differs from strftime(),
+ *       where the format is provided in the locale charset.
  */
 const char *gaim_utf8_strftime(const char *format, const struct tm *tm);