mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-14 00:06:24 +01:00
datetime: use g_utf8_next_char() to walk utf8 string
Previously, the format string was iterated many times by walking to the given offset in the string repeatedly. This patch instead walks the string using g_utf8_next_char(). Additionally, the character for lookups was a char and could loose content. This uses gunichar instead. https://bugzilla.gnome.org/show_bug.cgi?id=50076
This commit is contained in:
parent
52e44ddec2
commit
6bb89501cf
@ -1842,13 +1842,11 @@ gchar *
|
|||||||
g_date_time_printf (const GDateTime *datetime,
|
g_date_time_printf (const GDateTime *datetime,
|
||||||
const gchar *format)
|
const gchar *format)
|
||||||
{
|
{
|
||||||
GString *outstr;
|
GString *outstr;
|
||||||
const gchar *tmp;
|
gchar *tmp;
|
||||||
gchar *tmp2,
|
gunichar c;
|
||||||
c;
|
glong utf8len;
|
||||||
glong utf8len;
|
gboolean in_mod;
|
||||||
gint i;
|
|
||||||
gboolean in_mod;
|
|
||||||
|
|
||||||
g_return_val_if_fail (datetime != NULL, NULL);
|
g_return_val_if_fail (datetime != NULL, NULL);
|
||||||
g_return_val_if_fail (format != NULL, NULL);
|
g_return_val_if_fail (format != NULL, NULL);
|
||||||
@ -1858,10 +1856,9 @@ g_date_time_printf (const GDateTime *datetime,
|
|||||||
utf8len = g_utf8_strlen (format, -1);
|
utf8len = g_utf8_strlen (format, -1);
|
||||||
in_mod = FALSE;
|
in_mod = FALSE;
|
||||||
|
|
||||||
for (i = 0; i < utf8len; i++)
|
for (; *format; format = g_utf8_next_char(format))
|
||||||
{
|
{
|
||||||
tmp = g_utf8_offset_to_pointer (format, i);
|
c = g_utf8_get_char (format);
|
||||||
c = g_utf8_get_char (tmp);
|
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
@ -1974,16 +1971,16 @@ g_date_time_printf (const GDateTime *datetime,
|
|||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
{
|
{
|
||||||
tmp2 = GET_PREFERRED_DATE (datetime);
|
tmp = GET_PREFERRED_DATE (datetime);
|
||||||
g_string_append (outstr, tmp2);
|
g_string_append (outstr, tmp);
|
||||||
g_free (tmp2);
|
g_free (tmp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'X':
|
case 'X':
|
||||||
{
|
{
|
||||||
tmp2 = GET_PREFERRED_TIME (datetime);
|
tmp = GET_PREFERRED_TIME (datetime);
|
||||||
g_string_append (outstr, tmp2);
|
g_string_append (outstr, tmp);
|
||||||
g_free (tmp2);
|
g_free (tmp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
|
Loading…
Reference in New Issue
Block a user