test_locale.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. *
  3. * Copyright (c) 2004
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. /*
  12. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE test_locale.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Helper classes for testing locale-specific expressions.
  16. */
  17. #ifndef BOOST_REGEX_REGRESS_TEST_LOCALE_HPP
  18. #define BOOST_REGEX_REGRESS_TEST_LOCALE_HPP
  19. //
  20. // defines class test_locale that handles the locale used for testing:
  21. //
  22. class test_locale
  23. {
  24. public:
  25. enum{
  26. no_test,
  27. test_no_locale,
  28. test_with_locale
  29. };
  30. test_locale(const char* c_name, boost::uint32_t lcid);
  31. ~test_locale();
  32. static int c_locale_state()
  33. {
  34. return s_c_locale;
  35. }
  36. static int cpp_locale_state()
  37. {
  38. return s_cpp_locale;
  39. }
  40. static int win_locale_state()
  41. {
  42. return s_win_locale;
  43. }
  44. static const char* c_str()
  45. {
  46. return m_name.c_str();
  47. }
  48. #ifndef BOOST_NO_STD_LOCALE
  49. static std::locale cpp_locale()
  50. {
  51. return s_cpp_locale_inst;
  52. }
  53. #endif
  54. static boost::uint32_t win_locale()
  55. {
  56. return s_win_locale_inst;
  57. }
  58. private:
  59. // the actions to take for each locale type:
  60. static int s_c_locale;
  61. static int s_cpp_locale;
  62. static int s_win_locale;
  63. // current locales:
  64. #ifndef BOOST_NO_STD_LOCALE
  65. static std::locale s_cpp_locale_inst;
  66. #endif
  67. static boost::uint32_t s_win_locale_inst;
  68. static std::string m_name;
  69. // backed up versions of the previous locales and their action state:
  70. std::string m_old_c_locale;
  71. std::string m_old_name;
  72. int m_old_c_state;
  73. #ifndef BOOST_NO_STD_LOCALE
  74. std::locale m_old_cpp_locale;
  75. #endif
  76. int m_old_cpp_state;
  77. boost::uint32_t m_old_win_locale;
  78. int m_old_win_state;
  79. };
  80. #endif