Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-13 10:03:38

0001 // Copyright (c) 2016 Klemens D. Morgenstern
0002 // Copyright (c) 2008 Beman Dawes
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_PROCESS_DETAIL_WINDOWS_LOCALE_HPP_
0008 #define BOOST_PROCESS_DETAIL_WINDOWS_LOCALE_HPP_
0009 
0010 #include <boost/process/v1/detail/config.hpp>
0011 #include <locale>
0012 #include <boost/core/ignore_unused.hpp>
0013 #include <boost/winapi/file_management.hpp>
0014 #include <boost/winapi/character_code_conversion.hpp>
0015 
0016 namespace boost
0017 {
0018 namespace process
0019 {
0020 BOOST_PROCESS_V1_INLINE namespace v1
0021 {
0022 namespace detail
0023 {
0024 namespace windows
0025 {
0026 
0027 //copied from boost.filesystem
0028 class windows_file_codecvt
0029    : public std::codecvt< wchar_t, char, std::mbstate_t >
0030  {
0031  public:
0032    explicit windows_file_codecvt(std::size_t refs = 0)
0033        : std::codecvt<wchar_t, char, std::mbstate_t>(refs) {}
0034  protected:
0035 
0036    bool do_always_noconv() const noexcept override { return false; }
0037 
0038    //  seems safest to assume variable number of characters since we don't
0039    //  actually know what codepage is active
0040    int do_encoding() const noexcept override { return 0; }
0041 
0042    std::codecvt_base::result do_in(std::mbstate_t& state,
0043      const char* from, const char* from_end, const char*& from_next,
0044      wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const override
0045    {
0046      boost::ignore_unused(state);
0047 
0048        auto codepage =
0049 #if !defined(BOOST_NO_ANSI_APIS)
0050                ::boost::winapi::AreFileApisANSI() ?
0051                ::boost::winapi::CP_ACP_ :
0052 #endif
0053                ::boost::winapi::CP_OEMCP_;
0054 
0055      int count = 0;
0056      if ((count = ::boost::winapi::MultiByteToWideChar(codepage,
0057              ::boost::winapi::MB_PRECOMPOSED_, from,
0058        static_cast<int>(from_end - from), to, static_cast<int>(to_end - to))) == 0)
0059      {
0060        return error;  // conversion failed
0061      }
0062 
0063      from_next = from_end;
0064      to_next = to + count;
0065      *to_next = L'\0';
0066      return ok;
0067   }
0068 
0069    std::codecvt_base::result do_out(std::mbstate_t & state,
0070      const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
0071      char* to, char* to_end, char*& to_next) const override
0072    {
0073      boost::ignore_unused(state);
0074      auto codepage =
0075 #if !defined(BOOST_NO_ANSI_APIS)
0076                    ::boost::winapi::AreFileApisANSI() ?
0077                        ::boost::winapi::CP_ACP_ :
0078 #endif
0079                      ::boost::winapi::CP_OEMCP_;
0080      int count = 0;
0081 
0082 
0083      if ((count = ::boost::winapi::WideCharToMultiByte(codepage,
0084                    ::boost::winapi::WC_NO_BEST_FIT_CHARS_, from,
0085                   static_cast<int>(from_end - from), to, static_cast<int>(to_end - to), 0, 0)) == 0)
0086      {
0087        return error;  // conversion failed
0088      }
0089 
0090      from_next = from_end;
0091      to_next = to + count;
0092      *to_next = '\0';
0093      return ok;
0094    }
0095 
0096    std::codecvt_base::result do_unshift(std::mbstate_t&,
0097        char* /*from*/, char* /*to*/, char* & /*next*/) const override { return ok; }
0098 
0099    int do_length(std::mbstate_t&,
0100      const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const override { return 0; }
0101 
0102    int do_max_length() const noexcept override { return 0; }
0103  };
0104 
0105 
0106 
0107 }
0108 }
0109 }
0110 }
0111 }
0112 
0113 
0114 #endif /* BOOST_PROCESS_LOCALE_HPP_ */