info.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  3. // Copyright (c) 2022-2023 Alexander Grund
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // https://www.boost.org/LICENSE_1_0.txt
  7. #ifndef BOOST_LOCALE_INFO_HPP_INCLUDED
  8. #define BOOST_LOCALE_INFO_HPP_INCLUDED
  9. #include <boost/locale/config.hpp>
  10. #include <boost/locale/detail/facet_id.hpp>
  11. #include <locale>
  12. #include <string>
  13. #ifdef BOOST_MSVC
  14. # pragma warning(push)
  15. # pragma warning(disable : 4275 4251 4231 4660)
  16. #endif
  17. namespace boost { namespace locale {
  18. /// \brief a facet that holds general information about locale
  19. ///
  20. /// This facet should be always created in order to make all Boost.Locale functions work
  21. class BOOST_SYMBOL_VISIBLE info : public std::locale::facet, public detail::facet_id<info> {
  22. public:
  23. /// String information about the locale
  24. enum string_property {
  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_property 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