gutf8: Clarify return values from g_utf8_get_char_extended()

It’s hard to remember what the difference is between -1 and -2, so give
them names.

This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=780095
This commit is contained in:
Philip Withnall 2017-03-17 12:09:01 +00:00
parent 30e382bace
commit 1c56a87c08

View File

@ -567,6 +567,8 @@ g_utf8_get_char_extended (const gchar *p,
guint i, len; guint i, len;
gunichar min_code; gunichar min_code;
gunichar wc = (guchar) *p; gunichar wc = (guchar) *p;
const gunichar partial_sequence = (gunichar) -2;
const gunichar malformed_sequence = (gunichar) -1;
if (wc < 0x80) if (wc < 0x80)
{ {
@ -574,7 +576,7 @@ g_utf8_get_char_extended (const gchar *p,
} }
else if (G_UNLIKELY (wc < 0xc0)) else if (G_UNLIKELY (wc < 0xc0))
{ {
return (gunichar)-1; return malformed_sequence;
} }
else if (wc < 0xe0) else if (wc < 0xe0)
{ {
@ -608,7 +610,7 @@ g_utf8_get_char_extended (const gchar *p,
} }
else else
{ {
return (gunichar)-1; return malformed_sequence;
} }
if (G_UNLIKELY (max_len >= 0 && len > max_len)) if (G_UNLIKELY (max_len >= 0 && len > max_len))
@ -616,9 +618,9 @@ g_utf8_get_char_extended (const gchar *p,
for (i = 1; i < max_len; i++) for (i = 1; i < max_len; i++)
{ {
if ((((guchar *)p)[i] & 0xc0) != 0x80) if ((((guchar *)p)[i] & 0xc0) != 0x80)
return (gunichar)-1; return malformed_sequence;
} }
return (gunichar)-2; return partial_sequence;
} }
for (i = 1; i < len; ++i) for (i = 1; i < len; ++i)
@ -628,9 +630,9 @@ g_utf8_get_char_extended (const gchar *p,
if (G_UNLIKELY ((ch & 0xc0) != 0x80)) if (G_UNLIKELY ((ch & 0xc0) != 0x80))
{ {
if (ch) if (ch)
return (gunichar)-1; return malformed_sequence;
else else
return (gunichar)-2; return partial_sequence;
} }
wc <<= 6; wc <<= 6;
@ -638,7 +640,7 @@ g_utf8_get_char_extended (const gchar *p,
} }
if (G_UNLIKELY (wc < min_code)) if (G_UNLIKELY (wc < min_code))
return (gunichar)-1; return malformed_sequence;
return wc; return wc;
} }