1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef FLUTTER_FML_PLATFORM_WIN_WSTRING_CONVERSION_H_ 6 #define FLUTTER_FML_PLATFORM_WIN_WSTRING_CONVERSION_H_ 7 8 #include <codecvt> 9 #include <locale> 10 #include <string> 11 12 namespace fml { 13 14 using WideStringConvertor = 15 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>; 16 ConvertToWString(const char * path)17inline std::wstring ConvertToWString(const char* path) { 18 if (path == nullptr) { 19 return {}; 20 } 21 std::string path8(path); 22 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> wchar_conv; 23 return wchar_conv.from_bytes(path8); 24 } 25 StringToWideString(const std::string & str)26inline std::wstring StringToWideString(const std::string& str) { 27 WideStringConvertor converter; 28 return converter.from_bytes(str); 29 } 30 WideStringToString(const std::wstring & wstr)31inline std::string WideStringToString(const std::wstring& wstr) { 32 WideStringConvertor converter; 33 return converter.to_bytes(wstr); 34 } 35 36 } // namespace fml 37 38 #endif // FLUTTER_FML_PLATFORM_WIN_WSTRING_CONVERSION_H_ 39