mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
Fix incorrect call to on_align in '{:}=' (#750)
This commit is contained in:
parent
fba352a92a
commit
e2cd521b8f
@ -1975,41 +1975,42 @@ struct precision_adapter {
|
|||||||
template <typename Iterator, typename SpecHandler>
|
template <typename Iterator, typename SpecHandler>
|
||||||
FMT_CONSTEXPR Iterator parse_format_specs(Iterator it, SpecHandler &&handler) {
|
FMT_CONSTEXPR Iterator parse_format_specs(Iterator it, SpecHandler &&handler) {
|
||||||
typedef typename std::iterator_traits<Iterator>::value_type char_type;
|
typedef typename std::iterator_traits<Iterator>::value_type char_type;
|
||||||
|
char_type c = *it;
|
||||||
|
if (c == '}' || !c)
|
||||||
|
return it;
|
||||||
|
|
||||||
// Parse fill and alignment.
|
// Parse fill and alignment.
|
||||||
if (char_type c = *it) {
|
alignment align = ALIGN_DEFAULT;
|
||||||
alignment align = ALIGN_DEFAULT;
|
int i = 1;
|
||||||
int i = 1;
|
do {
|
||||||
do {
|
auto p = it + i;
|
||||||
auto p = it + i;
|
switch (*p) {
|
||||||
switch (*p) {
|
case '<':
|
||||||
case '<':
|
align = ALIGN_LEFT;
|
||||||
align = ALIGN_LEFT;
|
|
||||||
break;
|
|
||||||
case '>':
|
|
||||||
align = ALIGN_RIGHT;
|
|
||||||
break;
|
|
||||||
case '=':
|
|
||||||
align = ALIGN_NUMERIC;
|
|
||||||
break;
|
|
||||||
case '^':
|
|
||||||
align = ALIGN_CENTER;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (align != ALIGN_DEFAULT) {
|
|
||||||
handler.on_align(align);
|
|
||||||
if (p != it) {
|
|
||||||
if (c == '}') break;
|
|
||||||
if (c == '{') {
|
|
||||||
handler.on_error("invalid fill character '{'");
|
|
||||||
return it;
|
|
||||||
}
|
|
||||||
it += 2;
|
|
||||||
handler.on_fill(c);
|
|
||||||
} else ++it;
|
|
||||||
break;
|
break;
|
||||||
}
|
case '>':
|
||||||
} while (--i >= 0);
|
align = ALIGN_RIGHT;
|
||||||
}
|
break;
|
||||||
|
case '=':
|
||||||
|
align = ALIGN_NUMERIC;
|
||||||
|
break;
|
||||||
|
case '^':
|
||||||
|
align = ALIGN_CENTER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (align != ALIGN_DEFAULT) {
|
||||||
|
if (p != it) {
|
||||||
|
if (c == '{') {
|
||||||
|
handler.on_error("invalid fill character '{'");
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
it += 2;
|
||||||
|
handler.on_fill(c);
|
||||||
|
} else ++it;
|
||||||
|
handler.on_align(align);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (--i >= 0);
|
||||||
|
|
||||||
// Parse sign.
|
// Parse sign.
|
||||||
switch (*it) {
|
switch (*it) {
|
||||||
|
@ -435,6 +435,7 @@ TEST(FormatterTest, Fill) {
|
|||||||
EXPECT_EQ("c****", format("{0:*<5}", 'c'));
|
EXPECT_EQ("c****", format("{0:*<5}", 'c'));
|
||||||
EXPECT_EQ("abc**", format("{0:*<5}", "abc"));
|
EXPECT_EQ("abc**", format("{0:*<5}", "abc"));
|
||||||
EXPECT_EQ("**0xface", format("{0:*>8}", reinterpret_cast<void*>(0xface)));
|
EXPECT_EQ("**0xface", format("{0:*>8}", reinterpret_cast<void*>(0xface)));
|
||||||
|
EXPECT_EQ("foo=", format("{:}=", "foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, PlusSign) {
|
TEST(FormatterTest, PlusSign) {
|
||||||
|
Loading…
Reference in New Issue
Block a user