1//
2// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3// Copyright (c) 2023 Alexander Grund
4//
5// Distributed under the Boost Software License, Version 1.0.
6// https://www.boost.org/LICENSE_1_0.txt
7
8#include <boost/locale.hpp>
9#include <boost/algorithm/string/case_conv.hpp>
10#include <iostream>
11
12int main()
13{
14 if(boost::locale::localization_backend_manager::global().get_all_backends().at(n: 0) != "icu")
15 std::cout << "Need ICU support for this example!\nConversion below will likely be wrong!\n";
16
17 // Create system default locale
18 boost::locale::generator gen;
19 std::locale loc = gen("");
20 std::locale::global(loc: loc);
21 std::cout.imbue(loc: loc);
22
23 // This is needed to prevent the C stdio library from
24 // converting strings to narrow on some platforms
25 std::ios_base::sync_with_stdio(sync: false);
26
27 std::cout << "Correct case conversion can't be done by simple, character by character conversion\n";
28 std::cout << "because case conversion is context sensitive and not a 1-to-1 conversion.\n";
29 std::cout << "For example:\n";
30 const std::string gruessen("grüßen");
31 std::cout << " German " << gruessen << " would be incorrectly converted to " << boost::to_upper_copy(Input: gruessen);
32 std::cout << ", while Boost.Locale converts it to " << boost::locale::to_upper(str: gruessen) << std::endl
33 << " where ß is replaced with SS.\n";
34 const std::string greek("ὈΔΥΣΣΕΎΣ");
35 std::cout << " Greek " << greek << " would be incorrectly converted to " << boost::to_lower_copy(Input: greek);
36 std::cout << ", while Boost.Locale correctly converts it to " << boost::locale::to_lower(str: greek) << std::endl
37 << " where Σ is converted to σ or to ς, according to position in the word.\n";
38 std::cout
39 << "Such type of conversion just can't be done using std::toupper/boost::to_upper* that work on character "
40 "by character base.\n"
41 "Also std::toupper is not fully applicable when working with variable character length like UTF-8 or UTF-16\n"
42 "limiting the correct behavior to BMP or ASCII only\n";
43}
44
45// boostinspect:noascii
46

source code of boost/libs/locale/examples/conversions.cpp