mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-08-13 06:25:03 -05:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user