mirror of
https://github.com/fmtlib/fmt.git
synced 2026-10-29 02:17:28 +08:00
Use classic locale grouping without locale support (#4947)
This commit is contained in:
parent
0482001875
commit
1ffdc7687f
@ -2793,7 +2793,9 @@ template <typename Char, typename Grouping, typename OutputIt,
|
||||
FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
|
||||
const format_specs& specs, sign s,
|
||||
int exp_upper, locale_ref loc) -> OutputIt {
|
||||
Char point = specs.localized() ? detail::decimal_point<Char>(loc) : Char('.');
|
||||
Char point = FMT_USE_LOCALE && specs.localized()
|
||||
? detail::decimal_point<Char>(loc)
|
||||
: Char('.');
|
||||
int significand_size = get_significand_size(f);
|
||||
int exp = f.exponent + significand_size - 1;
|
||||
if (specs.type() == presentation_type::fixed ||
|
||||
@ -2832,7 +2834,7 @@ template <typename Char, typename OutputIt, typename DecimalFP>
|
||||
FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f,
|
||||
const format_specs& specs, sign s,
|
||||
int exp_upper, locale_ref loc) -> OutputIt {
|
||||
if (is_constant_evaluated()) {
|
||||
if (is_constant_evaluated() || !FMT_USE_LOCALE) {
|
||||
return do_write_float<Char, fallback_digit_grouping<Char>>(out, f, specs, s,
|
||||
exp_upper, loc);
|
||||
} else {
|
||||
|
||||
@ -129,12 +129,13 @@ if (FMT_PEDANTIC)
|
||||
endif ()
|
||||
|
||||
# Test that the library compiles without locale.
|
||||
add_library(nolocale-test ../src/format.cc)
|
||||
add_executable(nolocale-test ../src/format.cc nolocale-test.cc)
|
||||
target_include_directories(nolocale-test
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_compile_definitions(nolocale-test PRIVATE FMT_USE_LOCALE=0)
|
||||
target_compile_options(nolocale-test
|
||||
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
|
||||
add_test(NAME nolocale-test COMMAND nolocale-test)
|
||||
endif ()
|
||||
|
||||
# These tests are disabled on Windows because they take too long.
|
||||
|
||||
13
test/nolocale-test.cc
Normal file
13
test/nolocale-test.cc
Normal file
@ -0,0 +1,13 @@
|
||||
// Formatting library for C++ - no-locale tests
|
||||
//
|
||||
// Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#include "fmt/format.h"
|
||||
|
||||
int main() {
|
||||
if (fmt::format("{:L}", 1234567) != "1234567") return 1;
|
||||
if (fmt::format("{:L}", 1234.5) != "1234.5") return 1;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user