I want to refactor this code in C++17. Can I use std::filesystem in this case?
#if defined(BOOSTER_WIN_NATIVE)
bool open(std::string const &file_name,std::string const &encoding)
{
close();
//
// Under Windows, we have to use "_wfopen" to get
// access to paths with Unicode in them.
//
// As not all standard C++ libraries support nonstandard std::istream::open(wchar_t const *)
// we would use good old stdio and _wfopen CRTL functions.
//
std::wstring wfile_name = conv::to_utf<wchar_t>(file_name,encoding);
file = _wfopen(wfile_name.c_str(),L"rb");
return file!=0;
}
#else // POSIX systems do not have all this Wide API crap, as native codepages are UTF-8
// We do not use encoding as we use native file name encoding
bool open(std::string const &file_name,std::string const &/* encoding */)
{
close();
file = fopen(file_name.c_str(),"rb");
return file!=0;
}
#endif
I've already changed utf8 utf16 converting, but it seems there is no value in this anymore.
std::wstring wfile_name;
typedef std::codecvt_utf8_utf16<wchar_t> codec;
std::wstring_convert<codec> converter;
wfile_name = converter.from_bytes(file_name);
file = _wfopen(wfile_name.c_str(), L"rb");
return file != 0;