`<chrono>`: Estimate width of aligned chronat strings (#2017)

Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
This commit is contained in:
Matt Stephanson 2021-06-29 14:41:51 -07:00 коммит произвёл GitHub
Родитель 934a39ec18
Коммит 27b916fe2b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -5971,8 +5971,10 @@ namespace chrono {
}
}
return _Write_aligned(_STD move(_FormatCtx.out()), static_cast<int>(_Stream.view().size()), _Specs,
_Fmt_align::_Left, [&](auto _Out) { return _Fmt_write(_STD move(_Out), _Stream.view()); });
int _Estimated_width = -1;
(void) _Measure_string_prefix(_Stream.view(), _Estimated_width);
return _Write_aligned(_STD move(_FormatCtx.out()), _Estimated_width, _Specs, _Fmt_align::_Left,
[&](auto _Out) { return _Fmt_write(_STD move(_Out), _Stream.view()); });
}
// This echoes the functionality of put_time, but is able to handle invalid dates (when !ok()) since the

Просмотреть файл

@ -2,3 +2,5 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
RUNALL_INCLUDE ..\concepts_latest_matrix.lst
RUNALL_CROSSLIST
PM_CL="/utf-8"

Просмотреть файл

@ -3,9 +3,11 @@
#include <assert.h>
#include <chrono>
#include <clocale>
#include <concepts>
#include <format>
#include <iostream>
#include <locale>
#include <sstream>
#include <stdio.h>
#include <string>
@ -29,6 +31,13 @@ template <typename CharT>
#define STR(Literal) (choose_literal<CharT>(Literal, L##Literal))
// Test against IDL mismatch between the DLL which stores the locale and the code which uses it.
#ifdef _DEBUG
#define DEFAULT_IDL_SETTING 2
#else
#define DEFAULT_IDL_SETTING 0
#endif
template <typename CharT>
struct testing_callbacks {
_Fmt_align expected_alignment = _Fmt_align::_None;
@ -889,6 +898,12 @@ void test_zoned_time_formatter() {
assert(format(STR("{:%g %G %U %V %W}"), zt) == STR("21 2021 16 16 16"));
}
template <typename CharT>
void test_locale() {
assert(format(locale{"zh-CN"}, STR("{:^22%Y %B %d %A}"), 2021y / June / 16d)
== STR(" 2021 \u516D\u6708 16 \u661F\u671F\u4E09 "));
}
void test() {
test_parse_conversion_spec<char>();
test_parse_conversion_spec<wchar_t>();
@ -960,6 +975,14 @@ void test() {
test_zoned_time_formatter<char>();
test_zoned_time_formatter<wchar_t>();
#if !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING
test_locale<wchar_t>();
#ifndef MSVC_INTERNAL_TESTING // TRANSITION, the Windows version on Contest VMs doesn't always understand ".UTF-8"
assert(setlocale(LC_ALL, ".UTF-8") != nullptr);
test_locale<char>();
#endif // MSVC_INTERNAL_TESTING
#endif // !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING
}
int main() {