Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/evas

Dir     : e17/libs/evas/src/lib/engines/common


Modified Files:
        evas_font_main.c 


Log Message:


new calls to help string processing for programs - these walk up and down 1
utf8 character (sicne thats evas's standard string format). this lets apps do
character processing AND still be utf8-safe.

===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_font_main.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- evas_font_main.c    14 Nov 2002 05:38:10 -0000      1.2
+++ evas_font_main.c    5 Jun 2003 06:08:42 -0000       1.3
@@ -117,7 +117,7 @@
        r <<= 6;
        r |= (d3 & 0x3f);
      }
-   else 
+   else
      { 
        /* 4 byte */
        d2 = buf[index++];
@@ -133,15 +133,88 @@
        r <<= 6;
        r |= (d3 & 0x3f);
        r <<= 6;
-       r |= (d4 & 0x3f);
-       
+       r |= (d4 & 0x3f);       
      }
-   if (r < 0xdfff && d > 0xd800) 
+   *iindex = index;
+   return r;
+}
+
+int
+evas_common_font_utf8_get_prev(unsigned char *buf, int *iindex)
+{
+   /* Reads UTF8 bytes from @buf, starting at [EMAIL PROTECTED] and returns
+    * the code point of the previous valid code point. @index is
+    * updated ready for the next call.
+    * 
+    * Returns 0 to indicate an error (e.g. invalid UTF8)
+    */   
+   int index = *iindex, r, istart = *iindex;
+   unsigned char d = buf[index++], d2, d3, d4;
+   
+   if (!d)
+     return 0;
+   if (d < 0x80) 
      {
-       /* ill-formed says Table 3.1B in the */
-       /* Unicode 3.2 std */
-       return 0;      
+       r = d;
+     }
+   else if ((d & 0xe0) == 0xc0) 
+     { 
+       /* 2 byte */
+       d2 = buf[index++];
+       if ((d2 & 0xc0) != 0x80)
+         return 0;
+       r = d & 0x1f; /* copy lower 5 */
+       r <<= 6;
+       r |= (d2 & 0x3f); /* copy lower 6 */
+     }
+   else if ((d & 0xf0) == 0xe0) 
+     { 
+       /* 3 byte */
+       d2 = buf[index++];
+       d3 = buf[index++];
+       if ((d2 & 0xc0) != 0x80 ||
+           (d3 & 0xc0) != 0x80)
+         return 0;
+       r = d & 0x0f; /* copy lower 4 */
+       r <<= 6;
+       r |= (d2 & 0x3f);
+       r <<= 6;
+       r |= (d3 & 0x3f);
+     }
+   else
+     { 
+       /* 4 byte */
+       d2 = buf[index++];
+       d3 = buf[index++];
+       d4 = buf[index++];
+       if ((d2 & 0xc0) != 0x80 ||
+           (d3 & 0xc0) != 0x80 ||
+           (d4 & 0xc0) != 0x80)
+         return 0;
+       r = d & 0x0f; /* copy lower 4 */
+       r <<= 6;
+       r |= (d2 & 0x3f);
+       r <<= 6;
+       r |= (d3 & 0x3f);
+       r <<= 6;
+       r |= (d4 & 0x3f);       
+     }
+   index = istart - 1;
+   d = buf[index];
+   if (!(d & 0x80))
+     *iindex = index;
+   else
+     {
+       while (index > 0)
+         {
+            index--;
+            d = buf[index];
+            if ((d & 0xc0) != 0x80)
+              {
+                 *iindex = index;
+                 return r;
+              }
+         }
      }
-   *iindex = index;
    return r;
 }




-------------------------------------------------------
This SF.net email is sponsored by:  Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to