Skip to content

Commit

Permalink
Fix FP formatting to a non-back_insert_iterator with sign & numeric a…
Browse files Browse the repository at this point in the history
…lignment (#756)
  • Loading branch information
vitaut committed Jun 7, 2018
1 parent 6322b47 commit fc6e0fe
Show file tree
Hide file tree
Showing 2 changed files with 8 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 @@ -2927,7 +2927,8 @@ void basic_writer<Range>::write_double(T value, const format_specs &spec) {
align_spec as = spec;
if (spec.align() == ALIGN_NUMERIC) {
if (sign) {
*reserve(1) = sign;
auto &&it = reserve(1);
*it++ = sign;
sign = 0;
if (as.width_)
--as.width_;
Expand Down
6 changes: 6 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ TEST(FormatToTest, Format) {
EXPECT_EQ("part1part2", s);
}

TEST(FormatToTest, FormatToNonbackInsertIteratorWithSignAndNumericAlignment) {
char buffer[16] = {};
fmt::format_to(buffer, "{: =+}", 42.0);
EXPECT_STREQ("+42", buffer);
}

TEST(FormatterTest, Escape) {
EXPECT_EQ("{", format("{{"));
EXPECT_EQ("before {", format("before {{"));
Expand Down

0 comments on commit fc6e0fe

Please sign in to comment.