未验证 提交 1cd8f3b1 编写于 作者: S stuartmorgan 提交者: GitHub

Fix and consolidate wstring conversion utils (#16342)

There were two variants of string/wstring conversion utils, one using
codecvt_utf8 and the other using codecvt_utf8_utf16. We want the latter,
since we want to be using UTF-16, not UCS2.
上级 73c51304
......@@ -76,7 +76,7 @@ static DWORD GetShareFlags(FilePermission permission) {
}
static DWORD GetFileAttributesForUtf8Path(const char* absolute_path) {
return ::GetFileAttributes(ConvertToWString(absolute_path).c_str());
return ::GetFileAttributes(StringToWideString(absolute_path).c_str());
}
static DWORD GetFileAttributesForUtf8Path(const fml::UniqueFD& base_directory,
......@@ -272,7 +272,7 @@ bool IsFile(const std::string& path) {
}
bool UnlinkDirectory(const char* path) {
if (!::RemoveDirectory(ConvertToWString(path).c_str())) {
if (!::RemoveDirectory(StringToWideString(path).c_str())) {
FML_DLOG(ERROR) << "Could not remove directory: '" << path << "'. "
<< GetLastErrorMessage();
return false;
......@@ -291,7 +291,7 @@ bool UnlinkDirectory(const fml::UniqueFD& base_directory, const char* path) {
}
bool UnlinkFile(const char* path) {
if (!::DeleteFile(ConvertToWString(path).c_str())) {
if (!::DeleteFile(StringToWideString(path).c_str())) {
FML_DLOG(ERROR) << "Could not remove file: '" << path << "'. "
<< GetLastErrorMessage();
return false;
......
......@@ -16,7 +16,7 @@ NativeLibrary::NativeLibrary(const char* path)
return;
}
handle_ = ::LoadLibrary(ConvertToWString(path).c_str());
handle_ = ::LoadLibrary(StringToWideString(path).c_str());
}
NativeLibrary::NativeLibrary(Handle handle, bool close_handle)
......
......@@ -12,16 +12,7 @@
namespace fml {
using WideStringConvertor =
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>;
inline std::wstring ConvertToWString(const char* path) {
if (path == nullptr) {
return {};
}
std::string path8(path);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> wchar_conv;
return wchar_conv.from_bytes(path8);
}
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>;
inline std::wstring StringToWideString(const std::string& str) {
WideStringConvertor converter;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册