(file) Return to wide-character-support.txt CVS log (file) (dir) Up to [OMI] / omi / doc

File: [OMI] / omi / doc / wide-character-support.txt (download)
Revision: 1.1, Mon Apr 20 17:19:51 2015 UTC (9 years ago) by krisbash
Branch: MAIN
CVS Tags: OMI_1_0_8_2, OMI_1_0_8_1, HEAD
OMI 1.0.8-1

To build OMI to support wide characters, configure like this:

    $ ./configure --enable-wchar

This enables the use of wide characters in the code and defines the following 
macros:

    CONFIG_ENABLE_WCHAR
    MI_CHAR_TYPE==2

Depending on how these macros are defined, one of the following type definitions
is introduced (note ZChar is the same size as MI_Char):

    typedef wchar_t ZChar;
    typedef char ZChar;

Regardless of the size of ZChar, file and directory names and their contents
are always represented as single character.

Internally XML is always represented by ZChar. But on the wire it can be
either UTF-8 or UTF-16 (note: UTF-16 not supported yet). When XML requests
are received, they are converted to ZChar before they are parsed. After XML
responses are formed, they are converted to the XML wire format before they
are sent.

Note that in Windows, UTF-16 is the same as wchar_t. This is not so on most
Linux and Unix platforms, where sizeof(wchar_t) == 4.

To support building for single or wide character, we introduced the following 
functions:

    Zprintf()
    Fzprintf()
    Szprintf()
    Vzprintf()
    Vfzprintf()
    Vszprintf()

These replace the following functions (which should never be used):

    wprintf()
    fwprintf()
    swprintf()
    vwprintf()
    vfwprintf()
    vswprintf()

The former are similar to the latter except for their treatment of three
format specifiers:

    %s - for 'char' type.
    %S - for 'wchar_t' type.
    %Z - for 'ZChar' type.

For example:

    const char* str;
    const wchar_t* wstr;
    const ZChar* zstr; /* same as MI_Char* */
    .
    .
    .
    Fzprintf(ZT("%s %S %Z"), str, wstr, zstr);

Since it is hard for the reader to deduce the type of each string from looking
at the call, we introduced three empty inline functions for catching type
errors:

    scs() - for %s
    wcs() - for %S
    zcs() - for %Z

The above example, should be changed to this:

    Fzprintf(ZT("%s %S %Z"), scs(str), wcs(wstr), zcs(zstr));

This will tests assumptions and produce compile time errors where those
assumptions are wrong.


ViewCVS 0.9.2