3.4 Example: NWGetUnicodeToLocalHandle
/* exuu2l.c - NWGetUnicodeToLocalHandle / NWUnicodeToLocal example */
#define NWL_EXCLUDE_TIME
#define NWL_EXCLUDE_FILE
#include <nwlocale.h>
#include <unicode.h>
#include <string.h>
#include <assert.h>
void main()
{
LCONV lconv;
nint err;
nptr h = NULL;
unicode src[5] = {’a’, ’b’, ’c’, ’d’, 0}; /* Unicode input string */
nuint8 dest[5];
nuint8 noMap = 0; /* Use the default replacement char. */
nuint len;
/* Get the country ID and code page from the operating system. */
NWLlocaleconv(&lconv);
err = NWInitUnicodeTables(lconv.country_id, lconv.code_page);
assert (err == 0);
err = NWGetUnicodeToLocalHandle(&h);
assert (err == 0);
err = NWUnicodeToLocal(h, dest, sizeof(dest), src, noMap, &len);
assert (err == 0);
assert (strcmp(dest, "abcd") == 0); /* Local output string */
assert (len == 5); /* Output size includes null */
NWFreeUnicodeTables();
}