[eglib] Move definition of GPid to eglib-config.h
[mono.git] / eglib / src / gutf8.c
index 3f1fab47293fcc50fd6e429845ab3dd96b7e479e..fed6dd753ca6921ff34a30fa99b43c67906853e1 100644 (file)
@@ -65,17 +65,20 @@ utf8_to_utf16_len (const gchar *str, glong len, glong *items_read, GError **erro
        glong in_pos, ret;
 
        if (len < 0)
-               len = strlen (str);
+               len = (glong) strlen (str);
 
        in_pos = 0;
        ret = 0;
 
        /* Common case */
-       for (in_pos = 0; in_pos < len && str [in_pos] < 0x80; in_pos++)
+       for (in_pos = 0; in_pos < len && (guchar) str [in_pos] < 0x80; in_pos++)
                ret ++;
 
-       if (in_pos == len)
+       if (in_pos == len) {
+               if (items_read)
+                       *items_read = in_pos;
                return ret;
+       }
 
        mb_size = 0;
        mb_remain = 0;
@@ -212,8 +215,10 @@ g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_wr
                *error = NULL;
 
        if (len < 0)
-               len = strlen (str);
+               len = (glong) strlen (str);
 
+       if (items_read)
+               *items_read = 0;
        if (items_written)
                *items_written = 0;
        utf16_len = utf8_to_utf16_len (str, len, items_read, error);
@@ -311,6 +316,8 @@ g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *item
        out_pos = 0;
        surrogate = FALSE;
 
+       if (items_read)
+               *items_read = 0;
        if (items_written)
                *items_written = 0;
        utf8_len = utf16_to_utf8_len (str, len, items_read, error);
@@ -331,6 +338,7 @@ g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *item
                        } else {
                                surrogate = 0;
                                /* invalid surrogate pair */
+                               ++in_pos;
                                continue;
                        }
                } else {
@@ -347,6 +355,7 @@ g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *item
                        else if (ch >= 0xD800 && ch <= 0xDBFF)
                                surrogate = ch;
                        else if (ch >= 0xDC00 && ch <= 0xDFFF) {
+                               ++in_pos;
                                /* invalid surrogate pair */
                                continue;
                        }