fix counting of UTF8-charwidth
[citadel.git] / libcitadel / lib / stringbuf.c
index 3a9ccf58e3f3feaaac8e1346b4bdc9594a7cfe83..55daf6192c57b9127e1735b71a947ea9772804dd 100644 (file)
@@ -3312,14 +3312,16 @@ void StrBuf_RFC822_2_Utf8(StrBuf *Target,
  */
 static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *CharE)
 {
-       int n = 1;
-        char test = (1<<7);
+       int n = 0;
+        unsigned char test = (1<<7);
 
        if ((*CharS & 0xC0) == 0) 
                return 1;
 
-       while ((n < 8) && ((test & *CharS) != 0)) {
-               test = test << 1;
+       while ((n < 8) && 
+              ((test & ((unsigned char)*CharS)) != 0)) 
+       {
+               test = test >> 1;
                n ++;
        }
        if ((n > 6) || ((CharE - CharS) < n))