[glib] g_date_set_parse: Also support nominative/genitive month names
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] g_date_set_parse: Also support nominative/genitive month names
- Date: Tue, 20 Feb 2018 12:06:01 +0000 (UTC)
commit 915224482864a5f885ada8c981fc27f77e753528
Author: Rafal Luzynski <digitalfreak lingonborough com>
Date: Fri Feb 16 21:25:55 2018 +0100
g_date_set_parse: Also support nominative/genitive month names
As the support of two grammatical cases of month names has been introduced
try to find both forms when parsing a date.
https://bugzilla.gnome.org/show_bug.cgi?id=749206
glib/gdate.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 66 insertions(+), 1 deletion(-)
---
diff --git a/glib/gdate.c b/glib/gdate.c
index 58cb75cb4..252cb6748 100644
--- a/glib/gdate.c
+++ b/glib/gdate.c
@@ -879,11 +879,21 @@ static gchar *long_month_names[13] =
NULL,
};
+static gchar *long_month_names_alternative[13] =
+{
+ NULL,
+};
+
static gchar *short_month_names[13] =
{
NULL,
};
+static gchar *short_month_names_alternative[13] =
+{
+ NULL,
+};
+
/* This tells us if we need to update the parse info */
static gchar *current_locale = NULL;
@@ -974,6 +984,11 @@ g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
i = 1;
while (i < 13)
{
+ /* Here month names will be in a genitive case.
+ * Examples of how January may look in some languages:
+ * Catalan: "de gener", Croatian: "sijeÄŤnja", Polish: "stycznia",
+ * Upper Sorbian: "januara".
+ */
if (long_month_names[i] != NULL)
{
const gchar *found = strstr (normalized, long_month_names[i]);
@@ -984,7 +999,27 @@ g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
break;
}
}
-
+
+ /* Here month names will be in a nominative case.
+ * Examples of how January may look in some languages:
+ * Catalan: "gener", Croatian: "Siječanj", Polish: "styczeń",
+ * Upper Sorbian: "Januar".
+ */
+ if (long_month_names_alternative[i] != NULL)
+ {
+ const gchar *found = strstr (normalized, long_month_names_alternative[i]);
+
+ if (found != NULL)
+ {
+ pt->month = i;
+ break;
+ }
+ }
+
+ /* Differences between abbreviated nominative and abbreviated
+ * genitive month names are visible in very few languages but
+ * let's handle them.
+ */
if (short_month_names[i] != NULL)
{
const gchar *found = strstr (normalized, short_month_names[i]);
@@ -996,6 +1031,17 @@ g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
}
}
+ if (short_month_names_alternative[i] != NULL)
+ {
+ const gchar *found = strstr (normalized, short_month_names_alternative[i]);
+
+ if (found != NULL)
+ {
+ pt->month = i;
+ break;
+ }
+ }
+
++i;
}
@@ -1053,6 +1099,18 @@ g_date_prepare_to_parse (const gchar *str,
long_month_names[i] = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
g_free (casefold);
+ g_date_strftime (buf, 127, "%Ob", &d);
+ casefold = g_utf8_casefold (buf, -1);
+ g_free (short_month_names_alternative[i]);
+ short_month_names_alternative[i] = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
+ g_free (casefold);
+
+ g_date_strftime (buf, 127, "%OB", &d);
+ casefold = g_utf8_casefold (buf, -1);
+ g_free (long_month_names_alternative[i]);
+ long_month_names_alternative[i] = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL);
+ g_free (casefold);
+
++i;
}
@@ -1099,6 +1157,13 @@ g_date_prepare_to_parse (const gchar *str,
DEBUG_MSG ((" %s %s", long_month_names[i], short_month_names[i]));
++i;
}
+ DEBUG_MSG (("Alternative month names:"));
+ i = 1;
+ while (i < 13)
+ {
+ DEBUG_MSG ((" %s %s", long_month_names_alternative[i], short_month_names_alternative[i]));
+ ++i;
+ }
if (using_twodigit_years)
{
DEBUG_MSG (("**Using twodigit years with cutoff year: %u", twodigit_start_year));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]