| 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/encoding_errors.hpp> |
| 9 | #include "boost/locale/posix/all_generator.hpp" |
| 10 | #include "boost/locale/shared/iconv_codecvt.hpp" |
| 11 | #include "boost/locale/util/encoding.hpp" |
| 12 | #include <stdexcept> |
| 13 | |
| 14 | namespace boost { namespace locale { namespace impl_posix { |
| 15 | |
| 16 | std::locale create_codecvt(const std::locale& in, const std::string& encoding, char_facet_t type) |
| 17 | { |
| 18 | if(util::normalize_encoding(encoding) == "utf8") |
| 19 | return util::create_utf8_codecvt(in, type); |
| 20 | |
| 21 | try { |
| 22 | return util::create_simple_codecvt(in, encoding, type); |
| 23 | } catch(const conv::invalid_charset_error&) { |
| 24 | return util::create_codecvt(in, cvt: create_iconv_converter(encoding), type); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | }}} // namespace boost::locale::impl_posix |
| 29 |
