File indexing completed on 2025-01-18 09:29:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_CORE_DETAIL_WIN32_UNICODE_PATH_HPP
0011 #define BOOST_BEAST_CORE_DETAIL_WIN32_UNICODE_PATH_HPP
0012
0013 #ifdef _WIN32
0014 #include <boost/config.hpp>
0015 #include <boost/beast/core/error.hpp>
0016 #include <boost/winapi/character_code_conversion.hpp>
0017 #include <boost/winapi/file_management.hpp>
0018 #include <boost/winapi/get_last_error.hpp>
0019 #include <array>
0020 #include <vector>
0021
0022 namespace boost {
0023 namespace beast {
0024 namespace detail {
0025
0026 class win32_unicode_path
0027 {
0028 using WCHAR_ = boost::winapi::WCHAR_;
0029
0030 public:
0031 win32_unicode_path(const char* utf8_path, error_code& ec) {
0032 int ret = mb2wide(utf8_path, static_buf_.data(),
0033 static_buf_.size());
0034 if (ret == 0)
0035 {
0036 int sz = mb2wide(utf8_path, nullptr, 0);
0037 if (sz == 0)
0038 {
0039 ec.assign(boost::winapi::GetLastError(),
0040 system_category());
0041 return;
0042 }
0043 dynamic_buf_.resize(sz);
0044 int ret2 = mb2wide(utf8_path,
0045 dynamic_buf_.data(),
0046 dynamic_buf_.size());
0047 if (ret2 == 0)
0048 {
0049 ec.assign(boost::winapi::GetLastError(),
0050 system_category());
0051 return;
0052 }
0053 }
0054 }
0055
0056 WCHAR_ const* c_str() const noexcept
0057 {
0058 return dynamic_buf_.empty()
0059 ? static_buf_.data()
0060 : dynamic_buf_.data();
0061 }
0062
0063 private:
0064 int mb2wide(const char* utf8_path, WCHAR_* buf, size_t sz)
0065 {
0066 return boost::winapi::MultiByteToWideChar(
0067 boost::winapi::CP_UTF8_,
0068 boost::winapi::MB_ERR_INVALID_CHARS_,
0069 utf8_path, -1,
0070 buf, static_cast<int>(sz));
0071 }
0072
0073 std::array<WCHAR_, boost::winapi::MAX_PATH_> static_buf_;
0074 std::vector<WCHAR_> dynamic_buf_;
0075 };
0076
0077 }
0078 }
0079 }
0080 #endif
0081
0082 #endif