]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/filesystem/src/windows_file_codecvt.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / filesystem / src / windows_file_codecvt.cpp
CommitLineData
7c673cae
FG
1// filesystem windows_file_codecvt.cpp -----------------------------------------//
2
3// Copyright Beman Dawes 2009
4
5// Distributed under the Boost Software License, Version 1.0.
6// See http://www.boost.org/LICENSE_1_0.txt
7
8// Library home page: http://www.boost.org/libs/filesystem
9
92f5a8d4 10//--------------------------------------------------------------------------------------//
7c673cae 11
20effc67 12#include "platform_config.hpp"
7c673cae 13
7c673cae
FG
14#include <cwchar> // for mbstate_t
15
16#ifdef BOOST_WINDOWS_API
17
18#include "windows_file_codecvt.hpp"
19
7c673cae
FG
20#include <windows.h>
21
20effc67
TL
22std::codecvt_base::result windows_file_codecvt::do_in(
23 std::mbstate_t &,
24 const char* from, const char* from_end, const char*& from_next,
25 wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
26{
27 UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
28
29 int count;
30 if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from,
31 static_cast<int>(from_end - from), to, static_cast<int>(to_end - to))) == 0)
7c673cae 32 {
20effc67
TL
33 return error; // conversion failed
34 }
35
36 from_next = from_end;
37 to_next = to + count;
38 *to_next = L'\0';
39 return ok;
40}
41
42std::codecvt_base::result windows_file_codecvt::do_out(
43 std::mbstate_t &,
44 const wchar_t* from, const wchar_t* from_end, const wchar_t* & from_next,
45 char* to, char* to_end, char* & to_next) const
46{
47 UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
48
49 int count;
50 if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from,
51 static_cast<int>(from_end - from), to, static_cast<int>(to_end - to), 0, 0)) == 0)
7c673cae 52 {
20effc67 53 return error; // conversion failed
7c673cae
FG
54 }
55
20effc67
TL
56 from_next = from_end;
57 to_next = to + count;
58 *to_next = '\0';
59 return ok;
60}
7c673cae 61
20effc67 62#endif // BOOST_WINDOWS_API