Boost.Locale
|
Boost.Locale provides several functions for basic string manipulation:
All these functions receive an std::locale
object as parameter or use a global locale by default.
Global locale is used in all examples below.
For example:
Would print:
Upper GRÜSSEN Lower grüßen Title Grüßen Fold grüssen
There are existing functions to_upper
and to_lower
in the Boost.StringAlgo library, however the Boost.Locale functions operate on an entire string instead of performing incorrect character-by-character conversions.
For example:
Would give in output:
GRÜßEN GRÜSSEN
Where a letter "ß" was not converted correctly to double-S in first case because of a limitation of std::ctype
facet.
This is even more problematic in case of UTF-8 encodings where non US-ASCII are not converted at all. For example, this code:
Would modify ASCII characters only
GRüßEN GRÜSSEN
Unicode normalization is the process of converting strings to a standard form, suitable for text processing and comparison. For example, character "ü" can be represented by a single code point or a combination of the character "u" and the diaeresis "¨". Normalization is an important part of Unicode text processing.
Unicode defines four normalization forms. Each specific form is selected by a flag passed to normalize function:
For more details on normalization forms, read this report on unicode.org.