Implement more printf length specifiers.

This commit is contained in:
Victor Zverovich 2014-08-09 10:04:35 -07:00
parent 6a8becb5bf
commit 316ae7e244
2 changed files with 12 additions and 8 deletions

View File

@ -908,26 +908,30 @@ void fmt::internal::PrintfFormatter<Char>::format(
}
// Parse length and convert the argument to the required type.
switch (*s) {
case 'h': {
++s;
switch (*s++) {
case 'h':
if (*s == 'h')
ArgConverter<signed char>(arg, *++s).visit(arg);
else
ArgConverter<short>(arg, *s).visit(arg);
break;
}
case 'l':
++s;
ArgConverter<long>(arg, *s).visit(arg);
break;
case 'j':
ArgConverter<intmax_t>(arg, *s).visit(arg);
break;
case 'z':
ArgConverter<size_t>(arg, *s).visit(arg);
break;
case 't':
ArgConverter<ptrdiff_t>(arg, *s).visit(arg);
break;
case 'L':
// TODO: handle length
++s;
break;
default:
--s;
}
// Parse type.

View File

@ -350,8 +350,8 @@ TEST(PrintfTest, Length) {
TestLength<unsigned char>("hh");
TestLength<short>("h");
TestLength<unsigned short>("h");
//TestLength<long>("l");
//TestLength<unsigned long>("l");
TestLength<long>("l");
TestLength<unsigned long>("l");
// TODO: more tests
}