]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - utf8lib.c
reducing error output in font loading (use developer != 0 to re-enable)
[xonotic/darkplaces.git] / utf8lib.c
index 6b2b985e0e441cb6801bee024f0549368dd4ad13..c1e5a81000c635537687d7ed1edf858b6edc6d5b 100644 (file)
--- a/utf8lib.c
+++ b/utf8lib.c
@@ -41,19 +41,20 @@ static qboolean u8_analyze(const char *_s, size_t *_start, size_t *_len, Uchar *
 findchar:
 
        // <0xC2 is always an overlong encoding, they're invalid, thus skipped
-       while (i < _maxlen && s[i] && s[i] >= 0x80 && s[i] <= 0xC2) {
+       while (i < _maxlen && s[i] && s[i] >= 0x80 && s[i] < 0xC2) {
                //fprintf(stderr, "skipping\n");
                ++i;
        }
-       if(i >= _maxlen)
-               return false;
-       //fprintf(stderr, "checking\n");
 
+       //fprintf(stderr, "checking\n");
        // If we hit the end, well, we're out and invalid
-       if (!s[i])
+       if(i >= _maxlen || !s[i]) {
+               if (_start) *_start = i;
+               if (_len) *_len = 0;
                return false;
-       //fprintf(stderr, "checking ascii\n");
+       }
 
+       //fprintf(stderr, "checking ascii\n");
        // ascii characters
        if (s[i] < 0x80)
        {
@@ -76,8 +77,11 @@ findchar:
                ++i;
                goto findchar;
        }
-       if(i + bits > _maxlen)
+       if(i + bits > _maxlen) {
+               if (_start) *_start = i;
+               if (_len) *_len = 0;
                return false;
+       }
        // turn bt into a mask and give ch a starting value
        --bt;
        ch = (s[i] & bt);
@@ -144,7 +148,7 @@ size_t u8_strlen(const char *_s)
                }
 
                // invalid, skip u8_analyze
-               if (*s <= 0xC2)
+               if (*s < 0xC2)
                {
                        ++s;
                        continue;
@@ -188,7 +192,7 @@ size_t u8_strnlen(const char *_s, size_t n)
                }
 
                // invalid, skip u8_analyze
-               if (*s <= 0xC2)
+               if (*s < 0xC2)
                {
                        ++s;
                        --n;
@@ -233,7 +237,7 @@ size_t u8_bytelen(const char *_s, size_t n)
                }
 
                // invalid, skip u8_analyze
-               if (*s <= 0xC2)
+               if (*s < 0xC2)
                {
                        ++s;
                        ++len;
@@ -312,7 +316,7 @@ int u8_charidx(const char *_s, size_t i, size_t *len)
                }
 
                // invalid, skip u8_analyze
-               if (s[ofs] <= 0xC2)
+               if (s[ofs] < 0xC2)
                {
                        ++ofs;
                        continue;
@@ -373,7 +377,7 @@ size_t u8_prevbyte(const char *_s, size_t i)
                }
 
                // invalid, skip u8_analyze
-               if (s[ofs] <= 0xC2)
+               if (s[ofs] < 0xC2)
                {
                        ++ofs;
                        continue;
@@ -436,7 +440,7 @@ Uchar u8_getchar(const char *_s, const char **_end)
        }
        
        if (!u8_analyze(_s, &st, &ln, &ch, U8_ANALYZE_INFINITY))
-               return 0;
+               ch = 0;
        if (_end)
                *_end = _s + st + ln;
        return ch;
@@ -466,7 +470,7 @@ Uchar u8_getnchar(const char *_s, const char **_end, size_t _maxlen)
        }
        
        if (!u8_analyze(_s, &st, &ln, &ch, _maxlen))
-               return 0;
+               ch = 0;
        if (_end)
                *_end = _s + st + ln;
        return ch;
@@ -482,10 +486,10 @@ Uchar u8_getnchar(const char *_s, const char **_end, size_t _maxlen)
 int u8_fromchar(Uchar w, char *to, size_t maxlen)
 {
        if (maxlen < 1)
-               return -2;
+               return 0;
 
        if (!w)
-               return -5;
+               return 0;
 
        if (w >= 0xE000 && !utf8_enable.integer)
                w -= 0xE000;
@@ -540,7 +544,7 @@ int u8_fromchar(Uchar w, char *to, size_t maxlen)
                to[0] = 0xE0 | w;
                return 4;
        }
-       return -1;
+       return 0;
 }
 
 /** uses u8_fromchar on a static buffer
@@ -598,10 +602,13 @@ size_t u8_wcstombs(char *mb, const Uchar *wcs, size_t maxlen)
                return 0;
        for (i = 0; wcs[i] && i < maxlen-1; ++i)
        {
+               /*
                int len;
                if ( (len = u8_fromchar(wcs[i], mb, maxlen - i)) < 0)
                        return (mb - start);
                mb += len;
+               */
+               mb += u8_fromchar(wcs[i], mb, maxlen - i);
        }
        *mb = 0;
        return (mb - start);