| 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 | #include <boost/locale/generator.hpp> |
| 9 | #include <boost/locale/info.hpp> |
| 10 | #include <boost/locale/util.hpp> |
| 11 | #include <boost/locale/util/locale_data.hpp> |
| 12 | #include <cstdlib> |
| 13 | #include <ios> |
| 14 | #include <locale> |
| 15 | #include <sstream> |
| 16 | #include <string> |
| 17 | |
| 18 | namespace boost { namespace locale { namespace util { |
| 19 | |
| 20 | class simple_info : public info { |
| 21 | public: |
| 22 | simple_info(const std::string& name, size_t refs = 0) : info(refs), name_(name) { d.parse(locale_name: name); } |
| 23 | std::string get_string_property(string_property v) const override |
| 24 | { |
| 25 | switch(v) { |
| 26 | case language_property: return d.language(); |
| 27 | case country_property: return d.country(); |
| 28 | case variant_property: return d.variant(); |
| 29 | case encoding_property: return d.encoding(); |
| 30 | case name_property: return name_; |
| 31 | } |
| 32 | return ""; // LCOV_EXCL_LINE |
| 33 | } |
| 34 | |
| 35 | int get_integer_property(integer_property v) const override |
| 36 | { |
| 37 | switch(v) { |
| 38 | case utf8_property: return d.is_utf8(); |
| 39 | } |
| 40 | return 0; // LCOV_EXCL_LINE |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | locale_data d; |
| 45 | std::string name_; |
| 46 | }; |
| 47 | |
| 48 | std::locale create_info(const std::locale& in, const std::string& name) |
| 49 | { |
| 50 | return std::locale(in, new simple_info(name)); |
| 51 | } |
| 52 | |
| 53 | }}} // namespace boost::locale::util |
| 54 |
