3.3 Example: NWGetUnicodeToCollationHandle
/* exucoll.c - NWGetUnicodeToCollationHandle / NWUnicodeToCollation */
#define NWL_EXCLUDE_TIME
#define NWL_EXCLUDE_FILE
#include <nwlocale.h>
#include <unicode.h>
#include <assert.h>
void main()
{
LCONV lconv;
nint err;
nptr h = NULL;
unicode src[5] = {’A’, ’a’, ’1’, ’*’, 0}; /* Unicode input string */
unicode dest[5];
unicode noMap = 0; /* Use the default replacement char. */
nuint len;
/* On Win32, it calls wcsxfrm and converts to the same character value.
The return value does not include the null terminator.
On other platforms, it uses the Novell collation tables,
which converts to:
- the uppercase value of the character for letters
- zero for NULL
- 0xFFFF for all other characters
The return value includes the null terminator.
*/
#ifdef WIN32
unicode cmp[5] = { ’A’, ’a’, ’1’, ’*’, 0 };
nuint cmplen = 4;
#else
unicode cmp[5] = { ’A’, ’A’, 0xFFFF, 0xFFFF, 0 };
nuint cmplen = 5;
#endif
/* 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 = NWGetCollationHandle(&h);
assert (err == 0);
err = NWUnicodeToCollation(h, dest, sizeof(dest)/sizeof(unicode),
src, noMap, &len);
assert (err == 0);
assert (unicmp(dest, cmp) == 0); /* Unicode output string */
assert (len == cmplen);
NWFreeUnicodeTables();
}