ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

126 lines
3.1 KiB

  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. #ifndef BOOSTER_LOCLAE_TEST_LOCALE_TOOLS_HPP
  9. #define BOOSTER_LOCLAE_TEST_LOCALE_TOOLS_HPP
  10. #include <booster/locale/encoding.h>
  11. #include <fstream>
  12. #include <stdlib.h>
  13. template<typename Char>
  14. std::basic_string<Char> to_correct_string(std::string const &e,std::locale /*l*/)
  15. {
  16. return booster::locale::conv::to_utf<Char>(e,"UTF-8");
  17. }
  18. template<>
  19. inline std::string to_correct_string(std::string const &e,std::locale l)
  20. {
  21. return booster::locale::conv::from_utf(e,l);
  22. }
  23. bool has_std_locale(std::string const &name)
  24. {
  25. try {
  26. std::locale tmp(name.c_str());
  27. return true;
  28. }
  29. catch(...) {
  30. return false;
  31. }
  32. }
  33. inline bool test_std_supports_SJIS_codecvt(std::string const &locale_name)
  34. {
  35. bool res = true;
  36. {
  37. // Japan in Shift JIS/cp932
  38. char const *japan_932 = "\x93\xfa\x96\x7b";
  39. std::ofstream f("test-siftjis.txt");
  40. f<<japan_932;
  41. f.close();
  42. }
  43. try {
  44. std::wfstream test;
  45. test.imbue(std::locale(locale_name.c_str()));
  46. test.open("test-siftjis.txt");
  47. // Japan in Unicode
  48. std::wstring cmp = L"\u65e5\u672c";
  49. std::wstring ref;
  50. test >> ref;
  51. res = ref == cmp;
  52. }
  53. catch(std::exception const &)
  54. {
  55. res = false;
  56. }
  57. remove("test-siftjis.txt");
  58. return res;
  59. }
  60. std::string get_std_name(std::string const &name,std::string *real_name = 0)
  61. {
  62. if(has_std_locale(name)) {
  63. if(real_name)
  64. *real_name = name;
  65. return name;
  66. }
  67. #ifdef BOOSTER_WIN_NATIVE
  68. bool utf8=name.find("UTF-8")!=std::string::npos;
  69. if(name=="en_US.UTF-8" || name == "en_US.ISO8859-1") {
  70. if(has_std_locale("English_United States.1252")) {
  71. if(real_name)
  72. *real_name = "English_United States.1252";
  73. return utf8 ? name : "en_US.windows-1252";
  74. }
  75. return "";
  76. }
  77. else if(name=="he_IL.UTF-8" || name == "he_IL.ISO8859-8") {
  78. if(has_std_locale("Hebrew_Israel.1255")) {
  79. if(real_name)
  80. *real_name = "Hebrew_Israel.1255";
  81. return utf8 ? name : "he_IL.windows-1255";
  82. return name;
  83. }
  84. }
  85. else if(name=="ru_RU.UTF-8") {
  86. if(has_std_locale("Russian_Russia.1251")) {
  87. if(real_name)
  88. *real_name = "Russian_Russia.1251";
  89. return name;
  90. }
  91. }
  92. else if(name == "tr_TR.UTF-8") {
  93. if(has_std_locale("Turkish_Turkey.1254")) {
  94. if(real_name)
  95. *real_name = "Turkish_Turkey.1254";
  96. return name;
  97. }
  98. }
  99. if(name == "ja_JP.SJIS") {
  100. if(has_std_locale("Japanese_Japan.932")) {
  101. if(real_name)
  102. *real_name = "Japanese_Japan.932";
  103. return name;
  104. }
  105. return "";
  106. }
  107. #endif
  108. return "";
  109. }
  110. #endif
  111. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4