r17006 - gnucash/trunk/src - Make a few date printing functions in dense calendar utf8-safer.

Andreas Köhler andi5 at cvs.gnucash.org
Mon Mar 3 19:20:16 EST 2008


Author: andi5
Date: 2008-03-03 19:20:16 -0500 (Mon, 03 Mar 2008)
New Revision: 17006
Trac: http://svn.gnucash.org/trac/changeset/17006

Modified:
   gnucash/trunk/src/engine/Recurrence.c
   gnucash/trunk/src/gnome-utils/gnc-dense-cal.c
Log:
Make a few date printing functions in dense calendar utf8-safer.

Work on utf8 characters instead of bytes.  g_date_strftime() and
gnc_dow_abbrev() can grok full buffer sizes.


Modified: gnucash/trunk/src/engine/Recurrence.c
===================================================================
--- gnucash/trunk/src/engine/Recurrence.c	2008-03-04 00:20:07 UTC (rev 17005)
+++ gnucash/trunk/src/engine/Recurrence.c	2008-03-04 00:20:16 UTC (rev 17006)
@@ -441,8 +441,8 @@
         if ((dow_present_bits & (1 << dow_idx)) != 0)
         {
             gchar dbuf[10];
-            gnc_dow_abbrev(dbuf, 9, dow_idx);
-            g_string_append_printf(buf, "%c", dbuf[0]);
+            gnc_dow_abbrev(dbuf, 10, dow_idx);
+            g_string_append_unichar(buf, g_utf8_get_char(dbuf));
         }
         else
         {
@@ -458,10 +458,10 @@
     if (recurrenceGetPeriodType(r) == PERIOD_LAST_WEEKDAY)
     {
         gint abbrev_day_name_bufsize = 10;
-        gchar day_name_buf[abbrev_day_name_bufsize+1];
-                
+        gchar day_name_buf[abbrev_day_name_bufsize];
+
         gnc_dow_abbrev(day_name_buf, abbrev_day_name_bufsize, g_date_get_weekday(&date) % 7);
-            
+
         /* translators: %s is an already-localized form of the day of the week. */
         g_string_append_printf(buf, _("last %s"), day_name_buf);
     }

Modified: gnucash/trunk/src/gnome-utils/gnc-dense-cal.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-dense-cal.c	2008-03-04 00:20:07 UTC (rev 17005)
+++ gnucash/trunk/src/gnome-utils/gnc-dense-cal.c	2008-03-04 00:20:16 UTC (rev 17006)
@@ -149,13 +149,13 @@
 
 static GObject *parent_class = NULL;
 
-#define MONTH_NAME_BUFSIZE 5
+#define MONTH_NAME_BUFSIZE 10
 
 /* Takes the number of months since January, in the range 0 to
  * 11. Returns the abbreviated month name according to the current
  * locale.*/
 static const gchar*
-month_name(int mon) 
+month_name(int mon)
 {
     static gchar buf[MONTH_NAME_BUFSIZE];
     GDate date;
@@ -163,13 +163,13 @@
 
     memset(buf, 0, MONTH_NAME_BUFSIZE);
     g_date_clear(&date, 1);
-     
+
     g_date_set_year(&date, arbitrary_year);
     g_date_set_day(&date, 1);
     // g_date API is 1..12 (not 0..11)
     g_date_set_month(&date, mon+1);
-    g_date_strftime(buf, MONTH_NAME_BUFSIZE-1, "%b", &date);
-     
+    g_date_strftime(buf, MONTH_NAME_BUFSIZE, "%b", &date);
+
     return buf;
 }
 
@@ -179,8 +179,11 @@
 day_label(gchar *buf, int buf_len, int dow)
 {
     gnc_dow_abbrev(buf, buf_len, dow);
-    /* Wild hack to use only the first two letters */
-    buf[2]='\0';
+    /* Use only the first two characters */
+    if (g_utf8_strlen(buf, -1) > 2) {
+        gchar *pointer = g_utf8_offset_to_pointer(buf, 2);
+        *pointer = '\0';
+    }
 }
 
 GType



More information about the gnucash-changes mailing list