lib/icu/Win32: pass std::string_view

This commit is contained in:
Max Kellermann
2020-04-03 15:00:01 +02:00
parent a269fc988b
commit 2d0798cd4d
3 changed files with 18 additions and 14 deletions

View File

@@ -26,15 +26,16 @@
#include <windows.h>
AllocatedString<char>
WideCharToMultiByte(unsigned code_page, const wchar_t *src)
WideCharToMultiByte(unsigned code_page, std::wstring_view src)
{
int length = WideCharToMultiByte(code_page, 0, src, -1, nullptr, 0,
int length = WideCharToMultiByte(code_page, 0, src.data(), src.size(),
nullptr, 0,
nullptr, nullptr);
if (length <= 0)
throw MakeLastError("Failed to convert from Unicode");
std::unique_ptr<char[]> buffer(new char[length]);
length = WideCharToMultiByte(code_page, 0, src, -1,
length = WideCharToMultiByte(code_page, 0, src.data(), src.size(),
buffer.get(), length,
nullptr, nullptr);
if (length <= 0)
@@ -44,14 +45,15 @@ WideCharToMultiByte(unsigned code_page, const wchar_t *src)
}
AllocatedString<wchar_t>
MultiByteToWideChar(unsigned code_page, const char *src)
MultiByteToWideChar(unsigned code_page, std::string_view src)
{
int length = MultiByteToWideChar(code_page, 0, src, -1, nullptr, 0);
int length = MultiByteToWideChar(code_page, 0, src.data(), src.size(),
nullptr, 0);
if (length <= 0)
throw MakeLastError("Failed to convert to Unicode");
std::unique_ptr<wchar_t[]> buffer(new wchar_t[length]);
length = MultiByteToWideChar(code_page, 0, src, -1,
length = MultiByteToWideChar(code_page, 0, src.data(), src.size(),
buffer.get(), length);
if (length <= 0)
throw MakeLastError("Failed to convert to Unicode");