Patches to gutf8.c



Patch 1: changed the macro UTF8_COMPUTE definition to a more fast (made some tests) algorithm.
Patch 2: changed the function g_utf8_find_next_char because if the next char is pointed by end it returns NULL.

If I should proceed in a different way please inform.

Keep up the good work...
Best regards...
--- gutf8.c	2008-08-05 23:01:46.000000000 +0100
+++ gutf8_patched.c	2008-08-05 23:25:57.000000000 +0100
@@ -47,27 +47,31 @@
       Len = 1;								      \
       Mask = 0x7f;							      \
     }									      \
-  else if ((Char & 0xe0) == 0xc0)					      \
+  else if (Char < 192)							      \
+    {									      \
+      Len = -1;								      \
+    }									      \
+  else if (!(Char & 0x20))						      \
     {									      \
       Len = 2;								      \
       Mask = 0x1f;							      \
     }									      \
-  else if ((Char & 0xf0) == 0xe0)					      \
+  else if (!(Char & 0x10))						      \
     {									      \
       Len = 3;								      \
       Mask = 0x0f;							      \
     }									      \
-  else if ((Char & 0xf8) == 0xf0)					      \
+  else if (!(Char & 0x08))						      \
     {									      \
       Len = 4;								      \
       Mask = 0x07;							      \
     }									      \
-  else if ((Char & 0xfc) == 0xf8)					      \
+  else if (!(Char & 0x04))						      \
     {									      \
       Len = 5;								      \
       Mask = 0x03;							      \
     }									      \
-  else if ((Char & 0xfe) == 0xfc)					      \
+  else if (!(Char & 0x02))						      \
     {									      \
       Len = 6;								      \
       Mask = 0x01;							      \
@@ -171,7 +175,7 @@ g_utf8_find_next_char (const gchar *p,
 	for (++p; (*p & 0xc0) == 0x80; ++p)
 	  ;
     }
-  return (p == end) ? NULL : (gchar *)p;
+  return (p == end) ? (*p & 0xc0) == 0x80 ? NULL : (gchar *)end /* == p */ : (gchar *)p;
 }
 
 /**


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