Blame view

3rdparty/boost_1_81_0/libs/locale/examples/conversions.cpp 1.63 KB
73ef4ff3   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  //
  // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  //
  // Distributed under the Boost Software License, Version 1.0.
  // https://www.boost.org/LICENSE_1_0.txt
  
  #include <boost/locale.hpp>
  #include <boost/algorithm/string/case_conv.hpp>
  #include <iostream>
  
  #include <ctime>
  
  int main()
  {
      using namespace boost::locale;
      // Create system default locale
      generator gen;
      std::locale loc = gen("");
      std::locale::global(loc);
      std::cout.imbue(loc);
  
      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 1-to-1 conversion\n";
      std::cout << "For example:\n";
      std::cout << "   German grüßen correctly converted to " << to_upper("grüßen") << ", instead of incorrect "
                << boost::to_upper_copy(std::string("grüßen")) << std::endl;
      std::cout << "     where ß is replaced with SS\n";
      std::cout << "   Greek ὈΔΥΣΣΕΎΣ is correctly converted to " << to_lower("ὈΔΥΣΣΕΎΣ") << ", instead of incorrect "
                << boost::to_lower_copy(std::string("ὈΔΥΣΣΕΎΣ")) << std::endl;
      std::cout << "     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 that work on character base, also "
                   "std::toupper is\n";
      std::cout << "not even applicable when working with variable character length like in UTF-8 or UTF-16 limiting the "
                   "correct\n";
      std::cout << "behavior to unicode subset BMP or ASCII only\n";
  }
  
  // boostinspect:noascii