Re: [Nautilus-list] [PATCH] correct dates in nautilus



Št, 2002-01-19 22:28, Darin Adler rašė:
> I'm think we need to check and handle the case where the g_locale_from_utf8
> call fails and returns NULL. I think we want to do a return_if_fail in that
> case (and the g_string_new should be moved after).
> 
> Also, you need a new variable to hold the converted string. You can't just
> use "remainder", because that gets moved along the string buffer as we walk.
> So the g_free will just trash memory in many cases. So you should change
> remainder back to a const char *, and create a char * variable called
> format_in_locale_encoding or something like that.
> 
> Please fix those two things, and then show me a new patch so we can get it
> in there.

Here's revised patch with those 2 things fixed

-- 
Gediminas Paulauskas
Kaunas, Lithuania
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/eel/ChangeLog,v
retrieving revision 1.256
diff -u -p -r1.256 ChangeLog
--- ChangeLog	2002/01/19 08:02:27	1.256
+++ ChangeLog	2002/01/19 22:23:03
@@ -1,3 +1,9 @@
+2002-01-19  Gediminas Paulauskas <menesis delfi lt>
+
+	* eel/eel-glib-extensions.c: (eel_strdup_strftime):
+	Convert format string into locale encoding at start, and convert back
+	into utf-8 the result. 
+
 2002-01-19  Darin Adler  <darin bentspoon com>
 
 	* test/test-eel-gtk-style.c: (style_get_color), (style_get_gc):
Index: eel/eel-glib-extensions.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-glib-extensions.c,v
retrieving revision 1.13
diff -u -p -r1.13 eel-glib-extensions.c
--- eel/eel-glib-extensions.c	2002/01/19 00:19:29	1.13
+++ eel/eel-glib-extensions.c	2002/01/19 22:23:03
@@ -167,12 +167,17 @@ eel_strdup_strftime (const char *format,
 	GString *string;
 	const char *remainder, *percent;
 	char code[3], buffer[512];
-	char *piece, *result;
+	char *piece, *result, *converted;
 	size_t string_length;
 	gboolean strip_leading_zeros, turn_leading_zeros_to_spaces;
 
+	/* Format could be translated, and contain UTF-8 chars,
+	 * so convert to locale encoding which strftime uses */
+	converted = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
+	g_return_val_if_fail(converted != NULL, NULL);
+	
 	string = g_string_new ("");
-	remainder = format;
+	remainder = converted;
 
 	/* Walk from % character to % character. */
 	for (;;) {
@@ -262,10 +267,13 @@ eel_strdup_strftime (const char *format,
 		/* Add this piece. */
 		g_string_append (string, piece);
 	}
+	
+	/* Convert the string back into utf-8. */
+	result = g_locale_to_utf8 (string->str, -1, NULL, NULL, NULL);
 
-	/* Extract the string. */
-	result = string->str;
-	g_string_free (string, FALSE);
+	g_string_free (string, TRUE);
+	g_free (converted);
+
 	return result;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]