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