[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

13. Case mappings <unicase.h>

This include file defines functions for case mapping for Unicode strings and case insensitive comparison of Unicode strings and C strings.

These string functions fix the problems that were mentioned in char *’ strings, namely, they handle the Croatian LETTER DZ WITH CARON, the German LATIN SMALL LETTER SHARP S, the Greek sigma and the Lithuanian i correctly.


13.1 Case mappings of characters

The following functions implement case mappings on Unicode characters — for those cases only where the result of the mapping is a again a single Unicode character.

These mappings are locale and context independent.

WARNING! These functions are not sufficient for languages such as German, Greek and Lithuanian. Better use the functions below that treat an entire string at once and are language aware.

Function: ucs4_t uc_toupper (ucs4_t uc)

Returns the uppercase mapping of the Unicode character uc.

Function: ucs4_t uc_tolower (ucs4_t uc)

Returns the lowercase mapping of the Unicode character uc.

Function: ucs4_t uc_totitle (ucs4_t uc)

Returns the titlecase mapping of the Unicode character uc.


13.2 Case mappings of strings

Case mapping should always be performed on entire strings, not on individual characters. The functions in this sections do so.

These functions allow to apply a normalization after the case mapping. The reason is that if you want to treat ‘ä’ and ‘Ä’ the same, you most often also want to treat the composed and decomposed forms of such a character, U+00C4 LATIN CAPITAL LETTER A WITH DIAERESIS and U+0041 LATIN CAPITAL LETTER A U+0308 COMBINING DIAERESIS the same. The nf argument designates the normalization.

These functions are locale dependent. The iso639_language argument identifies the language (e.g. "tr" for Turkish). NULL means to use locale independent case mappings.

Function: const char * uc_locale_language ()

Returns the ISO 639 language code of the current locale. Returns "" if it is unknown, or in the "C" locale.

Function: uint8_t * u8_toupper (const uint8_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint8_t *resultbuf, size_t *lengthp)
Function: uint16_t * u16_toupper (const uint16_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint16_t *resultbuf, size_t *lengthp)
Function: uint32_t * u32_toupper (const uint32_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint32_t *resultbuf, size_t *lengthp)

Returns the uppercase mapping of a string.

The nf argument identifies the normalization form to apply after the case-mapping. It can also be NULL, for no normalization.

Function: uint8_t * u8_tolower (const uint8_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint8_t *resultbuf, size_t *lengthp)
Function: uint16_t * u16_tolower (const uint16_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint16_t *resultbuf, size_t *lengthp)
Function: uint32_t * u32_tolower (const uint32_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint32_t *resultbuf, size_t *lengthp)

Returns the lowercase mapping of a string.

The nf argument identifies the normalization form to apply after the case-mapping. It can also be NULL, for no normalization.

Function: uint8_t * u8_totitle (const uint8_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint8_t *resultbuf, size_t *lengthp)
Function: uint16_t * u16_totitle (const uint16_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint16_t *resultbuf, size_t *lengthp)
Function: uint32_t * u32_totitle (const uint32_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint32_t *resultbuf, size_t *lengthp)

Returns the titlecase mapping of a string.

The nf argument identifies the normalization form to apply after the case-mapping. It can also be NULL, for no normalization.


13.3 Case insensitive comparison

The following functions implement comparison that ignores differences in case and normalization.

Function: uint8_t * u8_casefold (const uint8_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint8_t *resultbuf, size_t *lengthp)
Function: uint16_t * u16_casefold (const uint16_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint16_t *resultbuf, size_t *lengthp)
Function: uint32_t * u32_casefold (const uint32_t *s, size_t n, const char *iso639_language, uninorm_t nf, uint32_t *resultbuf, size_t *lengthp)

Returns the case folded string.

Comparing u8_casefold (s1) and u8_casefold (s2) with the u8_cmp2 function is equivalent to comparing s1 and s2 with u8_casecmp.

The nf argument identifies the normalization form to apply after the case-mapping. It can also be NULL, for no normalization.

Function: int u8_casecmp (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2, const char *iso639_language, uninorm_t nf, int *resultp)
Function: int u16_casecmp (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2, const char *iso639_language, uninorm_t nf, int *resultp)
Function: int u32_casecmp (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2, const char *iso639_language, uninorm_t nf, int *resultp)
Function: int ulc_casecmp (const char *s1, size_t n1, const char *s2, size_t n2, const char *iso639_language, uninorm_t nf, int *resultp)

Compares s1 and s2, ignoring differences in case and normalization.

The nf argument identifies the normalization form to apply after the case-mapping. It can also be NULL, for no normalization.

If successful, sets *resultp to -1 if s1 < s2, 0 if s1 = s2, 1 if s1 > s2, and returns 0. Upon failure, returns -1 with errno set.

The following functions additionally take into account the sorting rules of the current locale.

Function: char * u8_casexfrm (const uint8_t *s, size_t n, const char *iso639_language, uninorm_t nf, char *resultbuf, size_t *lengthp)
Function: char * u16_casexfrm (const uint16_t *s, size_t n, const char *iso639_language, uninorm_t nf, char *resultbuf, size_t *lengthp)
Function: char * u32_casexfrm (const uint32_t *s, size_t n, const char *iso639_language, uninorm_t nf, char *resultbuf, size_t *lengthp)
Function: char * ulc_casexfrm (const char *s, size_t n, const char *iso639_language, uninorm_t nf, char *resultbuf, size_t *lengthp)

Converts the string s of length n to a string in locale encoding, in such a way that comparing u8_casexfrm (s1) and u8_casexfrm (s2) with memcmp2 is equivalent to comparing s1 and s2 with u8_casecoll.

nf must be either UNINORM_NFC, UNINORM_NFKC, or NULL for no normalization.

Function: int u8_casecoll (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2, const char *iso639_language, uninorm_t nf, int *resultp)
Function: int u16_casecoll (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2, const char *iso639_language, uninorm_t nf, int *resultp)
Function: int u32_casecoll (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2, const char *iso639_language, uninorm_t nf, int *resultp)
Function: int ulc_casecoll (const char *s1, size_t n1, const char *s2, size_t n2, const char *iso639_language, uninorm_t nf, int *resultp)

Compares s1 and s2, ignoring differences in case and normalization, using the collation rules of the current locale.

The nf argument identifies the normalization form to apply after the case-mapping. It must be either UNINORM_NFC or UNINORM_NFKC. It can also be NULL, for no normalization.

If successful, sets *resultp to -1 if s1 < s2, 0 if s1 = s2, 1 if s1 > s2, and returns 0. Upon failure, returns -1 with errno set.


13.4 Case detection

The following functions determine whether a Unicode string is entirely in upper case. or entirely in lower case, or entirely in title case, or already case-folded.

Function: int u8_is_uppercase (const uint8_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u16_is_uppercase (const uint16_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u32_is_uppercase (const uint32_t *s, size_t n, const char *iso639_language, bool *resultp)

Sets *resultp to true if mapping NFD(s) to upper case is a no-op, or to false otherwise, and returns 0. Upon failure, returns -1 with errno set.

Function: int u8_is_lowercase (const uint8_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u16_is_lowercase (const uint16_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u32_is_lowercase (const uint32_t *s, size_t n, const char *iso639_language, bool *resultp)

Sets *resultp to true if mapping NFD(s) to lower case is a no-op, or to false otherwise, and returns 0. Upon failure, returns -1 with errno set.

Function: int u8_is_titlecase (const uint8_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u16_is_titlecase (const uint16_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u32_is_titlecase (const uint32_t *s, size_t n, const char *iso639_language, bool *resultp)

Sets *resultp to true if mapping NFD(s) to title case is a no-op, or to false otherwise, and returns 0. Upon failure, returns -1 with errno set.

Function: int u8_is_casefolded (const uint8_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u16_is_casefolded (const uint16_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u32_is_casefolded (const uint32_t *s, size_t n, const char *iso639_language, bool *resultp)

Sets *resultp to true if applying case folding to NFD(S) is a no-op, or to false otherwise, and returns 0. Upon failure, returns -1 with errno set.

The following functions determine whether case mappings have any effect on a Unicode string.

Function: int u8_is_cased (const uint8_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u16_is_cased (const uint16_t *s, size_t n, const char *iso639_language, bool *resultp)
Function: int u32_is_cased (const uint32_t *s, size_t n, const char *iso639_language, bool *resultp)

Sets *resultp to true if case matters for s, that is, if mapping NFD(s) to either upper case or lower case or title case is not a no-op. Set *resultp to false if NFD(s) maps to itself under the upper case mapping, under the lower case mapping, and under the title case mapping; in other words, when NFD(s) consists entirely of caseless characters. Upon failure, returns -1 with errno set.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Bruno Haible on April, 27 2009 using texi2html 1.78a.