Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / locale / src / std / codecvt.cpp
1 //
2 //  Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 //  Distributed under the Boost Software License, Version 1.0. (See
5 //  accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #define BOOST_LOCALE_SOURCE
9 #include <locale>
10 #include <boost/cstdint.hpp>
11 #include <boost/locale/util.hpp>
12 #include "all_generator.hpp"
13 #include <vector>
14 namespace boost {
15 namespace locale {
16 namespace impl_std {
17     template<typename CharType>
18     std::locale codecvt_bychar( std::locale const &in,
19                                 std::string const &locale_name)
20     {
21         return std::locale(in,new std::codecvt_byname<CharType,char,std::mbstate_t>(locale_name.c_str()));
22     }
23     
24
25     std::locale create_codecvt( std::locale const &in,
26                                 std::string const &locale_name,
27                                 character_facet_type type,
28                                 utf8_support utf) 
29     {
30         if(utf == utf8_from_wide) {
31             return util::create_codecvt(in,util::create_utf8_converter(),type);
32         }
33         switch(type) {
34         case char_facet:
35             return codecvt_bychar<char>(in,locale_name);
36         case wchar_t_facet:
37             return codecvt_bychar<wchar_t>(in,locale_name);
38         #if defined(BOOST_HAS_CHAR16_T) && !defined(BOOST_NO_CHAR16_T_CODECVT)
39         case char16_t_facet:
40             return codecvt_bychar<char16_t>(in,locale_name);
41         #endif
42         #if defined(BOOST_HAS_CHAR32_T) && !defined(BOOST_NO_CHAR32_T_CODECVT)
43         case char32_t_facet:
44             return codecvt_bychar<char32_t>(in,locale_name);
45         #endif
46         default:
47             return in;
48         }
49     }
50
51 } // impl_std
52 } // locale 
53 } // boost
54
55 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4