Boost.Locale
locale_data.hpp
1 //
2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 // Copyright (c) 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_UTIL_LOCALE_DATA_HPP
9 #define BOOST_LOCALE_UTIL_LOCALE_DATA_HPP
10 
11 #include <boost/locale/config.hpp>
12 #include <string>
13 
14 #ifdef BOOST_MSVC
15 # pragma warning(push)
16 # pragma warning(disable : 4251)
17 #endif
18 
19 namespace boost { namespace locale { namespace util {
20 
22  class BOOST_LOCALE_DECL locale_data {
23  std::string language_;
24  std::string country_;
25  std::string encoding_;
26  std::string variant_;
27  bool utf8_;
28 
29  public:
30  // Default to C locale with US-ASCII encoding
31  locale_data();
32  // Construct from the parsed locale \see \ref parse
33  // Throws `std::invalid_argument` if parsing fails
34  explicit locale_data(const std::string& locale_name);
35 
37  const std::string& language() const { return language_; }
39  const std::string& country() const { return country_; }
41  const std::string& encoding() const { return encoding_; }
43  const std::string& variant() const { return variant_; }
45  bool is_utf8() const { return utf8_; }
46 
57  bool parse(const std::string& locale_name);
58 
61  std::string to_string() const;
62 
63  private:
64  void reset();
65  bool parse_from_lang(const std::string& input);
66  bool parse_from_country(const std::string& input);
67  bool parse_from_encoding(const std::string& input);
68  bool parse_from_variant(const std::string& input);
69  };
70 
71 }}} // namespace boost::locale::util
72 
73 #ifdef BOOST_MSVC
74 # pragma warning(pop)
75 #endif
76 #endif
const std::string & country() const
Return country (usually 2 uppercase letters, i.e. ISO-3166)
Definition: locale_data.hpp:39
const std::string & encoding() const
Return encoding/codeset, e.g. ISO8859-1 or UTF-8.
Definition: locale_data.hpp:41
Holder and parser for locale names/identifiers.
Definition: locale_data.hpp:22
bool is_utf8() const
Return iff the encoding is UTF-8.
Definition: locale_data.hpp:45
const std::string & language() const
Return language (usually 2 lowercase letters, i.e. ISO-639 or 'C')
Definition: locale_data.hpp:37
const std::string & variant() const
Return variant/modifier, e.g. euro or stroke.
Definition: locale_data.hpp:43