#undef DEBUG
-/* Tries to turn a NULL-terminated string into UTF16.
+/**
+ * mono_unicode_from_external:
+ * @in: pointers to the buffer.
+ * @bytes: number of bytes in the string.
+ *
+ * Tries to turn a NULL-terminated string into UTF16.
*
* First, see if it's valid UTF8, in which case just turn it directly
* into UTF16. Next, run through the colon-separated encodings in
* Callers must free the returned string if not NULL. bytes holds the number
* of bytes in the returned string, not including the terminator.
*/
-gunichar2 *mono_unicode_from_external (const gchar *in, gsize *bytes)
+gunichar2 *
+mono_unicode_from_external (const gchar *in, gsize *bytes)
{
gchar *res=NULL;
gchar **encodings;
}
g_free (utf8);
} else {
- res=g_convert (in, -1, "UTF16", encodings[i], NULL, bytes, NULL);
+ /* Don't use UTF16 here. It returns the <FF FE> prepended to the string */
+ res = g_convert (in, strlen (in), "UTF8", encodings[i], NULL, bytes, NULL);
+ if (res != NULL) {
+ gchar *ptr = res;
+ res = (gchar *) g_utf8_to_utf16 (res, -1, NULL, &lbytes, NULL);
+ *bytes = (gsize) lbytes;
+ g_free (ptr);
+ }
}
if(res!=NULL) {
return(NULL);
}
-/* Tries to turn a NULL-terminated string into UTF8.
+/**
+ * mono_utf8_from_external:
+ * @in: pointer to the string buffer.
+ *
+ * Tries to turn a NULL-terminated string into UTF8.
*
* First, see if it's valid UTF8, in which case there's nothing more
* to be done. Next, run through the colon-separated encodings in
return(NULL);
}
-/* Turns NULL-terminated UTF16 into either UTF8, or the first
+/**
+ * mono_unicode_to_external:
+ * @uni: an UTF16 string to conver to an external representation.
+ *
+ * Turns NULL-terminated UTF16 into either UTF8, or the first
* working item in MONO_EXTERNAL_ENCODINGS if set. If no conversions
* work, then UTF8 is returned.
*