Commit fc6e0fe9 authored by Victor Zverovich's avatar Victor Zverovich

Fix FP formatting to a non-back_insert_iterator with sign & numeric alignment (#756)

parent 6322b47e
...@@ -2927,7 +2927,8 @@ void basic_writer<Range>::write_double(T value, const format_specs &spec) { ...@@ -2927,7 +2927,8 @@ void basic_writer<Range>::write_double(T value, const format_specs &spec) {
align_spec as = spec; align_spec as = spec;
if (spec.align() == ALIGN_NUMERIC) { if (spec.align() == ALIGN_NUMERIC) {
if (sign) { if (sign) {
*reserve(1) = sign; auto &&it = reserve(1);
*it++ = sign;
sign = 0; sign = 0;
if (as.width_) if (as.width_)
--as.width_; --as.width_;
......
...@@ -232,6 +232,12 @@ TEST(FormatToTest, Format) { ...@@ -232,6 +232,12 @@ TEST(FormatToTest, Format) {
EXPECT_EQ("part1part2", s); EXPECT_EQ("part1part2", s);
} }
TEST(FormatToTest, FormatToNonbackInsertIteratorWithSignAndNumericAlignment) {
char buffer[16] = {};
fmt::format_to(buffer, "{: =+}", 42.0);
EXPECT_STREQ("+42", buffer);
}
TEST(FormatterTest, Escape) { TEST(FormatterTest, Escape) {
EXPECT_EQ("{", format("{{")); EXPECT_EQ("{", format("{{"));
EXPECT_EQ("before {", format("before {{")); EXPECT_EQ("before {", format("before {{"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment