[glib] gutf8: Clarify return values from g_utf8_get_char_extended()



commit 1c56a87c08f4e7b0e05959b0c894466a2bbf7f45
Author: Philip Withnall <withnall endlessm com>
Date:   Fri Mar 17 12:09:01 2017 +0000

    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

 glib/gutf8.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/glib/gutf8.c b/glib/gutf8.c
index b16648e..39438cd 100644
--- a/glib/gutf8.c
+++ b/glib/gutf8.c
@@ -567,6 +567,8 @@ g_utf8_get_char_extended (const  gchar *p,
   guint i, len;
   gunichar min_code;
   gunichar wc = (guchar) *p;
+  const gunichar partial_sequence = (gunichar) -2;
+  const gunichar malformed_sequence = (gunichar) -1;
 
   if (wc < 0x80)
     {
@@ -574,7 +576,7 @@ g_utf8_get_char_extended (const  gchar *p,
     }
   else if (G_UNLIKELY (wc < 0xc0))
     {
-      return (gunichar)-1;
+      return malformed_sequence;
     }
   else if (wc < 0xe0)
     {
@@ -608,7 +610,7 @@ g_utf8_get_char_extended (const  gchar *p,
     }
   else
     {
-      return (gunichar)-1;
+      return malformed_sequence;
     }
 
   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++)
        {
          if ((((guchar *)p)[i] & 0xc0) != 0x80)
-           return (gunichar)-1;
+           return malformed_sequence;
        }
-      return (gunichar)-2;
+      return partial_sequence;
     }
 
   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 (ch)
-           return (gunichar)-1;
+           return malformed_sequence;
          else
-           return (gunichar)-2;
+           return partial_sequence;
        }
 
       wc <<= 6;
@@ -638,7 +640,7 @@ g_utf8_get_char_extended (const  gchar *p,
     }
 
   if (G_UNLIKELY (wc < min_code))
-    return (gunichar)-1;
+    return malformed_sequence;
 
   return wc;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]