12.07.2015 Views

free openSS

free openSS

free openSS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Annex B. Localization – Technical Aspects ❘ 41POSIX LocalesAccording to POSIX, standard C library functions are internationalized according to the following categories:CategoryLC_CTYPELC_COLLATELC_TIMELC_NUMERICLC_MONETARYLC_MESSAGESDescriptioncharacter classificationstring collationdate and time formatnumber formatcurrency formatmessages in locale languageSetting LocaleA C application can set current locale with the setlocale() function (declared in ). The firstargument indicates the category to be set; alternatively, LC_ALL is used to set all categories. The secondargument is the locale name to be chosen, or alternatively empty string (“”) is used to rely on systemenvironment setting.Therefore, the program initialization of a typical internationalized C program may appear as follows:#include ...const char *prev_locale;prev_locale = setlocale (LC_ALL, “”);and the system environments are looked up to determine the appropriate locale as follows:1. If LC_ALL is defined, it shall be used as the locale name.2. Otherwise, if corresponding values of LC_CTYPE, LC_COLLATE, LC_MESSAGES are defined,they shall be used as locale names for corresponding categories.3. For categories that are still undefined by the above checks, and LANG is defined, this is usedas the locale name.4. For categories that are still undefined by the above checks, “C” (or “POSIX”) locale shall be used.The “C” or “POSIX” locale is a dummy locale in which all behaviours are C defaults (e.g. ASCII sort forLC_COLLATE).LC_CTYPELC_CTYPE defines character classification for functions declared in : iscntl() isgraph() isprint() isspace() ispunct() isalnum() isalpha() isdigit() isxdigit() islower() isupper() tolower() toupper()Since glibc is Unicode-based, and all character sets are defined as Unicode subsets, it makes no sense toredefine character properties in each locale. Typically, the LC_CTYPE category in most locale definitionsrefers to the default definition (called “i18n”).LC_COLLATEC functions that are affected by LC_COLLATE are strcoll() and strxfrm().strcoll() compares two strings in a similar manner as strcmp() but in a locale-dependent way.Note that the behaviour strcmp()never changes under different locales.strxfrm() translates string into a form that can be compared using the plain strcmp() to get thesame result as when directly compared with strcoll().

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!