XXX X    

The thread locale storage is the key to much of the xICU code.  Systems not using thread support use a static pointer in place of the TLS pointer.  This pointer is used to find the XIUA_Thread structure. This structure contains the thread specific fields. This contains XIUA_Locale pointers work storage management fields, the xIUA error code and a pointer field to make xiua_strtok thread safe.

The storage management function is designed to provide internal work storage to xIUA functions that need it. Because malloc/free have a bit of overhead associated with keeping storage from being too fragmented, xIUA reuses its work storage. Each routine that needs storage calculates how much it needs. If it is more than the current work buffer size the buffer is expanded. If the size is larger then the buffer limit a temporary buffer is malloced. This buffer is freed on the next call to check buffer size unless the next request is also larger than the buffer limit and fits in the temporary buffer.

The XIUA_Thread structure has three XIUA_Locale pointers. The current locale pointer points to the currently active locale. The default locale is a pointer to the locale to be made the active locale after a locale close if the close indicates that it want the default locale to be made the active locale. The third pointer is a pointer to the first locale structure in the chain of locales. The locale structures are chained together so that this pointer will let you navigate the entire list of open locales for this thread.

The XIUA_Locale structure contains forward and backward chaining pointers and a pointer back to the XIUA_Thread structure. There can be any number of locales but only one thread structure per thread. The locale structures also have the locale, character set and time zone of each locale. Even though ICU expects the time zone as a UChar field, it is easier for applications to use the ASCII representation. To convert it, xIUA uses a fast transform since it is limited to 7 bit ASCII characters.

The locale also carries an ICU converter that is opened for the character set. This means that a locale that is a code page locale and uses Shift_JIS will handle xiua_ChartoUTF8 that same way as a UTF-8 locale with a Shift_JIS character set (xiua_OpenLocale("ja_JP.Shift_JIS",XDFUTF8);). However, xiua_NativetoUTF8 works differently. The code page locale will convert form Shift_JIS to UTF-8 and the UTF-8 locale will just copy the data.

The locale also carries a code set identifier. This enumerator make character set identification easier. It identifies not the character set but the set of rules needed to handle the characters set. These rules govern validation of strings to see that the character data in encoded properly. It is also use to determine character length values and how to navigate the character string or fix broken characters.

X.Net Inc. Home Page

xIUA Home Page