xIUA supports four data types; UTF-32, UTF-16, UTF-8 and code page. It also provides for dynamic as well as static data type switching. Many of its functions are designed as a set of functions. For example:

xiua_strcmp(char *str1, char * str2);
xiu2_strcmp(UChar16 *str1, UChar16 * str2);
xiu4_strcmp(UChar32 *str1, UChar32 * str2);
xiu8_strcmp(UChar8 *str1, UChar8 * str2);
xicp_strcmp(UChar8 *str1, UChar8 * str2);

The first function is the dynamic function and it invokes one of the explicit functions depending on the data type of the current locale. If the current locale was set for UTF-16 data then xiua_strcmp will call xiu2_strcmp. Even though the parameters are char* the data in the buffers must contain UTF-16 data.

Why would you want this type of flexibility? One example is where you define fields as wchar_t. This can be either 16 or 32 bits depending on the operating system. You can determine this in one place where you open the locale and all of your code will run unchanged. In the case of the xiua_strcmp function it always compares UTF-32, UTF-16 and UTF-8 in Unicode code point order so that the compare sequences do not change between different Unicode encodings. This type of flexibility could have also been done statically so that although the source is the same you select the various type of data encoding statically at compile time.

The static approach does not work for all situations. For example if the code is web server code and you can support the newer browsers such as IE 5.x and Netscape 6.0 using utf-8 and the older browsers in code page, you want to be able to switch data types dynamically.

This process automatically adjusts lengths that are passed to and returns from the function. In some cases xIUA converts the values and calls the ICU functions. In other cases the functions are separately implemented for the different data types.


X.Net Inc. Home Page

xIUA Home Page