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
8#ifndef BOOST_LOCALE_INFO_HPP_INCLUDED
9#define BOOST_LOCALE_INFO_HPP_INCLUDED
10
11#include <boost/locale/config.hpp>
12#include <boost/locale/detail/facet_id.hpp>
13#include <locale>
14#include <string>
15
16#ifdef BOOST_MSVC
17# pragma warning(push)
18# pragma warning(disable : 4275 4251 4231 4660)
19#endif
20
21namespace boost { namespace locale {
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 class BOOST_SYMBOL_VISIBLE info : public std::locale::facet, public detail::facet_id<info> {
27 public:
28 /// String information about the locale
29 enum string_property {
30 language_property, ///< ISO 639 language id
31 country_property, ///< ISO 3166 country id
32 variant_property, ///< Variant for locale
33 encoding_property, ///< encoding name
34 name_property ///< locale name
35 };
36
37 /// Integer information about locale
38 enum integer_property {
39 utf8_property ///< Non zero value if uses UTF-8 encoding
40 };
41
42 /// Standard facet's constructor
43 info(size_t refs = 0) : std::locale::facet(refs) {}
44 /// Get language name
45 std::string language() const { return get_string_property(v: language_property); }
46 /// Get country name
47 std::string country() const { return get_string_property(v: country_property); }
48 /// Get locale variant
49 std::string variant() const { return get_string_property(v: variant_property); }
50 /// Get encoding
51 std::string encoding() const { return get_string_property(v: encoding_property); }
52
53 /// Get the name of the locale, like en_US.UTF-8
54 std::string name() const { return get_string_property(v: name_property); }
55
56 /// True if the underlying encoding is UTF-8 (for char streams and strings)
57 bool utf8() const { return get_integer_property(v: utf8_property) != 0; }
58
59 protected:
60 /// Get string property by its id \a v
61 virtual std::string get_string_property(string_property v) const = 0;
62 /// Get integer property by its id \a v
63 virtual int get_integer_property(integer_property v) const = 0;
64 };
65
66}} // namespace boost::locale
67
68#ifdef BOOST_MSVC
69# pragma warning(pop)
70#endif
71
72#endif
73

source code of boost/libs/locale/include/boost/locale/info.hpp