info.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #ifndef BOOST_LOCALE_INFO_HPP_INCLUDED
  7. #define BOOST_LOCALE_INFO_HPP_INCLUDED
  8. #include <boost/locale/config.hpp>
  9. #include <locale>
  10. #include <string>
  11. #ifdef BOOST_MSVC
  12. # pragma warning(push)
  13. # pragma warning(disable : 4275 4251 4231 4660)
  14. #endif
  15. namespace boost { namespace locale {
  16. /// \brief a facet that holds general information about locale
  17. ///
  18. /// This facet should be always created in order to make all Boost.Locale functions work
  19. class BOOST_LOCALE_DECL info : public std::locale::facet {
  20. public:
  21. ~info();
  22. static std::locale::id id; ///< This member uniquely defines this facet, required by STL
  23. /// String information about the locale
  24. enum string_propery {
  25. language_property, ///< ISO 639 language id
  26. country_property, ///< ISO 3166 country id
  27. variant_property, ///< Variant for locale
  28. encoding_property, ///< encoding name
  29. name_property ///< locale name
  30. };
  31. /// Integer information about locale
  32. enum integer_property {
  33. utf8_property ///< Non zero value if uses UTF-8 encoding
  34. };
  35. /// Standard facet's constructor
  36. info(size_t refs = 0) : std::locale::facet(refs) {}
  37. /// Get language name
  38. std::string language() const { return get_string_property(language_property); }
  39. /// Get country name
  40. std::string country() const { return get_string_property(country_property); }
  41. /// Get locale variant
  42. std::string variant() const { return get_string_property(variant_property); }
  43. /// Get encoding
  44. std::string encoding() const { return get_string_property(encoding_property); }
  45. /// Get the name of the locale, like en_US.UTF-8
  46. std::string name() const { return get_string_property(name_property); }
  47. /// True if the underlying encoding is UTF-8 (for char streams and strings)
  48. bool utf8() const { return get_integer_property(utf8_property) != 0; }
  49. protected:
  50. /// Get string property by its id \a v
  51. virtual std::string get_string_property(string_propery v) const = 0;
  52. /// Get integer property by its id \a v
  53. virtual int get_integer_property(integer_property v) const = 0;
  54. };
  55. }} // namespace boost::locale
  56. #ifdef BOOST_MSVC
  57. # pragma warning(pop)
  58. #endif
  59. #endif