mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 18:52:09 +01:00
gdatetime: Factor out some string pointer arithmetic
Makes the following code a little clearer, but doesn’t introduce any functional changes. Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
parent
5e8a3c19fc
commit
804a395772
@ -1402,6 +1402,7 @@ parse_iso8601_timezone (const gchar *text, gsize length, size_t *tz_offset)
|
|||||||
gint i, offset_hours, offset_minutes;
|
gint i, offset_hours, offset_minutes;
|
||||||
gint offset_sign = 1;
|
gint offset_sign = 1;
|
||||||
GTimeZone *tz;
|
GTimeZone *tz;
|
||||||
|
const char *tz_start;
|
||||||
|
|
||||||
/* UTC uses Z suffix */
|
/* UTC uses Z suffix */
|
||||||
if (length > 0 && text[length - 1] == 'Z')
|
if (length > 0 && text[length - 1] == 'Z')
|
||||||
@ -1419,34 +1420,35 @@ parse_iso8601_timezone (const gchar *text, gsize length, size_t *tz_offset)
|
|||||||
}
|
}
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
tz_start = text + i;
|
||||||
tz_length = length - i;
|
tz_length = length - i;
|
||||||
|
|
||||||
/* +hh:mm or -hh:mm */
|
/* +hh:mm or -hh:mm */
|
||||||
if (tz_length == 6 && text[i+3] == ':')
|
if (tz_length == 6 && tz_start[3] == ':')
|
||||||
{
|
{
|
||||||
if (!get_iso8601_int (text + i + 1, 2, &offset_hours) ||
|
if (!get_iso8601_int (tz_start + 1, 2, &offset_hours) ||
|
||||||
!get_iso8601_int (text + i + 4, 2, &offset_minutes))
|
!get_iso8601_int (tz_start + 4, 2, &offset_minutes))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* +hhmm or -hhmm */
|
/* +hhmm or -hhmm */
|
||||||
else if (tz_length == 5)
|
else if (tz_length == 5)
|
||||||
{
|
{
|
||||||
if (!get_iso8601_int (text + i + 1, 2, &offset_hours) ||
|
if (!get_iso8601_int (tz_start + 1, 2, &offset_hours) ||
|
||||||
!get_iso8601_int (text + i + 3, 2, &offset_minutes))
|
!get_iso8601_int (tz_start + 3, 2, &offset_minutes))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* +hh or -hh */
|
/* +hh or -hh */
|
||||||
else if (tz_length == 3)
|
else if (tz_length == 3)
|
||||||
{
|
{
|
||||||
if (!get_iso8601_int (text + i + 1, 2, &offset_hours))
|
if (!get_iso8601_int (tz_start + 1, 2, &offset_hours))
|
||||||
return NULL;
|
return NULL;
|
||||||
offset_minutes = 0;
|
offset_minutes = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*tz_offset = i;
|
*tz_offset = tz_start - text;
|
||||||
tz = g_time_zone_new_identifier (text + i);
|
tz = g_time_zone_new_identifier (tz_start);
|
||||||
|
|
||||||
/* Double-check that the GTimeZone matches our interpretation of the timezone.
|
/* Double-check that the GTimeZone matches our interpretation of the timezone.
|
||||||
* This can fail because our interpretation is less strict than (for example)
|
* This can fail because our interpretation is less strict than (for example)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user