Bypass including Windows.h (MultiByteToWideChar/WideCharToMultiByte) (#98)

This commit is contained in:
BeastLe9enD 2021-05-10 17:13:54 +02:00 committed by GitHub
parent 369b36d288
commit 1ab8d3d022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 15 deletions

View File

@ -208,7 +208,7 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[
- **[@traversaro](https://github.com/traversaro)** - Added vcpkg support and reported a bunch of bugs
- **[@ximion](https://github.com/ximion)** - Added support for installation with meson
- **[@whiterabbit963](https://github.com/whiterabbit963)** - Fixed a bug with value_or conversions
- **[@beastle9end](https://github.com/beastle9end)** - Made Windows.h include bypass
<br>
# Contact

View File

@ -204,9 +204,16 @@ TOML_NAMESPACE_END;
// implementations of windows wide string nonsense
#if TOML_WINDOWS_COMPAT
TOML_DISABLE_WARNINGS;
#include <windows.h> // fuckkkk :(
TOML_ENABLE_WARNINGS;
namespace winapi
{
extern "C"
{
int __stdcall WideCharToMultiByte(unsigned int CodePage, unsigned long dwFlags, const wchar_t* lpWideCharStr, int cchWideChar,
const char* lpMultiByteStr, int cbMultiByte, const char* lpDefaultChar, int* lpUsedDefaultChar);
int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char* lpMultiByteStr, int cbMultiByte,
const wchar_t* lpWideCharStr, int cchWideChar);
}
}
TOML_IMPL_NAMESPACE_START
{
@ -218,13 +225,13 @@ TOML_IMPL_NAMESPACE_START
return {};
std::string s;
const auto len = WideCharToMultiByte(
const auto len = winapi::WideCharToMultiByte(
65001, 0, str.data(), static_cast<int>(str.length()), nullptr, 0, nullptr, nullptr
);
if (len)
{
s.resize(static_cast<size_t>(len));
WideCharToMultiByte(65001, 0, str.data(), static_cast<int>(str.length()), s.data(), len, nullptr, nullptr);
winapi::WideCharToMultiByte(65001, 0, str.data(), static_cast<int>(str.length()), s.data(), len, nullptr, nullptr);
}
return s;
}
@ -237,11 +244,11 @@ TOML_IMPL_NAMESPACE_START
return {};
std::wstring s;
const auto len = MultiByteToWideChar(65001, 0, str.data(), static_cast<int>(str.length()), nullptr, 0);
const auto len = winapi::MultiByteToWideChar(65001, 0, str.data(), static_cast<int>(str.length()), nullptr, 0);
if (len)
{
s.resize(static_cast<size_t>(len));
MultiByteToWideChar(65001, 0, str.data(), static_cast<int>(str.length()), s.data(), len);
winapi::MultiByteToWideChar(65001, 0, str.data(), static_cast<int>(str.length()), s.data(), len);
}
return s;
}

View File

@ -11963,9 +11963,16 @@ TOML_NAMESPACE_END;
// implementations of windows wide string nonsense
#if TOML_WINDOWS_COMPAT
TOML_DISABLE_WARNINGS;
#include <windows.h> // fuckkkk :(
TOML_ENABLE_WARNINGS;
namespace winapi
{
extern "C"
{
int __stdcall WideCharToMultiByte(unsigned int CodePage, unsigned long dwFlags, const wchar_t* lpWideCharStr, int cchWideChar,
const char* lpMultiByteStr, int cbMultiByte, const char* lpDefaultChar, int* lpUsedDefaultChar);
int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char* lpMultiByteStr, int cbMultiByte,
const wchar_t* lpWideCharStr, int cchWideChar);
}
}
TOML_IMPL_NAMESPACE_START
{
@ -11977,13 +11984,13 @@ TOML_IMPL_NAMESPACE_START
return {};
std::string s;
const auto len = WideCharToMultiByte(
const auto len = winapi::WideCharToMultiByte(
65001, 0, str.data(), static_cast<int>(str.length()), nullptr, 0, nullptr, nullptr
);
if (len)
{
s.resize(static_cast<size_t>(len));
WideCharToMultiByte(65001, 0, str.data(), static_cast<int>(str.length()), s.data(), len, nullptr, nullptr);
winapi::WideCharToMultiByte(65001, 0, str.data(), static_cast<int>(str.length()), s.data(), len, nullptr, nullptr);
}
return s;
}
@ -11996,11 +12003,11 @@ TOML_IMPL_NAMESPACE_START
return {};
std::wstring s;
const auto len = MultiByteToWideChar(65001, 0, str.data(), static_cast<int>(str.length()), nullptr, 0);
const auto len = winapi::MultiByteToWideChar(65001, 0, str.data(), static_cast<int>(str.length()), nullptr, 0);
if (len)
{
s.resize(static_cast<size_t>(len));
MultiByteToWideChar(65001, 0, str.data(), static_cast<int>(str.length()), s.data(), len);
winapi::MultiByteToWideChar(65001, 0, str.data(), static_cast<int>(str.length()), s.data(), len);
}
return s;
}