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