I keep getting errors popup whenever my source input is not UTF-8 so I'm clearly using it wrong somehow, this is how I've been using it so far:
Code:
U8.used = utflen(u8) + 1;
if ( (ret = vecsize( &CB, U8.size * 4 )) != EXIT_SUCCESS )
goto literalc_cleanup;
cb = CB.buff;
iconvSrcBuff = U8.buff;
iconvSrcSize = U8.used * sizeof(char8_t);
iconvDstBuff = CB.buff;
iconvDstSize = CB.size;
if ( encoding != std_encoding_utf ) {
while ( iconvSrcSize && iconvDstSize ) {
bytes = iconv( utf_to_iconv[encoding],
&iconvSrcBuff, &iconvSrcSize,
&iconvDstBuff, &iconvDstSize );
if ( !bytes ) break;
if ( errno != EXIT_SUCCESS ) break;
}
if ( errno != EXIT_SUCCESS ) {
// Should not reach here in unit tests but does
ret = errno;
errno = 0;
FAIL( stderr, ret, "" );
}
}
else (void)utfcpy( cb, U8.used, u8, U8.used );
And this is the section of unit tests that it fails at:
Code:
...
u8"abcd\u2ea2wxyz" = 64636261, 'abcd\u2ea2wxyz'
u'cd' = 00FFFE63, '
u'\u2ea2' = 0000A22E, '
u'a\u2ea2' = 2E6100A2, '
u'\u2ea2a' = 00A22E61, '
u"\u2ea2" = 00002EA2, '
Last character was ' '
Character hex: 00 00 00 00 00 00
rm libtsc.so libbase62.so char.elf libnext.so
char.c:692:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
char.c:692:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
make: *** [makefile:36: char.run] Error 1
Compilation failed.
Edit 1: Just thought to clear errno before starting the loop so something else must be setting it instead, or it's setting it elsewhere, give me a few minutes
Edit 2: Turned out printf was setting it, despite supporting %ls it doesn't actually support doing it, resolved it with a switch statement which was need anyway
Code:
switch ( encoding ) {
case std_encoding_wcs:
for ( i = 0; (c = ((wchar_t*)cb)[i]); ++i )
putwchar( c );
putchar('\'');
break;
case std_encoding_u16:
for ( i = 0; (c = ((char16_t*)cb)[i]); ++i )
putwchar( c );
putchar('\'');
break;
case std_encoding_u32:
for ( i = 0; (c = ((char32_t*)cb)[i]); ++i )
putwchar( c );
putchar('\'');
break;
default:
printf( "%s'", cb );
}