1 // filesystem windows_file_codecvt.cpp -----------------------------------------//
3 // Copyright Beman Dawes 2009
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 // Library home page: http://www.boost.org/libs/filesystem
10 //--------------------------------------------------------------------------------------//
12 // Include Boost.Predef first so that windows.h is guaranteed to be not included
13 #include <boost/predef/os/windows.h>
15 #include <boost/winapi/config.hpp>
18 #ifndef BOOST_SYSTEM_NO_DEPRECATED
19 # define BOOST_SYSTEM_NO_DEPRECATED
22 #include <boost/filesystem/config.hpp>
23 #include <cwchar> // for mbstate_t
25 #ifdef BOOST_WINDOWS_API
27 #include "windows_file_codecvt.hpp"
29 // Versions of MinGW prior to GCC 4.6 requires this
31 # define WINVER 0x0500
36 std::codecvt_base::result windows_file_codecvt::do_in(
38 const char* from, const char* from_end, const char*& from_next,
39 wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
41 UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
44 if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from,
45 static_cast<int>(from_end - from), to, static_cast<int>(to_end - to))) == 0)
47 return error; // conversion failed
56 std::codecvt_base::result windows_file_codecvt::do_out(
58 const wchar_t* from, const wchar_t* from_end, const wchar_t* & from_next,
59 char* to, char* to_end, char* & to_next) const
61 UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
64 if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from,
65 static_cast<int>(from_end - from), to, static_cast<int>(to_end - to), 0, 0)) == 0)
67 return error; // conversion failed
76 # endif // BOOST_WINDOWS_API