Example of using various text conversion functions.
#include <boost/locale.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <iostream>
int main()
{
std::cout << "Need ICU support for this example!\nConversion below will likely be wrong!\n";
std::locale loc = gen("");
std::locale::global(loc);
std::cout.imbue(loc);
std::ios_base::sync_with_stdio(false);
std::cout << "Correct case conversion can't be done by simple, character by character conversion\n";
std::cout << "because case conversion is context sensitive and not a 1-to-1 conversion.\n";
std::cout << "For example:\n";
const std::string gruessen("grüßen");
std::cout << " German " << gruessen << " would be incorrectly converted to " << boost::to_upper_copy(gruessen);
<< " where ß is replaced with SS.\n";
const std::string greek("ὈΔΥΣΣΕΎΣ");
std::cout << " Greek " << greek << " would be incorrectly converted to " << boost::to_lower_copy(greek);
<< " where Σ is converted to σ or to ς, according to position in the word.\n";
std::cout
<< "Such type of conversion just can't be done using std::toupper/boost::to_upper* that work on character "
"by character base.\n"
"Also std::toupper is not fully applicable when working with variable character length like UTF-8 or UTF-16\n"
"limiting the correct behavior to BMP or ASCII only\n";
}
the major class used for locale generation
Definition: generator.hpp:101
static localization_backend_manager global()
std::basic_string< CharType > to_upper(const CharType *begin, const CharType *end, const std::locale &loc=std::locale())
Definition: conversion.hpp:120
std::basic_string< CharType > to_lower(const CharType *begin, const CharType *end, const std::locale &loc=std::locale())
Definition: conversion.hpp:150