File indexing completed on 2025-01-18 09:50:08
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_PROCESS_DETAIL_WINDOWS_LOCALE_HPP_
0008 #define BOOST_PROCESS_DETAIL_WINDOWS_LOCALE_HPP_
0009
0010 #include <locale>
0011 #include <boost/core/ignore_unused.hpp>
0012 #include <boost/winapi/file_management.hpp>
0013 #include <boost/winapi/character_code_conversion.hpp>
0014
0015 namespace boost
0016 {
0017 namespace process
0018 {
0019 namespace detail
0020 {
0021 namespace windows
0022 {
0023
0024
0025 class windows_file_codecvt
0026 : public std::codecvt< wchar_t, char, std::mbstate_t >
0027 {
0028 public:
0029 explicit windows_file_codecvt(std::size_t refs = 0)
0030 : std::codecvt<wchar_t, char, std::mbstate_t>(refs) {}
0031 protected:
0032
0033 bool do_always_noconv() const noexcept override { return false; }
0034
0035
0036
0037 int do_encoding() const noexcept override { return 0; }
0038
0039 std::codecvt_base::result do_in(std::mbstate_t& state,
0040 const char* from, const char* from_end, const char*& from_next,
0041 wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const override
0042 {
0043 boost::ignore_unused(state);
0044
0045 auto codepage =
0046 #if !defined(BOOST_NO_ANSI_APIS)
0047 ::boost::winapi::AreFileApisANSI() ?
0048 ::boost::winapi::CP_ACP_ :
0049 #endif
0050 ::boost::winapi::CP_OEMCP_;
0051
0052 int count = 0;
0053 if ((count = ::boost::winapi::MultiByteToWideChar(codepage,
0054 ::boost::winapi::MB_PRECOMPOSED_, from,
0055 static_cast<int>(from_end - from), to, static_cast<int>(to_end - to))) == 0)
0056 {
0057 return error;
0058 }
0059
0060 from_next = from_end;
0061 to_next = to + count;
0062 *to_next = L'\0';
0063 return ok;
0064 }
0065
0066 std::codecvt_base::result do_out(std::mbstate_t & state,
0067 const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
0068 char* to, char* to_end, char*& to_next) const override
0069 {
0070 boost::ignore_unused(state);
0071 auto codepage =
0072 #if !defined(BOOST_NO_ANSI_APIS)
0073 ::boost::winapi::AreFileApisANSI() ?
0074 ::boost::winapi::CP_ACP_ :
0075 #endif
0076 ::boost::winapi::CP_OEMCP_;
0077 int count = 0;
0078
0079
0080 if ((count = ::boost::winapi::WideCharToMultiByte(codepage,
0081 ::boost::winapi::WC_NO_BEST_FIT_CHARS_, from,
0082 static_cast<int>(from_end - from), to, static_cast<int>(to_end - to), 0, 0)) == 0)
0083 {
0084 return error;
0085 }
0086
0087 from_next = from_end;
0088 to_next = to + count;
0089 *to_next = '\0';
0090 return ok;
0091 }
0092
0093 std::codecvt_base::result do_unshift(std::mbstate_t&,
0094 char* , char* , char* & ) const override { return ok; }
0095
0096 int do_length(std::mbstate_t&,
0097 const char* , const char* , std::size_t ) const override { return 0; }
0098
0099 int do_max_length() const noexcept override { return 0; }
0100 };
0101
0102
0103
0104 }
0105 }
0106 }
0107 }
0108
0109
0110
0111 #endif