]>
Commit | Line | Data |
---|---|---|
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 | |
1e59de90 | 14 | #include <cwchar> // for mbstate_t |
7c673cae FG |
15 | |
16 | #ifdef BOOST_WINDOWS_API | |
17 | ||
18 | #include "windows_file_codecvt.hpp" | |
19 | ||
7c673cae FG |
20 | #include <windows.h> |
21 | ||
1e59de90 TL |
22 | namespace boost { |
23 | namespace filesystem { | |
24 | namespace detail { | |
25 | ||
20effc67 | 26 | std::codecvt_base::result windows_file_codecvt::do_in( |
1e59de90 TL |
27 | std::mbstate_t&, |
28 | const char* from, const char* from_end, const char*& from_next, | |
29 | wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const | |
20effc67 | 30 | { |
1e59de90 TL |
31 | UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; |
32 | ||
33 | int count; | |
34 | if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to))) == 0) | |
35 | { | |
36 | return error; // conversion failed | |
37 | } | |
38 | ||
39 | from_next = from_end; | |
40 | to_next = to + count; | |
41 | *to_next = L'\0'; | |
42 | return ok; | |
20effc67 TL |
43 | } |
44 | ||
45 | std::codecvt_base::result windows_file_codecvt::do_out( | |
1e59de90 TL |
46 | std::mbstate_t&, |
47 | const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, | |
48 | char* to, char* to_end, char*& to_next) const | |
20effc67 | 49 | { |
1e59de90 TL |
50 | UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; |
51 | ||
52 | int count; | |
53 | if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to), 0, 0)) == 0) | |
54 | { | |
55 | return error; // conversion failed | |
56 | } | |
57 | ||
58 | from_next = from_end; | |
59 | to_next = to + count; | |
60 | *to_next = '\0'; | |
61 | return ok; | |
20effc67 | 62 | } |
7c673cae | 63 | |
1e59de90 TL |
64 | } // namespace detail |
65 | } // namespace filesystem | |
66 | } // namespace boost | |
67 | ||
68 | #endif // BOOST_WINDOWS_API |