Skip to content

Commit

Permalink
pdal: apply PDAL #3764 to 2.3 (fixes #759, fixes qgis/QGIS#49507, refs
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Aug 3, 2022
1 parent 0932322 commit 8f79e2f
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/pdal/osgeo4w/patch
@@ -1,4 +1,3 @@
Only in ../pdal-2.3/pdal: gitsha.cpp
diff -ur PDAL-2.3-maintenance/pdal/StageExtensions.hpp ../pdal-2.3/pdal/StageExtensions.hpp
--- PDAL-2.3-maintenance/pdal/StageExtensions.hpp 2021-05-28 02:51:09.000000000 +0200
+++ ../pdal-2.3/pdal/StageExtensions.hpp 2022-07-02 19:56:50.279316800 +0200
Expand All @@ -11,3 +10,54 @@ diff -ur PDAL-2.3-maintenance/pdal/StageExtensions.hpp ../pdal-2.3/pdal/StageExt
std::string defaultWriter(const std::string& filename);
PDAL_DLL StringList extensions(const std::string& stage);
private:
diff -ur PDAL-2.3-maintenance/pdal/util/FileUtils.cpp ../pdal-2.3/pdal/util/FileUtils.cpp
--- PDAL-2.3-maintenance/pdal/util/FileUtils.cpp 2021-05-28 02:51:09.000000000 +0200
+++ ../pdal-2.3/pdal/util/FileUtils.cpp 2022-08-03 14:33:46.326750400 +0200
@@ -78,18 +78,38 @@
#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());
+ if (in.empty())
+ return std::string();
+
+ // The first call determines the length of the conversion. The second does the
+ // actual conversion.
+ int len = WideCharToMultiByte(CP_UTF8, 0, in.data(), in.length(), nullptr, 0, nullptr, nullptr);
+ std::string out(len, 0);
+ if (WideCharToMultiByte(CP_UTF8, 0, in.data(), in.length(), const_cast<char*>( out.data() ), len, nullptr, nullptr) == 0)
+ {
+ int err = GetLastError();
+ char buf[200] {};
+ len = FormatMessageA(0, 0, GetLastError(), 0, buf, 199, 0);
+ throw pdal_error("Can't convert UTF16 to UTF8: " + std::string(buf, len));
+ }
+ return out;
}
inline 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());
+ if (in.empty())
+ return std::wstring();
+
+ // The first call determines the length of the conversion. The second does the
+ // actual conversion.
+ int len = MultiByteToWideChar(CP_UTF8, 0, in.data(), in.length(), nullptr, 0);
+ std::wstring out(len, 0);
+ if (MultiByteToWideChar(CP_UTF8, 0, in.data(), in.length(), const_cast<wchar_t*>( out.data() ), len) == 0)
+ {
+ char buf[200] {};
+ len = FormatMessageA(0, 0, GetLastError(), 0, buf, 199, 0);
+ throw pdal_error("Can't convert UTF8 to UTF16: " + std::string(buf, len));
+ }
+ return out;
}
#else
// inline std::string const& fromNative(std::string const& in) { return in; }

0 comments on commit 8f79e2f

Please sign in to comment.