]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - utf8lib.c
manpage: -futf8
[xonotic/gmqcc.git] / utf8lib.c
index b26f2f151ccb5a6c8a80430b1ff5015913fbcb30..12074320cf20ae6bedef7d670f72d1625dbff814 100644 (file)
--- a/utf8lib.c
+++ b/utf8lib.c
@@ -35,12 +35,12 @@ static Uchar utf8_range[5] = {
 /** Analyze the next character and return various information if requested.
  * @param _s      An utf-8 string.
  * @param _start  Filled with the start byte-offset of the next valid character
- * @param _len    Fileed with the length of the next valid character
+ * @param _len    Filled with the length of the next valid character
  * @param _ch     Filled with the unicode value of the next character
  * @param _maxlen Maximum number of bytes to read from _s
  * @return        Whether or not another valid character is in the string
  */
-static bool u8_analyze(const char *_s, size_t *_start, size_t *_len, Uchar *_ch, size_t _maxlen)
+bool u8_analyze(const char *_s, size_t *_start, size_t *_len, Uchar *_ch, size_t _maxlen)
 {
        const unsigned char *s = (const unsigned char*)_s;
        size_t i, j;
@@ -74,6 +74,7 @@ static bool u8_analyze(const char *_s, size_t *_start, size_t *_len, Uchar *_ch,
                        /* in gmqcc, invalid / overlong encodings are considered an error
                         * goto findchar;
                         */
+                       if (!s[i]) goto done;
                        return false;
                }
                ch = (ch << 6) | (s[i+j] & 0x3F);
@@ -87,6 +88,7 @@ static bool u8_analyze(const char *_s, size_t *_start, size_t *_len, Uchar *_ch,
                return false;
        }
 
+done:
        if (_start)
                *_start = i;
        if (_len)