Add support for hexadecimal floating point format specifiers a and A.

This commit is contained in:
Victor Zverovich 2014-06-10 07:03:49 -07:00
parent 546b62e74f
commit 03776dd988
3 changed files with 10 additions and 15 deletions

View File

@ -393,7 +393,7 @@ void fmt::BasicWriter<Char>::FormatDouble(
case 0:
type = 'g';
break;
case 'e': case 'f': case 'g':
case 'e': case 'f': case 'g': case 'a':
break;
case 'F':
#ifdef _MSC_VER
@ -401,7 +401,7 @@ void fmt::BasicWriter<Char>::FormatDouble(
type = 'f';
#endif
// Fall through.
case 'E': case 'G':
case 'E': case 'G': case 'A':
upper = true;
break;
default:
@ -707,17 +707,11 @@ void fmt::BasicWriter<Char>::PrintfParser::Format(
spec.width_ = 0;
ParseFlags(spec, s, *arg);
/*
if (*s == '#') {
if (arg.type > LAST_NUMERIC_TYPE)
ReportError(s, "format specifier '#' requires numeric argument");
spec.flags_ |= HASH_FLAG;
++s;
}*/
// Parse width and zero flag.
if (*s < '0' || *s > '9')
if (*s < '0' || *s > '9') {
// TODO: parse '*' width
break;
}
spec.width_ = internal::ParseNonnegativeInt(s, error);
}
// Fall through.

View File

@ -1201,7 +1201,7 @@ TEST(FormatterTest, FormatFloat) {
}
TEST(FormatterTest, FormatDouble) {
CheckUnknownTypes(1.2, "eEfFgG", "double");
CheckUnknownTypes(1.2, "eEfFgGaA", "double");
EXPECT_EQ("0", str(Format("{0:}") << 0.0));
EXPECT_EQ("0.000000", str(Format("{0:f}") << 0.0));
EXPECT_EQ("392.65", str(Format("{0:}") << 392.65));
@ -1215,6 +1215,8 @@ TEST(FormatterTest, FormatDouble) {
SPrintf(buffer, "%E", 392.65);
EXPECT_EQ(buffer, str(Format("{0:E}") << 392.65));
EXPECT_EQ("+0000392.6", str(Format("{0:+010.4g}") << 392.65));
EXPECT_EQ("-0x1.5p+5", str(Format("{:a}") << -42.0));
EXPECT_EQ("-0X1.5P+5", str(Format("{:A}") << -42.0));
}
TEST(FormatterTest, FormatNaN) {

View File

@ -210,9 +210,8 @@ TEST(PrintfTest, HashFlag) {
EXPECT_PRINTF("-42.0000", "%#g", -42.0);
EXPECT_PRINTF("-42.0000", "%#G", -42.0);
// TODO
//EXPECT_PRINTF("-0x1.5p+5", "%#a", -42.0);
//EXPECT_PRINTF("-0x1.5A+5", "%#A", -42.0);
EXPECT_PRINTF("0x1.p+4", "%#a", 16.0);
EXPECT_PRINTF("0X1.P+4", "%#A", 16.0);
// '#' flag is ignored for non-numeric types.
EXPECT_PRINTF("x", "%#c", 'x');