unicode: Remove deprecated MB_PRECOMPOSED
Online documentation suggests it should be used as default (for the most of code pages), SDK source code says it's deprecated. Let's remove it and see how things work. Reference: https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
832daf89d6
commit
50578dabaa
@ -197,10 +197,9 @@ namespace stdex
|
||||
stdex_assert(count_src < INT_MAX || count_src == SIZE_MAX);
|
||||
|
||||
// Try to convert to stack buffer first.
|
||||
DWORD dwFlagsMBWC = static_cast<UINT>(m_from_wincp) < CP_UTF7 ? MB_PRECOMPOSED : 0;
|
||||
WCHAR szStackBuffer[1024 / sizeof(WCHAR)];
|
||||
#pragma warning(suppress: 6387) // Testing indicates src may be NULL when count_src is also 0. Is SAL of the lpMultiByteStr parameter wrong?
|
||||
int cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), dwFlagsMBWC, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), szStackBuffer, _countof(szStackBuffer));
|
||||
int cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), 0, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), szStackBuffer, _countof(szStackBuffer));
|
||||
if (cch) {
|
||||
// Append from stack.
|
||||
dst.append(reinterpret_cast<const T_to*>(szStackBuffer), count_src != SIZE_MAX ? wcsnlen(szStackBuffer, cch) : static_cast<size_t>(cch) - 1);
|
||||
@ -209,10 +208,10 @@ namespace stdex
|
||||
DWORD dwResult = GetLastError();
|
||||
if (dwResult == ERROR_INSUFFICIENT_BUFFER) {
|
||||
// Query the required output size. Allocate buffer. Then convert again.
|
||||
cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), dwFlagsMBWC, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), NULL, 0);
|
||||
cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), 0, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), NULL, 0);
|
||||
size_t offset = dst.size();
|
||||
dst.resize(offset + static_cast<size_t>(cch));
|
||||
cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), dwFlagsMBWC, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), &dst[offset], cch);
|
||||
cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), 0, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), &dst[offset], cch);
|
||||
dst.resize(offset + (count_src != SIZE_MAX ? wcsnlen(&dst[offset], cch) : static_cast<size_t>(cch) - 1));
|
||||
return;
|
||||
}
|
||||
@ -250,10 +249,10 @@ namespace stdex
|
||||
stdex_assert(count_src < INT_MAX || count_src == SIZE_MAX);
|
||||
|
||||
// Try to convert to stack buffer first.
|
||||
DWORD dwFlagsMBWC = static_cast<UINT>(m_from_wincp) < CP_UTF7 ? MB_PRECOMPOSED : 0, dwResult;
|
||||
DWORD dwResult;
|
||||
WCHAR szStackBufferMBWC[512 / sizeof(WCHAR)];
|
||||
#pragma warning(suppress: 6387) // Testing indicates src may be NULL when count_src is also 0. Is SAL of the lpMultiByteStr parameter wrong?
|
||||
int cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), dwFlagsMBWC, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), szStackBufferMBWC, _countof(szStackBufferMBWC));
|
||||
int cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), 0, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), szStackBufferMBWC, _countof(szStackBufferMBWC));
|
||||
if (cch) {
|
||||
// Append from stack.
|
||||
size_t count_inter = count_src != SIZE_MAX ? wcsnlen(szStackBufferMBWC, cch) : static_cast<size_t>(cch) - 1;
|
||||
@ -283,9 +282,9 @@ namespace stdex
|
||||
dwResult = GetLastError();
|
||||
if (dwResult == ERROR_INSUFFICIENT_BUFFER) {
|
||||
// Query the required output size. Allocate buffer. Then convert again.
|
||||
cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), dwFlagsMBWC, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), NULL, 0);
|
||||
cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), 0, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), NULL, 0);
|
||||
std::unique_ptr<WCHAR[]> szBufferMBWC(new WCHAR[cch]);
|
||||
cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), dwFlagsMBWC, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), szBufferMBWC.get(), cch);
|
||||
cch = MultiByteToWideChar(static_cast<UINT>(m_from_wincp), 0, reinterpret_cast<LPCCH>(src), static_cast<int>(count_src), szBufferMBWC.get(), cch);
|
||||
size_t count_inter = count_src != SIZE_MAX ? wcsnlen(szBufferMBWC.get(), cch) : static_cast<size_t>(cch) - 1;
|
||||
|
||||
// Query the required output size. Allocate buffer. Then convert again.
|
||||
|
Loading…
x
Reference in New Issue
Block a user