Chris@16: // Chris@16: // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: #ifndef BOOST_LOCALE_INFO_HPP_INCLUDED Chris@16: #define BOOST_LOCALE_INFO_HPP_INCLUDED Chris@16: #include Chris@16: #ifdef BOOST_MSVC Chris@16: # pragma warning(push) Chris@16: # pragma warning(disable : 4275 4251 4231 4660) Chris@16: #endif Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: namespace boost { Chris@16: namespace locale { Chris@16: Chris@16: /// Chris@16: /// \brief a facet that holds general information about locale Chris@16: /// Chris@16: /// This facet should be always created in order to make all Boost.Locale functions work Chris@16: /// Chris@16: class BOOST_LOCALE_DECL info : public std::locale::facet Chris@16: { Chris@16: public: Chris@16: static std::locale::id id; ///< This member uniquely defines this facet, required by STL Chris@16: Chris@16: /// Chris@16: /// String information about the locale Chris@16: /// Chris@16: enum string_propery { Chris@16: language_property, ///< ISO 639 language id Chris@16: country_property, ///< ISO 3166 country id Chris@16: variant_property, ///< Variant for locale Chris@16: encoding_property, ///< encoding name Chris@16: name_property ///< locale name Chris@16: }; Chris@16: Chris@16: /// Chris@16: /// Integer information about locale Chris@16: /// Chris@16: enum integer_property { Chris@16: utf8_property ///< Non zero value if uses UTF-8 encoding Chris@16: }; Chris@16: Chris@16: Chris@16: /// Chris@16: /// Standard facet's constructor Chris@16: /// Chris@16: info(size_t refs = 0) : std::locale::facet(refs) Chris@16: { Chris@16: } Chris@16: /// Chris@16: /// Get language name Chris@16: /// Chris@16: std::string language() const Chris@16: { Chris@16: return get_string_property(language_property); Chris@16: } Chris@16: /// Chris@16: /// Get country name Chris@16: /// Chris@16: std::string country() const Chris@16: { Chris@16: return get_string_property(country_property); Chris@16: } Chris@16: /// Chris@16: /// Get locale variant Chris@16: /// Chris@16: std::string variant() const Chris@16: { Chris@16: return get_string_property(variant_property); Chris@16: } Chris@16: /// Chris@16: /// Get encoding Chris@16: /// Chris@16: std::string encoding() const Chris@16: { Chris@16: return get_string_property(encoding_property); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Get the name of the locale, like en_US.UTF-8 Chris@16: /// Chris@16: std::string name() const Chris@16: { Chris@16: return get_string_property(name_property); Chris@16: } Chris@16: Chris@16: /// Chris@16: /// True if the underlying encoding is UTF-8 (for char streams and strings) Chris@16: /// Chris@16: bool utf8() const Chris@16: { Chris@16: return get_integer_property(utf8_property) != 0; Chris@16: } Chris@16: Chris@16: #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) Chris@16: std::locale::id& __get_id (void) const { return id; } Chris@16: #endif Chris@16: protected: Chris@16: /// Chris@16: /// Get string property by its id \a v Chris@16: /// Chris@16: virtual std::string get_string_property(string_propery v) const = 0; Chris@16: /// Chris@16: /// Get integer property by its id \a v Chris@16: /// Chris@16: virtual int get_integer_property(integer_property v) const = 0; Chris@16: }; Chris@16: Chris@16: } Chris@16: } Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #endif Chris@16: Chris@16: // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4