fix some warnings

This commit is contained in:
Megamouse 2023-12-29 18:33:29 +01:00
parent b1c48e66c9
commit 59c58aa3cf
72 changed files with 263 additions and 203 deletions

View file

@ -21,9 +21,10 @@ std::string wchar_to_utf8(std::wstring_view src)
{
#ifdef _WIN32
std::string utf8_string;
const auto tmp_size = WideCharToMultiByte(CP_UTF8, 0, src.data(), src.size(), nullptr, 0, nullptr, nullptr);
const int size = ::narrow<int>(src.size());
const auto tmp_size = WideCharToMultiByte(CP_UTF8, 0, src.data(), size, nullptr, 0, nullptr, nullptr);
utf8_string.resize(tmp_size);
WideCharToMultiByte(CP_UTF8, 0, src.data(), src.size(), utf8_string.data(), tmp_size, nullptr, nullptr);
WideCharToMultiByte(CP_UTF8, 0, src.data(), size, utf8_string.data(), tmp_size, nullptr, nullptr);
return utf8_string;
#else
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter{};
@ -31,7 +32,10 @@ std::string wchar_to_utf8(std::wstring_view src)
#endif
}
#ifndef _MSC_VER
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
@ -46,7 +50,9 @@ std::u16string utf8_to_utf16(std::string_view src)
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter{};
return converter.from_bytes(src.data());
}
#ifndef _MSC_VER
#ifdef _MSC_VER
#pragma warning(pop)
#else
#pragma GCC diagnostic pop
#endif
@ -54,9 +60,10 @@ std::wstring utf8_to_wchar(std::string_view src)
{
#ifdef _WIN32
std::wstring wchar_string;
const auto tmp_size = MultiByteToWideChar(CP_UTF8, 0, src.data(), src.size(), nullptr, 0);
const int size = ::narrow<int>(src.size());
const auto tmp_size = MultiByteToWideChar(CP_UTF8, 0, src.data(), size, nullptr, 0);
wchar_string.resize(tmp_size);
MultiByteToWideChar(CP_UTF8, 0, src.data(), src.size(), wchar_string.data(), tmp_size);
MultiByteToWideChar(CP_UTF8, 0, src.data(), size, wchar_string.data(), tmp_size);
return wchar_string;
#else
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter{};