[glib] win32_strftime_helper: Factor out the common code
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] win32_strftime_helper: Factor out the common code
- Date: Tue, 20 Feb 2018 12:06:06 +0000 (UTC)
commit 5520a879303264c57757b1fb806b9fe720cac664
Author: Rafal Luzynski <digitalfreak lingonborough com>
Date: Fri Feb 16 22:20:50 2018 +0100
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
glib/gdate.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/glib/gdate.c b/glib/gdate.c
index 252cb6748..fd5e5444d 100644
--- a/glib/gdate.c
+++ b/glib/gdate.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]