office-gobmx/external/liborcus/win_path_utf16.patch
Mike Kaganski c2e86396b7 tdf#150247: patch orcus to use UTF-16 paths on Windows
This adds UTF8->UTF16 conversion of the paths passed to ctor of
file_content on Windows, since both boost::filesystem::file_size
and boost::interprocess::file_mapping take UTF-16 strings on this
platform. So the assumption is that 8-bit path strings passed to
orcus are UTF-8-encoded.

This partially reverts commit 75252e58d9
(it keeps use of osl_getThreadTextEncoding for platforms other than
Windows).

Change-Id: Ie467f71a65945f4f07ff432136ea06b811c3f794
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137759
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-08-04 06:31:36 +02:00

33 lines
1.1 KiB
Diff

diff --git a/src/parser/stream.cpp b/src/parser/stream.cpp
index 00395f59ff25..8f385fb8965a 100644
--- a/src/parser/stream.cpp
+++ b/src/parser/stream.cpp
@@ -147,6 +147,14 @@ std::tuple<std::string_view, size_t, size_t> find_line_with_offset(std::string_v
return std::make_tuple(line, line_num, offset_on_line);
}
+#ifdef _WIN32
+std::wstring to_wstring(std::string_view s)
+{
+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> conversion;
+ return conversion.from_bytes(s.data(), s.data() + s.size());
+}
+#endif
+
} // anonymous namespace
struct file_content::impl
@@ -162,8 +170,13 @@ struct file_content::impl
impl() : content_size(0), content(nullptr) {}
impl(std::string_view filepath) :
+#ifdef _WIN32
+ content_size(fs::file_size(to_wstring(filepath))),
+ mapped_file(to_wstring(filepath).c_str(), bip::read_only),
+#else
content_size(fs::file_size(std::string{filepath}.c_str())),
mapped_file(std::string{filepath}.c_str(), bip::read_only),
+#endif
mapped_region(mapped_file, bip::read_only, 0, content_size),
content(nullptr)
{