info.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 BOOST_LOCALE_INFO_HPP_INCLUDED
  9. #define BOOST_LOCALE_INFO_HPP_INCLUDED
  10. #include <boost/locale/config.hpp>
  11. #ifdef BOOST_MSVC
  12. # pragma warning(push)
  13. # pragma warning(disable : 4275 4251 4231 4660)
  14. #endif
  15. #include <locale>
  16. #include <string>
  17. namespace boost {
  18. namespace locale {
  19. ///
  20. /// \brief a facet that holds general information about locale
  21. ///
  22. /// This facet should be always created in order to make all Boost.Locale functions work
  23. ///
  24. class BOOST_LOCALE_DECL info : public std::locale::facet
  25. {
  26. public:
  27. static std::locale::id id; ///< This member uniquely defines this facet, required by STL
  28. ///
  29. /// String information about the locale
  30. ///
  31. enum string_propery {
  32. language_property, ///< ISO 639 language id
  33. country_property, ///< ISO 3166 country id
  34. variant_property, ///< Variant for locale
  35. encoding_property, ///< encoding name
  36. name_property ///< locale name
  37. };
  38. ///
  39. /// Integer information about locale
  40. ///
  41. enum integer_property {
  42. utf8_property ///< Non zero value if uses UTF-8 encoding
  43. };
  44. ///
  45. /// Standard facet's constructor
  46. ///
  47. info(size_t refs = 0) : std::locale::facet(refs)
  48. {
  49. }
  50. ///
  51. /// Get language name
  52. ///
  53. std::string language() const
  54. {
  55. return get_string_property(language_property);
  56. }
  57. ///
  58. /// Get country name
  59. ///
  60. std::string country() const
  61. {
  62. return get_string_property(country_property);
  63. }
  64. ///
  65. /// Get locale variant
  66. ///
  67. std::string variant() const
  68. {
  69. return get_string_property(variant_property);
  70. }
  71. ///
  72. /// Get encoding
  73. ///
  74. std::string encoding() const
  75. {
  76. return get_string_property(encoding_property);
  77. }
  78. ///
  79. /// Get the name of the locale, like en_US.UTF-8
  80. ///
  81. std::string name() const
  82. {
  83. return get_string_property(name_property);
  84. }
  85. ///
  86. /// True if the underlying encoding is UTF-8 (for char streams and strings)
  87. ///
  88. bool utf8() const
  89. {
  90. return get_integer_property(utf8_property) != 0;
  91. }
  92. #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
  93. std::locale::id& __get_id (void) const { return id; }
  94. #endif
  95. protected:
  96. ///
  97. /// Get string property by its id \a v
  98. ///
  99. virtual std::string get_string_property(string_propery v) const = 0;
  100. ///
  101. /// Get integer property by its id \a v
  102. ///
  103. virtual int get_integer_property(integer_property v) const = 0;
  104. };
  105. }
  106. }
  107. #ifdef BOOST_MSVC
  108. #pragma warning(pop)
  109. #endif
  110. #endif
  111. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4