[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    kconfigbase
From:       Waldo Bastian <bastian () kde ! org>
Date:       2001-02-21 21:23:44
[Download RAW message or body]

Hiya,

Does this utf8 check still work with the following patch?

Cheers,
Waldo
-- 
bastian@kde.org | SuSE Labs KDE Developer | bastian@suse.com

["kconfigbase.diff" (text/x-c++)]

Index: kconfigbase.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfigbase.cpp,v
retrieving revision 1.108
diff -u -r1.108 kconfigbase.cpp
--- kconfigbase.cpp	2001/02/21 03:22:41	1.108
+++ kconfigbase.cpp	2001/02/21 21:14:49
@@ -35,16 +35,15 @@
 
 static bool isUtf8(const char *buf) {
   int i, n;
-  // unsigned long c;
+  register char c;
   bool gotone = false;
-  int buflen = strlen(buf);
 
 #define F 0   /* character never appears in text */
 #define T 1   /* character appears in plain ASCII text */
 #define I 2   /* character appears in ISO-8859 text */
 #define X 3   /* character appears in non-ISO extended ASCII (Mac, IBM PC) */
 
-  static char text_chars[256] = {
+  static const char text_chars[256] = {
   /*                  BEL BS HT LF    FF CR    */
         F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F,  /* 0x0X */
         /*                              ESC          */
@@ -67,54 +66,42 @@
   };
 
   /* *ulen = 0; */
-  for (i = 0; i < buflen; i++) {
-    if ((buf[i] & 0x80) == 0) {        /* 0xxxxxxx is plain ASCII */
+  for (i = 0; (c = buf[i]); i++) {
+    if ((c & 0x80) == 0) {        /* 0xxxxxxx is plain ASCII */
       /*
        * Even if the whole file is valid UTF-8 sequences,
        * still reject it if it uses weird control characters.
        */
 
-      if (text_chars[buf[i]] != T)
+      if (text_chars[c] != T)
         return false;
 
-      /* if (ubuf != NULL)
-        ubuf[(*ulen)++] = buf[i]; */
-
-    } else if ((buf[i] & 0x40) == 0) { /* 10xxxxxx never 1st byte */
+    } else if ((c & 0x40) == 0) { /* 10xxxxxx never 1st byte */
       return false;
     } else {                           /* 11xxxxxx begins UTF-8 */
       int following;
 
-    if ((buf[i] & 0x20) == 0) {             /* 110xxxxx */
-      // c = buf[i] & 0x1f;
+    if ((c & 0x20) == 0) {             /* 110xxxxx */
       following = 1;
-    } else if ((buf[i] & 0x10) == 0) {      /* 1110xxxx */
-      // c = buf[i] & 0x0f;
+    } else if ((c & 0x10) == 0) {      /* 1110xxxx */
       following = 2;
-    } else if ((buf[i] & 0x08) == 0) {      /* 11110xxx */
-      // c = buf[i] & 0x07;
+    } else if ((c & 0x08) == 0) {      /* 11110xxx */
       following = 3;
-    } else if ((buf[i] & 0x04) == 0) {      /* 111110xx */
-      // c = buf[i] & 0x03;
+    } else if ((c & 0x04) == 0) {      /* 111110xx */
       following = 4;
-    } else if ((buf[i] & 0x02) == 0) {      /* 1111110x */
-      // c = buf[i] & 0x01;
+    } else if ((c & 0x02) == 0) {      /* 1111110x */
       following = 5;
     } else
       return false;
 
       for (n = 0; n < following; n++) {
         i++;
-        if (i >= buflen)
+        if (!(c = buf[i]))
           goto done;
 
-        if ((buf[i] & 0x80) == 0 || (buf[i] & 0x40))
+        if ((c & 0x80) == 0 || (c & 0x40))
           return false;
-
-        // c = (c << 6) + (buf[i] & 0x3f);
       }
-      /* if (ubuf != NULL)
-        ubuf[(*ulen)++] = c; */
       gotone = true;
     }
   }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic