From 7fb266e91078528dad5e46f169bd9ef5ac593740 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Tue, 4 Feb 2020 13:33:07 -0800 Subject: [PATCH] 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. --- engine/src/flutter/fml/platform/win/file_win.cc | 6 +++--- .../flutter/fml/platform/win/native_library_win.cc | 2 +- .../src/flutter/fml/platform/win/wstring_conversion.h | 11 +---------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/fml/platform/win/file_win.cc b/engine/src/flutter/fml/platform/win/file_win.cc index e6319dfd5f..0b52c37fa6 100644 --- a/engine/src/flutter/fml/platform/win/file_win.cc +++ b/engine/src/flutter/fml/platform/win/file_win.cc @@ -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; diff --git a/engine/src/flutter/fml/platform/win/native_library_win.cc b/engine/src/flutter/fml/platform/win/native_library_win.cc index 3a74189396..046c3237a9 100644 --- a/engine/src/flutter/fml/platform/win/native_library_win.cc +++ b/engine/src/flutter/fml/platform/win/native_library_win.cc @@ -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) diff --git a/engine/src/flutter/fml/platform/win/wstring_conversion.h b/engine/src/flutter/fml/platform/win/wstring_conversion.h index 8258ba59f7..d68f615673 100644 --- a/engine/src/flutter/fml/platform/win/wstring_conversion.h +++ b/engine/src/flutter/fml/platform/win/wstring_conversion.h @@ -12,16 +12,7 @@ namespace fml { using WideStringConvertor = - std::wstring_convert, wchar_t>; - -inline std::wstring ConvertToWString(const char* path) { - if (path == nullptr) { - return {}; - } - std::string path8(path); - std::wstring_convert, wchar_t> wchar_conv; - return wchar_conv.from_bytes(path8); -} + std::wstring_convert, wchar_t>; inline std::wstring StringToWideString(const std::string& str) { WideStringConvertor converter;