mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-27 12:49:46 +01:00
More showpoint fixes and tests (#1498)
This commit is contained in:
@@ -1112,7 +1112,7 @@ int snprintf_float(T value, int precision, float_specs specs,
|
||||
char format[max_format_size];
|
||||
char* format_ptr = format;
|
||||
*format_ptr++ = '%';
|
||||
if (specs.showpoint) *format_ptr++ = '#';
|
||||
if (specs.showpoint && specs.format == float_format::hex) *format_ptr++ = '#';
|
||||
if (precision >= 0) {
|
||||
*format_ptr++ = '.';
|
||||
*format_ptr++ = '*';
|
||||
@@ -1351,7 +1351,8 @@ FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) {
|
||||
internal::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size()));
|
||||
auto written = DWORD();
|
||||
if (!WriteConsoleW(reinterpret_cast<HANDLE>(_get_osfhandle(fd)),
|
||||
u16.c_str(), static_cast<DWORD>(u16.size()), &written, nullptr)) {
|
||||
u16.c_str(), static_cast<DWORD>(u16.size()), &written,
|
||||
nullptr)) {
|
||||
throw format_error("failed to write to console");
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -1125,9 +1125,10 @@ template <typename Char> class float_writer {
|
||||
if (specs_.precision >= 0 && specs_.precision < num_zeros)
|
||||
num_zeros = specs_.precision;
|
||||
int num_digits = num_digits_;
|
||||
// Remove trailing zeros.
|
||||
if (!specs_.showpoint)
|
||||
while (num_digits > 0 && digits_[num_digits - 1] == '0') --num_digits;
|
||||
if (num_zeros != 0 || num_digits != 0) {
|
||||
if (num_zeros != 0 || num_digits != 0 || specs_.showpoint) {
|
||||
*it++ = decimal_point_;
|
||||
it = std::fill_n(it, num_zeros, static_cast<Char>('0'));
|
||||
it = copy_str<Char>(digits_, digits_ + num_digits, it);
|
||||
|
||||
Reference in New Issue
Block a user