Skip to content

Commit

Permalink
make plus flag for printf not be ignored for char argument (#1683)
Browse files Browse the repository at this point in the history
* make plus flag for printf not be ignored for char argument

* clarify overwriting of alignment specifiers for printf with char argument
  • Loading branch information
rimathia authored May 15, 2020
1 parent 981b517 commit 96c18b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/fmt/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ class printf_arg_formatter : public detail::arg_formatter_base<Range> {
return (*this)(static_cast<int>(value));
fmt_specs.sign = sign::none;
fmt_specs.alt = false;
fmt_specs.align = align::right;
// align::numeric needs to be overwritten here since the '0' flag is
// ignored for non-numeric types
if (fmt_specs.align == align::none || fmt_specs.align == align::numeric)
fmt_specs.align = align::right;
return base::operator()(value);
} else {
return base::operator()(value);
Expand Down
4 changes: 4 additions & 0 deletions test/printf-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ TEST(PrintfTest, PlusFlag) {
TEST(PrintfTest, MinusFlag) {
EXPECT_PRINTF("abc ", "%-5s", "abc");
EXPECT_PRINTF("abc ", "%0--5s", "abc");

EXPECT_PRINTF("7 ", "%-5d", 7);
EXPECT_PRINTF("97 ", "%-5hhi", 'a');
EXPECT_PRINTF("a ", "%-5c", 'a');
}

TEST(PrintfTest, SpaceFlag) {
Expand Down

0 comments on commit 96c18b2

Please sign in to comment.