From 278882eaeb20f4f39605818a4f4e41b173e70306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Tue, 4 Mar 2008 00:20:16 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17006 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Recurrence.c | 10 +++++----- src/gnome-utils/gnc-dense-cal.c | 17 ++++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/engine/Recurrence.c b/src/engine/Recurrence.c index 771c54d419..6f49d07390 100644 --- a/src/engine/Recurrence.c +++ b/src/engine/Recurrence.c @@ -441,8 +441,8 @@ _weekly_list_to_compact_string(GList *rs, GString *buf) 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 @@ _monthly_append_when(Recurrence *r, GString *buf) 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); } diff --git a/src/gnome-utils/gnc-dense-cal.c b/src/gnome-utils/gnc-dense-cal.c index 9a3a905029..a6503cacb0 100644 --- a/src/gnome-utils/gnc-dense-cal.c +++ b/src/gnome-utils/gnc-dense-cal.c @@ -149,13 +149,13 @@ static void gdc_remove_markings(GncDenseCal *cal); 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 @@ month_name(int mon) 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 @@ static void 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