]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/process/detail/windows/locale.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / process / detail / windows / locale.hpp
1 // Copyright (c) 2016 Klemens D. Morgenstern
2 // Copyright (c) 2008 Beman Dawes
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef BOOST_PROCESS_DETAIL_WINDOWS_LOCALE_HPP_
8 #define BOOST_PROCESS_DETAIL_WINDOWS_LOCALE_HPP_
9
10 #include <locale>
11 #include <boost/core/ignore_unused.hpp>
12 #include <boost/winapi/file_management.hpp>
13 #include <boost/winapi/character_code_conversion.hpp>
14
15 namespace boost
16 {
17 namespace process
18 {
19 namespace detail
20 {
21 namespace windows
22 {
23
24 //copied from boost.filesystem
25 class windows_file_codecvt
26 : public std::codecvt< wchar_t, char, std::mbstate_t >
27 {
28 public:
29 explicit windows_file_codecvt(std::size_t refs = 0)
30 : std::codecvt<wchar_t, char, std::mbstate_t>(refs) {}
31 protected:
32
33 bool do_always_noconv() const noexcept override { return false; }
34
35 // seems safest to assume variable number of characters since we don't
36 // actually know what codepage is active
37 int do_encoding() const noexcept override { return 0; }
38
39 std::codecvt_base::result do_in(std::mbstate_t& state,
40 const char* from, const char* from_end, const char*& from_next,
41 wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const override
42 {
43 boost::ignore_unused(state);
44 ::boost::winapi::UINT_ codepage = AreFileApisANSI() ?
45 ::boost::winapi::CP_ACP_ :
46 ::boost::winapi::CP_OEMCP_;
47
48 int count;
49 if ((count = ::boost::winapi::MultiByteToWideChar(codepage,
50 ::boost::winapi::MB_PRECOMPOSED_, from,
51 static_cast<int>(from_end - from), to, static_cast<int>(to_end - to))) == 0)
52 {
53 return error; // conversion failed
54 }
55
56 from_next = from_end;
57 to_next = to + count;
58 *to_next = L'\0';
59 return ok;
60 }
61
62 std::codecvt_base::result do_out(std::mbstate_t & state,
63 const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
64 char* to, char* to_end, char*& to_next) const override
65 {
66 boost::ignore_unused(state);
67 auto codepage = ::boost::winapi::AreFileApisANSI() ?
68 ::boost::winapi::CP_ACP_ :
69 ::boost::winapi::CP_OEMCP_;
70
71 int count;
72 if ((count = ::boost::winapi::WideCharToMultiByte(codepage,
73 ::boost::winapi::WC_NO_BEST_FIT_CHARS_, from,
74 static_cast<int>(from_end - from), to, static_cast<int>(to_end - to), 0, 0)) == 0)
75 {
76 return error; // conversion failed
77 }
78
79 from_next = from_end;
80 to_next = to + count;
81 *to_next = '\0';
82 return ok;
83 }
84
85 std::codecvt_base::result do_unshift(std::mbstate_t&,
86 char* /*from*/, char* /*to*/, char* & /*next*/) const override { return ok; }
87
88 int do_length(std::mbstate_t&,
89 const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const override { return 0; }
90
91 int do_max_length() const noexcept override { return 0; }
92 };
93
94
95
96 }
97 }
98 }
99 }
100
101
102
103 #endif /* BOOST_PROCESS_LOCALE_HPP_ */