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/config.hpp>
13 #if !defined( BOOST_NO_STD_WSTRING )
14 // Boost.Filesystem V3 and later requires std::wstring support.
15 // During the transition to V3, libraries are compiled with both V2 and V3 sources.
16 // On old compilers that don't support V3 anyhow, we just skip everything so the compile
17 // will succeed and the library can be built.
19 // define BOOST_FILESYSTEM_SOURCE so that <boost/system/config.hpp> knows
20 // the library is being built (possibly exporting rather than importing code)
21 #define BOOST_FILESYSTEM_SOURCE
23 #ifndef BOOST_SYSTEM_NO_DEPRECATED
24 # define BOOST_SYSTEM_NO_DEPRECATED
27 #include <boost/filesystem/v3/config.hpp>
28 #include <cwchar> // for mbstate_t
30 #ifdef BOOST_WINDOWS_API
32 #include "windows_file_codecvt.hpp"
34 // Versions of MinGW prior to GCC 4.6 requires this
36 # define WINVER 0x0500
41 std::codecvt_base::result
windows_file_codecvt::do_in(
43 const char* from
, const char* from_end
, const char*& from_next
,
44 wchar_t* to
, wchar_t* to_end
, wchar_t*& to_next
) const
46 UINT codepage
= AreFileApisANSI() ? CP_ACP
: CP_OEMCP
;
49 if ((count
= ::MultiByteToWideChar(codepage
, MB_PRECOMPOSED
, from
,
50 from_end
- from
, to
, to_end
- to
)) == 0)
52 return error
; // conversion failed
61 std::codecvt_base::result
windows_file_codecvt::do_out(
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
66 UINT codepage
= AreFileApisANSI() ? CP_ACP
: CP_OEMCP
;
69 if ((count
= ::WideCharToMultiByte(codepage
, WC_NO_BEST_FIT_CHARS
, from
,
70 from_end
- from
, to
, to_end
- to
, 0, 0)) == 0)
72 return error
; // conversion failed
81 # endif // BOOST_WINDOWS_API
83 #endif // no wide character support