ecere/gui/EditBox; utf8: Updated EditBox UTF8 iteration; Fixed UTF8GetChar to return...
authorJerome St-Louis <jerome@ecere.com>
Mon, 18 Mar 2013 21:16:52 +0000 (17:16 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 18 Mar 2013 21:19:08 +0000 (17:19 -0400)
compiler/bootstrap/ecere/bootstrap/instance.c
ecere/src/com/instance.ec
ecere/src/gui/controls/EditBox.ec

index 8607ffd..ba69762 100644 (file)
@@ -5739,7 +5739,7 @@ unsigned int ch;
 unsigned char b = ((unsigned char *)string)[0];
 int i;
 unsigned char mask = (unsigned char)0x7F;
-int nb = 1;
+int nb = b ? 1 : 0;
 
 ch = 0;
 if(b & (unsigned char)0x80)
index 5cce5f5..9d5dc82 100644 (file)
@@ -6641,7 +6641,7 @@ public unichar UTF8GetChar(char * string, int * numBytes)
    byte b = ((byte *)string)[0];
    int i;
    byte mask = 0x7F;
-   int nb = 1;
+   int nb = b ? 1 : 0;
    ch = 0;
    if(b & 0x80)
    {
index 7791478..faf79a8 100644 (file)
@@ -47,28 +47,48 @@ public:
       byte b = (string)[0]; \
       int i; \
       byte mask = 0x7F; \
-      numBytes = 1; \
+      numBytes = b ? 1 : 0; \
       ch = 0; \
-      if(b & 0x80 && b & 0x40) \
+      if(b & 0x80) \
       { \
-         mask >>= 2; \
-         numBytes++; \
-         if(b & 0x20) \
+         if(b & 0x40) \
          { \
+            mask >>= 2; \
             numBytes++; \
-            mask >>= 1; \
-            if(b & 0x10) \
+            if(b & 0x20) \
             { \
                numBytes++; \
                mask >>= 1; \
+               if(b & 0x10) \
+               { \
+                  if(b & 0x08) { numBytes = 0; } \
+                  numBytes++; \
+                  mask >>= 1; \
+               } \
             } \
          } \
+         else \
+            numBytes = 0; \
       } \
       for(i = 0; i<numBytes; i++) \
       { \
          ch <<= 6; \
-         ch |= (string)[i] & mask; \
+         ch |= (b = (string)[i]) & mask; \
          mask = 0x3F; \
+         if(i > 1 && (!(b & 0x80) || (b & 0x40))) \
+         { \
+            numBytes = 0; \
+            ch = 0; \
+         } \
+      } \
+      if(i < numBytes || \
+         ch > 0x10FFFF || (ch >= 0xD800 && ch <= 0xDFFF) || \
+        (ch < 0x80 && numBytes > 1) || \
+        (ch < 0x800 && numBytes > 2) || \
+        (ch < 0x10000 && numBytes > 3))\
+      { \
+         ch = 0; \
+         numBytes = 0; \
       } \
       ch; \
    })