• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //  Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 //  Distributed under the Boost Software License, Version 1.0. (See
5 //  accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7 //
8 
9 //
10 // ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
11 //
12 // BIG FAT WARNING FOR Microsoft Visual Studio Users
13 //
14 // YOU NEED TO CONVERT THIS SOURCE FILE ENCODING TO UTF-8 WITH BOM ENCODING.
15 //
16 // Unfortunately MSVC understands that the source code is encoded as
17 // UTF-8 only if you add useless BOM in the beginning.
18 //
19 // So, before you compile "wide" examples with MSVC, please convert them to text
20 // files with BOM. There are two very simple ways to do it:
21 //
22 // 1. Open file with Notepad and save it from there. It would convert
23 //    it to file with BOM.
24 // 2. In Visual Studio go File->Advances Save Options... and select
25 //    Unicode (UTF-8  with signature) Codepage 65001
26 //
27 // Note: once converted to UTF-8 with BOM, this source code would not
28 // compile with other compilers, because no-one uses BOM with UTF-8 today
29 // because it is absolutely meaningless in context of UTF-8.
30 //
31 // ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
32 //
33 #include <boost/locale.hpp>
34 #include <boost/algorithm/string/case_conv.hpp>
35 #include <iostream>
36 
37 #include <ctime>
38 
39 
main()40 int main()
41 {
42     using namespace boost::locale;
43     using namespace std;
44     // Create system default locale
45     generator gen;
46     locale loc=gen("");
47     locale::global(loc);
48     wcout.imbue(loc);
49 
50     // This is needed to prevent C library to
51     // convert strings to narrow
52     // instead of C++ on some platforms
53     std::ios_base::sync_with_stdio(false);
54 
55 
56     wcout<<L"Correct case conversion can't be done by simple, character by character conversion"<<endl;
57     wcout<<L"because case conversion is context sensitive and not 1-to-1 conversion"<<endl;
58     wcout<<L"For example:"<<endl;
59     wcout<<L"   German grüßen correctly converted to "<<to_upper(L"grüßen")<<L", instead of incorrect "
60                     <<boost::to_upper_copy(std::wstring(L"grüßen"))<<endl;
61     wcout<<L"     where ß is replaced with SS"<<endl;
62     wcout<<L"   Greek ὈΔΥΣΣΕΎΣ is correctly converted to "<<to_lower(L"ὈΔΥΣΣΕΎΣ")<<L", instead of incorrect "
63                     <<boost::to_lower_copy(std::wstring(L"ὈΔΥΣΣΕΎΣ"))<<endl;
64     wcout<<L"     where Σ is converted to σ or to ς, according to position in the word"<<endl;
65     wcout<<L"Such type of conversion just can't be done using std::toupper that work on character base, also std::toupper is "<<endl;
66     wcout<<L"not fully applicable when working with variable character length like in UTF-8 or UTF-16 limiting the correct "<<endl;
67     wcout<<L"behavoir to BMP or ASCII only"<<endl;
68 
69 }
70 
71 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
72 
73 // boostinspect:noascii
74