#include "platform_config.hpp"
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/detail/path_traits.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/system/system_error.hpp>
#include <boost/assert.hpp>
#include <memory>
#include <string>
#include <locale>
#include <cwchar>
#include <cstddef>
#include <boost/filesystem/detail/header.hpp>
namespace pt = boost::filesystem::detail::path_traits;
namespace fs = boost::filesystem;
namespace bs = boost::system;
#ifndef BOOST_FILESYSTEM_CODECVT_BUF_SIZE
#define BOOST_FILESYSTEM_CODECVT_BUF_SIZE 256
#endif
namespace {
BOOST_CONSTEXPR_OR_CONST std::size_t default_codecvt_buf_size = BOOST_FILESYSTEM_CODECVT_BUF_SIZE;
void convert_aux(const char* from, const char* from_end, wchar_t* to, wchar_t* to_end, std::wstring& target, pt::codecvt_type const& cvt)
{
std::mbstate_t state = std::mbstate_t(); const char* from_next;
wchar_t* to_next;
std::codecvt_base::result res;
if ((res = cvt.in(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
{
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to wstring"));
}
target.append(to, to_next);
}
void convert_aux(const wchar_t* from, const wchar_t* from_end, char* to, char* to_end, std::string& target, pt::codecvt_type const& cvt)
{
std::mbstate_t state = std::mbstate_t(); const wchar_t* from_next;
char* to_next;
std::codecvt_base::result res;
if ((res = cvt.out(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
{
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to string"));
}
target.append(to, to_next);
}
}
namespace boost {
namespace filesystem {
namespace detail {
namespace path_traits {
BOOST_FILESYSTEM_DECL
void convert(const char* from, const char* from_end, std::wstring& to, const codecvt_type* cvt)
{
if (from == from_end)
return;
BOOST_ASSERT(from != nullptr);
BOOST_ASSERT(from_end != nullptr);
if (!cvt)
cvt = &fs::path::codecvt();
std::size_t buf_size = (from_end - from) * 3;
if (buf_size > default_codecvt_buf_size)
{
std::unique_ptr< wchar_t[] > buf(new wchar_t[buf_size]);
convert_aux(from, from_end, buf.get(), buf.get() + buf_size, to, *cvt);
}
else
{
wchar_t buf[default_codecvt_buf_size];
convert_aux(from, from_end, buf, buf + default_codecvt_buf_size, to, *cvt);
}
}
BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from, const wchar_t* from_end, std::string& to, const codecvt_type* cvt)
{
if (from == from_end)
return;
BOOST_ASSERT(from != nullptr);
BOOST_ASSERT(from_end != nullptr);
if (!cvt)
cvt = &fs::path::codecvt();
std::size_t buf_size = (from_end - from) * 4; buf_size += 4;
if (buf_size > default_codecvt_buf_size)
{
std::unique_ptr< char[] > buf(new char[buf_size]);
convert_aux(from, from_end, buf.get(), buf.get() + buf_size, to, *cvt);
}
else
{
char buf[default_codecvt_buf_size];
convert_aux(from, from_end, buf, buf + default_codecvt_buf_size, to, *cvt);
}
}
} } } }
#include <boost/filesystem/detail/footer.hpp>