Merge #13877: utils: Make fs::path::string() always return utf-8 string on Windows
2c3eade704
Make fs::path::string() always return utf-8 string (Chun Kuan Lee)
Pull request description:
Imbue `fs::path` with `std::codecvt_utf8_utf16` at `SetupEnvironment()`, so that default string encoding will be utf-8 inside `fs::path`.
Tree-SHA512: 0cb59464d777278decbf24771fc5ff0cb2caa7bc2fe8ee5cd36c97a2324873a3caad131f08f050393b488316ee7f4ab0b28b7fa4699e41839f8e51b9867d5118
This commit is contained in:
commit
cc7258bdfb
1
src/fs.h
1
src/fs.h
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
|
|
||||||
|
|
||||||
/** Filesystem operations and types */
|
/** Filesystem operations and types */
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
|
@ -60,8 +60,6 @@
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static fs::detail::utf8_codecvt_facet utf8;
|
|
||||||
|
|
||||||
namespace GUIUtil {
|
namespace GUIUtil {
|
||||||
|
|
||||||
QString dateTimeStr(const QDateTime &date)
|
QString dateTimeStr(const QDateTime &date)
|
||||||
|
@ -764,12 +762,12 @@ void setClipboard(const QString& str)
|
||||||
|
|
||||||
fs::path qstringToBoostPath(const QString &path)
|
fs::path qstringToBoostPath(const QString &path)
|
||||||
{
|
{
|
||||||
return fs::path(path.toStdString(), utf8);
|
return fs::path(path.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString boostPathToQString(const fs::path &path)
|
QString boostPathToQString(const fs::path &path)
|
||||||
{
|
{
|
||||||
return QString::fromStdString(path.string(utf8));
|
return QString::fromStdString(path.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString formatDurationStr(int secs)
|
QString formatDurationStr(int secs)
|
||||||
|
|
|
@ -1206,7 +1206,11 @@ void SetupEnvironment()
|
||||||
// A dummy locale is used to extract the internal default locale, used by
|
// A dummy locale is used to extract the internal default locale, used by
|
||||||
// fs::path, which is then used to explicitly imbue the path.
|
// fs::path, which is then used to explicitly imbue the path.
|
||||||
std::locale loc = fs::path::imbue(std::locale::classic());
|
std::locale loc = fs::path::imbue(std::locale::classic());
|
||||||
|
#ifndef WIN32
|
||||||
fs::path::imbue(loc);
|
fs::path::imbue(loc);
|
||||||
|
#else
|
||||||
|
fs::path::imbue(std::locale(loc, new std::codecvt_utf8_utf16<wchar_t>()));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetupNetworking()
|
bool SetupNetworking()
|
||||||
|
|
|
@ -54,7 +54,6 @@ EXPECTED_BOOST_INCLUDES=(
|
||||||
boost/chrono/chrono.hpp
|
boost/chrono/chrono.hpp
|
||||||
boost/date_time/posix_time/posix_time.hpp
|
boost/date_time/posix_time/posix_time.hpp
|
||||||
boost/filesystem.hpp
|
boost/filesystem.hpp
|
||||||
boost/filesystem/detail/utf8_codecvt_facet.hpp
|
|
||||||
boost/filesystem/fstream.hpp
|
boost/filesystem/fstream.hpp
|
||||||
boost/multi_index/hashed_index.hpp
|
boost/multi_index/hashed_index.hpp
|
||||||
boost/multi_index/ordered_index.hpp
|
boost/multi_index/ordered_index.hpp
|
||||||
|
|
Loading…
Reference in a new issue