Implement 'l' length specifier.

This commit is contained in:
Victor Zverovich 2014-08-01 07:15:27 -07:00
parent be9356b651
commit a259c941e2
2 changed files with 9 additions and 10 deletions

View File

@ -233,11 +233,12 @@ class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
} else { } else {
if (is_signed) { if (is_signed) {
arg_.type = Arg::LONG_LONG; arg_.type = Arg::LONG_LONG;
arg_.long_long_value = static_cast<T>(value); arg_.long_long_value =
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
} else { } else {
arg_.type = Arg::ULONG_LONG; arg_.type = Arg::ULONG_LONG;
arg_.ulong_long_value = arg_.ulong_long_value =
static_cast<typename fmt::internal::MakeUnsigned<T>::Type>(value); static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
} }
} }
} }
@ -906,10 +907,6 @@ void fmt::internal::PrintfFormatter<Char>::format(
} }
// Parse length and convert the argument to the required type. // Parse length and convert the argument to the required type.
// Conversion is done for compatibility with glibc's printf, MSVC's
// printf simply ignores width specifiers. For example:
// printf("%hhd", -129);
// prints 127 when using glibc's printf and -129 when using MSVC's one.
switch (*s) { switch (*s) {
case 'h': { case 'h': {
++s; ++s;

View File

@ -308,6 +308,8 @@ void TestLength(const char *length_spec) {
EXPECT_STD_PRINTF(format, T, max); EXPECT_STD_PRINTF(format, T, max);
EXPECT_STD_PRINTF(format, T, fmt::LongLong(min) - 1); EXPECT_STD_PRINTF(format, T, fmt::LongLong(min) - 1);
EXPECT_STD_PRINTF(format, T, fmt::LongLong(max) + 1); EXPECT_STD_PRINTF(format, T, fmt::LongLong(max) + 1);
EXPECT_STD_PRINTF(format, T, std::numeric_limits<short>::min());
EXPECT_STD_PRINTF(format, T, std::numeric_limits<unsigned short>::max());
EXPECT_STD_PRINTF(format, T, std::numeric_limits<int>::min()); EXPECT_STD_PRINTF(format, T, std::numeric_limits<int>::min());
EXPECT_STD_PRINTF(format, T, std::numeric_limits<int>::max()); EXPECT_STD_PRINTF(format, T, std::numeric_limits<int>::max());
EXPECT_STD_PRINTF(format, T, std::numeric_limits<unsigned>::min()); EXPECT_STD_PRINTF(format, T, std::numeric_limits<unsigned>::min());
@ -320,12 +322,12 @@ void TestLength(const char *length_spec) {
} }
TEST(PrintfTest, Length) { TEST(PrintfTest, Length) {
TestLength<short>("h");
TestLength<unsigned short>("h");
TestLength<signed char>("hh"); TestLength<signed char>("hh");
TestLength<unsigned char>("hh"); TestLength<unsigned char>("hh");
//TestLength<long>("l"); TestLength<short>("h");
//TestLength<unsigned long>("l"); TestLength<unsigned short>("h");
TestLength<long>("l");
TestLength<unsigned long>("l");
// TODO: more tests // TODO: more tests
} }