Skip to content

Commit

Permalink
Support for the s format specifier to bool (fmtlib#2094)
Browse files Browse the repository at this point in the history
  • Loading branch information
powercoderlol committed Jan 21, 2021
1 parent 456efa4 commit 200a4a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2344,7 +2344,8 @@ class arg_formatter_base {
}

FMT_CONSTEXPR iterator operator()(bool value) {
if (specs_ && specs_->type) return (*this)(value ? 1 : 0);
if (specs_ && specs_->type != 0 && specs_->type != 's')
return (*this)(value ? 1 : 0);
write(value != 0);
return out_;
}
Expand Down
3 changes: 3 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,9 @@ TEST(BoolTest, FormatBool) {
EXPECT_EQ("1", format("{:d}", true));
EXPECT_EQ("true ", format("{:5}", true));
EXPECT_EQ(L"true", format(L"{}", true));
EXPECT_EQ("true", format("{:s}", true));
EXPECT_EQ("false", format("{:s}", false));
EXPECT_EQ("false ", format("{:6s}", false));
}

TEST(FormatterTest, FormatShort) {
Expand Down

0 comments on commit 200a4a0

Please sign in to comment.