win32_strftime_helper: Factor out the common code

Factor out the common code supporting "%B", "%b", and "%h" format
specifiers. It will be helpful for the next commit.

https://bugzilla.gnome.org/show_bug.cgi?id=749206
This commit is contained in:
Rafal Luzynski 2018-02-16 22:20:50 +01:00 committed by Philip Withnall
parent 9152244828
commit 5520a87930

View File

@ -2133,6 +2133,23 @@ g_date_order (GDate *date1,
}
#ifdef G_OS_WIN32
static void
append_month_name (GArray *result,
LCID lcid,
SYSTEMTIME *systemtime,
gboolean abbreviated)
{
int n;
WORD base;
base = abbreviated ? LOCALE_SABBREVMONTHNAME1 : LOCALE_SMONTHNAME1;
n = GetLocaleInfoW (lcid, base + systemtime->wMonth - 1, NULL, 0);
g_array_set_size (result, result->len + n);
GetLocaleInfoW (lcid, base + systemtime->wMonth - 1,
((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
}
static gsize
win32_strftime_helper (const GDate *d,
const gchar *format,
@ -2219,16 +2236,10 @@ win32_strftime_helper (const GDate *d,
break;
case 'b':
case 'h':
n = GetLocaleInfoW (lcid, LOCALE_SABBREVMONTHNAME1+systemtime.wMonth-1, NULL, 0);
g_array_set_size (result, result->len + n);
GetLocaleInfoW (lcid, LOCALE_SABBREVMONTHNAME1+systemtime.wMonth-1, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
append_month_name (result, lcid, &systemtime, TRUE);
break;
case 'B':
n = GetLocaleInfoW (lcid, LOCALE_SMONTHNAME1+systemtime.wMonth-1, NULL, 0);
g_array_set_size (result, result->len + n);
GetLocaleInfoW (lcid, LOCALE_SMONTHNAME1+systemtime.wMonth-1, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
append_month_name (result, lcid, &systemtime, FALSE);
break;
case 'c':
n = GetDateFormatW (lcid, 0, &systemtime, NULL, NULL, 0);