Skip to content

Commit

Permalink
Don't use wstring for MinGW.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Sep 7, 2021
1 parent 55eca7f commit 7859720
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions pdal/util/FileUtils.cpp
Expand Up @@ -75,25 +75,20 @@ std::string addTrailingSlash(std::string path)
return path;
}

#ifdef _WIN32
inline std::string fromNative(std::wstring const& in)
{
// TODO: C++11 define convert with static thread_local
std::wstring_convert<std::codecvt_utf8_utf16<unsigned short>, unsigned short> convert;
auto p = reinterpret_cast<unsigned short const*>(in.data());
return convert.to_bytes(p, p + in.size());
}
inline std::wstring toNative(std::string const& in)
#ifdef PDAL_WIN32_STL
std::wstring toNative(std::string const& in)
{
// TODO: C++11 define convert with static thread_local
std::wstring_convert<std::codecvt_utf8_utf16<unsigned short>, unsigned short> convert;
auto s = convert.from_bytes(in);
auto p = reinterpret_cast<wchar_t const*>(s.data());
return std::wstring(p, p + s.size());
}
#else
// inline std::string const& fromNative(std::string const& in) { return in; }
inline std::string const& toNative(std::string const& in) { return in; }
#else // Unix, OSX, MinGW
std::string const& toNative(std::string const& in)
{
return in;
}
#endif

} // unnamed namespace
Expand Down Expand Up @@ -434,7 +429,14 @@ std::vector<std::string> glob(std::string path)
if (path[0] == '~')
throw pdal::pdal_error("PDAL does not support shell expansion");

#ifdef _WIN32
#ifdef PDAL_WIN32_STL
auto fromNative = [](std::wstring const& in) => std::wstring
{
std::wstring_convert<std::codecvt_utf8_utf16<unsigned short>, unsigned short> convert;
auto p = reinterpret_cast<unsigned short const*>(in.data());
return convert.to_bytes(p, p + in.size());
};

std::wstring wpath(toNative(path));
WIN32_FIND_DATAW ffd;
HANDLE handle = FindFirstFileW(wpath.c_str(), &ffd);
Expand Down

0 comments on commit 7859720

Please sign in to comment.