locale_info.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // locale_info.cpp ---------------------------------------------------------//
  2. // Copyright Beman Dawes 2011
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. #include <locale>
  6. #include <iostream>
  7. #include <exception>
  8. #include <cstdlib>
  9. using namespace std;
  10. #ifdef _MSC_VER
  11. # pragma warning(push)
  12. # pragma warning(disable: 4996) // ... Function call with parameters that may be unsafe
  13. #endif
  14. namespace
  15. {
  16. void facet_info(const locale& loc, const char* msg)
  17. {
  18. cout << "has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >("
  19. << msg << ") is "
  20. << (has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc)
  21. ? "true\n"
  22. : "false\n");
  23. }
  24. void default_info()
  25. {
  26. try
  27. {
  28. locale loc;
  29. cout << "\nlocale default construction OK" << endl;
  30. facet_info(loc, "locale()");
  31. }
  32. catch (const exception& ex)
  33. {
  34. cout << "\nlocale default construction threw: " << ex.what() << endl;
  35. }
  36. }
  37. void null_string_info()
  38. {
  39. try
  40. {
  41. locale loc("");
  42. cout << "\nlocale(\"\") construction OK" << endl;
  43. facet_info(loc, "locale(\"\")");
  44. }
  45. catch (const exception& ex)
  46. {
  47. cout << "\nlocale(\"\") construction threw: " << ex.what() << endl;
  48. }
  49. }
  50. void classic_info()
  51. {
  52. try
  53. {
  54. locale loc(locale::classic());
  55. cout << "\nlocale(locale::classic()) copy construction OK" << endl;
  56. facet_info(loc, "locale::classic()");
  57. }
  58. catch (const exception& ex)
  59. {
  60. cout << "\nlocale(locale::clasic()) copy construction threw: " << ex.what() << endl;
  61. }
  62. }
  63. }
  64. int main()
  65. {
  66. const char* lang = getenv("LANG");
  67. cout << "\nLANG environmental variable is "
  68. << (lang ? lang : "not present") << endl;
  69. default_info();
  70. null_string_info();
  71. classic_info();
  72. return 0;
  73. }
  74. #ifdef _MSC_VER
  75. # pragma warning(pop)
  76. #endif