Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyCarter authored and StephanTLavavej committed Apr 15, 2021
1 parent eaa454f commit 9494a9c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
17 changes: 7 additions & 10 deletions stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

extern "C" _NODISCARD __std_win_error __stdcall __std_get_cvt(
const __std_code_page _Codepage, _Cvtvec* const _Pcvt) noexcept;
extern "C" _NODISCARD __std_win_error __stdcall __std_get_cvt(__std_code_page _Codepage, _Cvtvec* _Pcvt) noexcept;

_STD_BEGIN

Expand Down Expand Up @@ -501,9 +500,8 @@ protected:
#ifndef _FORMAT_CODEPAGE
#define _FORMAT_CODEPAGE __std_code_page::_Acp
#endif // _FORMAT_CODEPAGE
if (__std_get_cvt(_FORMAT_CODEPAGE, &_Cvt) != __std_win_error::_Success) {
_THROW(format_error("failed to retrieve codepage info"));
}
[[maybe_unused]] const __std_win_error _Result = __std_get_cvt(_FORMAT_CODEPAGE, &_Cvt);
_STL_INTERNAL_CHECK(_Result == __std_win_error::_Success);
#undef _FORMAT_CODEPAGE
}
};
Expand Down Expand Up @@ -537,7 +535,7 @@ private:
return (_Len >= 4) ? 4 : -1;
}

_NODISCARD static constexpr int _Estimate_utf8_character_width(const char* const _Ptr, const int _Units) noexcept {
_NODISCARD static int _Estimate_utf8_character_width(const char* const _Ptr, const int _Units) noexcept {
// Return an estimate for the width of the character composed of _Units code units,
// whose first code unit is denoted by _Ptr.
auto _Ch = static_cast<char32_t>(*_Ptr);
Expand Down Expand Up @@ -633,7 +631,6 @@ public:

template <bool _Statically_Utf8>
class _Fmt_codec<wchar_t, _Statically_Utf8> {
private:
public:
_NODISCARD int _Units_in_next_character(const wchar_t* _First, const wchar_t* _Last) const noexcept {
// Returns a count of the number of code units that compose the first encoded character in
Expand Down Expand Up @@ -948,15 +945,15 @@ template <class _CharT, _Parse_replacement_field_callbacks<_CharT> _HandlerT>
void _Parse_format_string(basic_string_view<_CharT> _Format_str, _HandlerT&& _Handler) {
auto _Begin = _Format_str.data();
auto _End = _Begin + _Format_str.size();
const _Fmt_codec<_CharT> _Counter{};
const _Fmt_codec<_CharT> _Codec;

while (_Begin != _End) {
const _CharT* _OpeningCurl = _Begin;
if (*_Begin != '{') {
_OpeningCurl = _Counter._Find_encoded(_Begin, _End, _CharT{'{'});
_OpeningCurl = _Codec._Find_encoded(_Begin, _End, _CharT{'{'});

for (;;) {
const _CharT* _ClosingCurl = _Counter._Find_encoded(_Begin, _OpeningCurl, _CharT{'}'});
const _CharT* _ClosingCurl = _Codec._Find_encoded(_Begin, _OpeningCurl, _CharT{'}'});

// In this case there are neither closing nor opening curls in [_Begin, _OpeningCurl)
// Write the whole thing out.
Expand Down
1 change: 1 addition & 0 deletions stl/msbuild/stl_base/stl.files.settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
(controlled by IncludeInLink and IncludeInImportLib). -->
<BuildFiles Include="
$(CrtRoot)\github\stl\src\filesystem.cpp;
$(CrtRoot)\github\stl\src\format.cpp;
$(CrtRoot)\github\stl\src\locale0_implib.cpp;
$(CrtRoot)\github\stl\src\nothrow.cpp;
$(CrtRoot)\github\stl\src\sharedmutex.cpp;
Expand Down
14 changes: 8 additions & 6 deletions stl/src/format.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
// 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});

// CODEPAGE is conditionally defined so tests can override it.
#ifndef CODEPAGE
#define CODEPAGE(x) static_cast<UINT>(x)
#endif

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(CODEPAGE(_Codepage), _Flags, &_Info) == 0) {
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()};
Expand Down

0 comments on commit 9494a9c

Please sign in to comment.