conversions.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #include <boost/locale.hpp>
  9. #include <boost/algorithm/string/case_conv.hpp>
  10. #include <iostream>
  11. #include <ctime>
  12. int main()
  13. {
  14. using namespace boost::locale;
  15. using namespace std;
  16. // Create system default locale
  17. generator gen;
  18. locale loc=gen("");
  19. locale::global(loc);
  20. cout.imbue(loc);
  21. cout<<"Correct case conversion can't be done by simple, character by character conversion"<<endl;
  22. cout<<"because case conversion is context sensitive and not 1-to-1 conversion"<<endl;
  23. cout<<"For example:"<<endl;
  24. cout<<" German grüßen correctly converted to "<<to_upper("grüßen")<<", instead of incorrect "
  25. <<boost::to_upper_copy(std::string("grüßen"))<<endl;
  26. cout<<" where ß is replaced with SS"<<endl;
  27. cout<<" Greek ὈΔΥΣΣΕΎΣ is correctly converted to "<<to_lower("ὈΔΥΣΣΕΎΣ")<<", instead of incorrect "
  28. <<boost::to_lower_copy(std::string("ὈΔΥΣΣΕΎΣ"))<<endl;
  29. cout<<" where Σ is converted to σ or to ς, according to position in the word"<<endl;
  30. cout<<"Such type of conversion just can't be done using std::toupper that work on character base, also std::toupper is "<<endl;
  31. cout<<"not even applicable when working with variable character length like in UTF-8 or UTF-16 limiting the correct "<<endl;
  32. cout<<"behavior to unicode subset BMP or ASCII only"<<endl;
  33. }
  34. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
  35. // boostinspect:noascii