-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<format> assumes strings are encoded in the active code page
#1834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d298aa
`format` assumes strings are encoded in the active code page
CaseyCarter eaa454f
More hygienic testing method
CaseyCarter 9494a9c
Review comments
CaseyCarter 799a55a
Remove confusing comment
CaseyCarter c6efbdb
Add test coverage for width estimation
CaseyCarter 16c599c
*sigh* commit the fix for the second bug
CaseyCarter 3f2944f
More review comments
CaseyCarter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
|
|
||
CaseyCarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // 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( | ||
CaseyCarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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()}; | ||
CaseyCarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| _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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.