Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:15

0001 //
0002 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
0003 // Copyright (c) 2023 Alexander Grund
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // https://www.boost.org/LICENSE_1_0.txt
0007 
0008 #ifndef BOOST_LOCALE_UTIL_LOCALE_DATA_HPP
0009 #define BOOST_LOCALE_UTIL_LOCALE_DATA_HPP
0010 
0011 #include <boost/locale/config.hpp>
0012 #include <string>
0013 
0014 #ifdef BOOST_MSVC
0015 #    pragma warning(push)
0016 #    pragma warning(disable : 4251)
0017 #endif
0018 
0019 namespace boost { namespace locale { namespace util {
0020 
0021     /// Holder and parser for locale names/identifiers
0022     class BOOST_LOCALE_DECL locale_data {
0023         std::string language_;
0024         std::string country_;
0025         std::string encoding_;
0026         std::string variant_;
0027         bool utf8_;
0028 
0029     public:
0030         /// Default to C locale with US-ASCII encoding
0031         locale_data();
0032         /// Construct from the parsed locale \see \ref parse
0033         ///
0034         /// \throws std::invalid_argument: parsing failed
0035         explicit locale_data(const std::string& locale_name);
0036 
0037         /// Return language (usually 2 lowercase letters, i.e. ISO-639 or 'C')
0038         const std::string& language() const { return language_; }
0039         /// Return country (usually 2 uppercase letters, i.e. ISO-3166)
0040         const std::string& country() const { return country_; }
0041         /// Return encoding/codeset, e.g. ISO8859-1 or UTF-8
0042         const std::string& encoding() const { return encoding_; }
0043         /// Set encoding, will be made uppercase by default as-if it was parsed
0044         /// Returns \c *this for chaining
0045         locale_data& encoding(std::string new_encoding, bool uppercase = true);
0046         /// Return variant/modifier, e.g. euro or stroke
0047         const std::string& variant() const { return variant_; }
0048         /// Return iff the encoding is UTF-8
0049         bool is_utf8() const { return utf8_; }
0050 
0051         /// Parse a locale identifier of the form `[language[_territory][.codeset][@modifier]]`
0052         ///
0053         /// Allows a dash as the delimiter: `[language-territory]`
0054         /// Return true if the identifier is valid:
0055         ///   - `language` is given and consists of ASCII letters
0056         ///   - `territory`, if given, consists of ASCII letters
0057         ///   - Any field started by a delimiter (`_`, `-`, `.`, `@`) is not empty
0058         /// Otherwise parsing is aborted. Valid values already parsed stay set, other are defaulted.
0059         bool parse(const std::string& locale_name);
0060 
0061         /// Get a representation in the form `[language[_territory][.codeset][@modifier]]`
0062         /// codeset is omitted if it is US-ASCII
0063         std::string to_string() const;
0064 
0065     private:
0066         void reset();
0067         bool parse_from_lang(const std::string& input);
0068         bool parse_from_country(const std::string& input);
0069         bool parse_from_encoding(const std::string& input);
0070         bool parse_from_variant(const std::string& input);
0071     };
0072 
0073 }}} // namespace boost::locale::util
0074 
0075 #ifdef BOOST_MSVC
0076 #    pragma warning(pop)
0077 #endif
0078 #endif