All pastes #1579179 Raw Edit

teuf

public text v1 · immutable
#1579179 ·published 2009-09-25 14:18 UTC
rendered paste body
/* gcc -Wall -Werror $(pkg-config --cflags --libs glib-2.0) ./test-utf16.c */#include <glib.h>int main (int argc, char **argv){    /* UTF16_BE string with a BOM */    const char utf16_be[] = { 0xfe, 0xff, 0x00, 0x64, 0x00, 0x65, 0x00, 0x65,			      0x00, 0x20, 0x00, 0x6c, 0x00, 0x79, 0x00, 0x6c,                              0x00, 0x61 };    char *utf8;    glong items_read;    glong items_written;    GError *error = NULL;    /* on x86 machines, g_utf16_to_utf8 doesn't handle UTF16-BE strings */    utf8 = g_utf16_to_utf8 ((const gunichar2 *)utf16_be, 9,                            &items_read, &items_written,                            &error);    g_print ("read %ld unichar2, wrote %ld bytes, utf8 is %p\n",             items_read, items_written, utf8);    g_print ("error is %p\n", error);    g_assert (g_utf8_validate (utf8, -1, NULL));    return 0;}