Fix and consolidate wstring conversion utils (flutter/engine#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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user