}
gunichar2 *
-g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err)
+g_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong *items_written, gboolean include_nuls, GError **err)
{
gunichar2 *outbuf, *outptr;
size_t outlen = 0;
g_return_val_if_fail (str != NULL, NULL);
- if (len < 0)
+ if (len < 0) {
+ if (include_nuls) {
+ g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED, "Conversions with embedded nulls must pass the string length");
+ return NULL;
+ }
len = strlen (str);
+ }
inptr = (char *) str;
inleft = len;
*items_written = 0;
return NULL;
- } else if (c == 0)
+ } else if (c == 0 && !include_nuls)
break;
outlen += g_unichar_to_utf16 (c, NULL);
while (inleft > 0) {
if ((n = decode_utf8 (inptr, inleft, &c)) < 0)
break;
- else if (c == 0)
+ else if (c == 0 && !include_nuls)
break;
outptr += g_unichar_to_utf16 (c, outptr);
return outbuf;
}
+gunichar2 *
+g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err)
+{
+ return g_utf8_to_utf16_general (str, len, items_read, items_written, FALSE, err);
+}
+
+gunichar2 *
+g_utf8_to_utf16_with_nuls (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err)
+{
+ return g_utf8_to_utf16_general (str, len, items_read, items_written, TRUE, err);
+}
+
gunichar *
g_utf8_to_ucs4 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err)
{
gunichar *g_utf8_to_ucs4_fast (const gchar *str, glong len, glong *items_written);
gunichar *g_utf8_to_ucs4 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
+gunichar2 *g_utf8_to_utf16_with_nuls (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err);
gchar *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **err);
gunichar *g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **err);
gchar *g_ucs4_to_utf8 (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **err);