From ca692e52cee55da2f9d65d66e5f3997f3a335743 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 2 Oct 2017 16:40:18 -0700 Subject: [PATCH] Replace deprecated std::codecvt/std::wstring_convert. Fixes building with v141 --- toolsrc/src/vcpkg_Strings.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 1bd96fc12f..964ed73d01 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -73,14 +73,20 @@ namespace vcpkg::Strings { std::wstring to_utf16(const CStringView s) { - std::wstring_convert, wchar_t> conversion; - return conversion.from_bytes(s); + const size_t size = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, nullptr, 0); + std::wstring output; + output.resize(size - 1); + MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, output.data(), size - 1); + return output; } std::string to_utf8(const CWStringView w) { - std::wstring_convert, wchar_t> conversion; - return conversion.to_bytes(w); + const size_t size = WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, nullptr, 0, nullptr, nullptr); + std::string output; + output.resize(size - 1); + WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, output.data(), size - 1, nullptr, nullptr); + return output; } std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern)