mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 10:16:17 +01:00
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
This commit is contained in:
parent
03d06c175f
commit
9152244828
67
glib/gdate.c
67
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));
|
||||
|
Loading…
Reference in New Issue
Block a user