mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-22 02:20:06 +00:00
Ignore 0 character with align
This commit is contained in:
parent
840ec8569d
commit
a585571e90
@ -2237,7 +2237,9 @@ template <typename Char> class specs_setter {
|
|||||||
FMT_CONSTEXPR void on_localized() { specs_.localized = true; }
|
FMT_CONSTEXPR void on_localized() { specs_.localized = true; }
|
||||||
|
|
||||||
FMT_CONSTEXPR void on_zero() {
|
FMT_CONSTEXPR void on_zero() {
|
||||||
if (specs_.align == align::none) specs_.align = align::numeric;
|
// If the 0 character and an align option both appear, the 0 character is ignored.
|
||||||
|
if (specs_.align != align::none) return;
|
||||||
|
specs_.align = align::numeric;
|
||||||
specs_.fill[0] = Char('0');
|
specs_.fill[0] = Char('0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,6 +799,16 @@ TEST(format_test, zero_flag) {
|
|||||||
format_error, "format specifier requires numeric argument");
|
format_error, "format specifier requires numeric argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(format_test, zero_flag_and_align) {
|
||||||
|
// If the 0 character and an align option both appear, the 0 character is ignored.
|
||||||
|
EXPECT_EQ("42 ", fmt::format("{0:<05}", 42));
|
||||||
|
EXPECT_EQ("-42 ", fmt::format("{0:<05}", -42));
|
||||||
|
EXPECT_EQ(" 42 ", fmt::format("{0:^05}", 42));
|
||||||
|
EXPECT_EQ(" -42 ", fmt::format("{0:^05}", -42));
|
||||||
|
EXPECT_EQ(" 42", fmt::format("{0:>05}", 42));
|
||||||
|
EXPECT_EQ(" -42", fmt::format("{0:>05}", -42));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(format_test, width) {
|
TEST(format_test, width) {
|
||||||
char format_str[buffer_size];
|
char format_str[buffer_size];
|
||||||
safe_sprintf(format_str, "{0:%u", UINT_MAX);
|
safe_sprintf(format_str, "{0:%u", UINT_MAX);
|
||||||
@ -833,7 +843,7 @@ TEST(format_test, width) {
|
|||||||
EXPECT_EQ(fmt::format("{:*^8}", "你好"), "**你好**");
|
EXPECT_EQ(fmt::format("{:*^8}", "你好"), "**你好**");
|
||||||
EXPECT_EQ(fmt::format("{:#6}", 42.0), " 42.0");
|
EXPECT_EQ(fmt::format("{:#6}", 42.0), " 42.0");
|
||||||
EXPECT_EQ(fmt::format("{:6c}", static_cast<int>('x')), "x ");
|
EXPECT_EQ(fmt::format("{:6c}", static_cast<int>('x')), "x ");
|
||||||
EXPECT_EQ(fmt::format("{:>06.0f}", 0.00884311), "000000");
|
EXPECT_EQ(fmt::format("{:>06.0f}", 0.00884311), " 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(format_test, runtime_width) {
|
TEST(format_test, runtime_width) {
|
||||||
|
Loading…
Reference in New Issue
Block a user