Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 08:38:34

0001 //
0002 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
0003 // Copyright (c) 2023-2024 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 script_;
0025         std::string country_;
0026         std::string encoding_;
0027         std::string variant_;
0028         bool utf8_;
0029 
0030     public:
0031         /// Default to C locale with US-ASCII encoding
0032         locale_data();
0033         /// Construct from the parsed locale \see \ref parse
0034         ///
0035         /// \throws std::invalid_argument: parsing failed
0036         explicit locale_data(const std::string& locale_name);
0037 
0038         /// Return language (usually 2 lowercase letters, i.e. ISO-639 or 'C')
0039         const std::string& language() const { return language_; }
0040         /// Return the ISO-15924 abbreviation script code if present
0041         const std::string& script() const { return script_; }
0042         /// Return country (usually 2 uppercase letters, i.e. ISO-3166)
0043         const std::string& country() const { return country_; }
0044         /// Return encoding/codeset, e.g. ISO8859-1 or UTF-8
0045         const std::string& encoding() const { return encoding_; }
0046         /// Set encoding, will be made uppercase by default as-if it was parsed
0047         /// Returns \c *this for chaining
0048         locale_data& encoding(std::string new_encoding, bool uppercase = true);
0049         /// Return variant/modifier, e.g. euro or stroke
0050         const std::string& variant() const { return variant_; }
0051         /// Return iff the encoding is UTF-8
0052         bool is_utf8() const { return utf8_; }
0053 
0054         /// Parse a locale identifier of the form `[language[_script][_territory][.codeset][@modifier]]`
0055         ///
0056         /// Allows a dash as the delimiter: `[language-territory]`
0057         /// Return true if the identifier is valid:
0058         ///   - `language` is given and consists of ASCII letters
0059         ///   - `script` is only considered if it consists of exactly 4 ASCII letters
0060         ///   - `territory`, if given, consists of ASCII letters (usually ISO-3166)
0061         ///   - Any field started by a delimiter (`_`, `-`, `.`, `@`) is not empty
0062         /// Otherwise parsing is aborted. Valid values already parsed stay set, other are defaulted.
0063         bool parse(const std::string& locale_name);
0064 
0065         /// Get a representation in the form `[language[_territory][.codeset][@modifier]]`
0066         /// codeset is omitted if it is US-ASCII
0067         std::string to_string() const;
0068 
0069     private:
0070         void reset();
0071         bool parse_from_lang(const std::string& input);
0072         bool parse_from_script(const std::string& input);
0073         bool parse_from_country(const std::string& input);
0074         bool parse_from_encoding(const std::string& input);
0075         bool parse_from_variant(const std::string& input);
0076     };
0077 
0078 }}} // namespace boost::locale::util
0079 
0080 #ifdef BOOST_MSVC
0081 #    pragma warning(pop)
0082 #endif
0083 #endif