-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<format>
assumes strings are encoded in the active code page (#1834)
- Loading branch information
1 parent
a108657
commit ccc5aaa
Showing
10 changed files
with
435 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
// Implements a win32 API wrapper for <format> | ||
|
||
// This must be as small as possible, because its contents are | ||
// injected into the msvcprt.lib and msvcprtd.lib import libraries. | ||
// Do not include or define anything else here. | ||
// In particular, basic_string must not be included here. | ||
|
||
#include <xfilesystem_abi.h> | ||
#include <xlocinfo.h> | ||
|
||
#include <Windows.h> | ||
|
||
static_assert(__std_code_page::_Acp == __std_code_page{CP_ACP}); | ||
|
||
extern "C" [[nodiscard]] __std_win_error __stdcall __std_get_cvt( | ||
const __std_code_page _Codepage, _Cvtvec* const _Pcvt) noexcept { | ||
// get conversion info for an arbitrary codepage | ||
*_Pcvt = {}; | ||
|
||
CPINFOEXW _Info{}; | ||
const DWORD _Flags = 0; // reserved, must be zero | ||
if (GetCPInfoExW(static_cast<UINT>(_Codepage), _Flags, &_Info) == 0) { | ||
// NB: the only documented failure mode for GetCPInfoExW is ERROR_INVALID_PARAMETER, | ||
// so in practice it should never fail for CP_ACP. | ||
return __std_win_error{GetLastError()}; | ||
} | ||
|
||
_Pcvt->_Page = _Info.CodePage; | ||
_Pcvt->_Mbcurmax = _Info.MaxCharSize; | ||
|
||
for (int _Idx = 0; _Idx < MAX_LEADBYTES; _Idx += 2) { | ||
if (_Info.LeadByte[_Idx] == 0 && _Info.LeadByte[_Idx + 1] == 0) { | ||
break; | ||
} | ||
|
||
for (unsigned char _First = _Info.LeadByte[_Idx], _Last = _Info.LeadByte[_Idx + 1]; _First != _Last; ++_First) { | ||
_Pcvt->_Isleadbyte[_First >> 3] |= 1u << (_First & 0b111u); | ||
} | ||
} | ||
|
||
return __std_win_error::_Success; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.