mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-22 18:40:05 +00:00
Implement 'l' length specifier.
This commit is contained in:
parent
be9356b651
commit
a259c941e2
@ -233,11 +233,12 @@ class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
|
||||
} else {
|
||||
if (is_signed) {
|
||||
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 {
|
||||
arg_.type = Arg::ULONG_LONG;
|
||||
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.
|
||||
// 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) {
|
||||
case 'h': {
|
||||
++s;
|
||||
|
@ -308,6 +308,8 @@ void TestLength(const char *length_spec) {
|
||||
EXPECT_STD_PRINTF(format, T, max);
|
||||
EXPECT_STD_PRINTF(format, T, fmt::LongLong(min) - 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>::max());
|
||||
EXPECT_STD_PRINTF(format, T, std::numeric_limits<unsigned>::min());
|
||||
@ -320,12 +322,12 @@ void TestLength(const char *length_spec) {
|
||||
}
|
||||
|
||||
TEST(PrintfTest, Length) {
|
||||
TestLength<short>("h");
|
||||
TestLength<unsigned short>("h");
|
||||
TestLength<signed char>("hh");
|
||||
TestLength<unsigned char>("hh");
|
||||
//TestLength<long>("l");
|
||||
//TestLength<unsigned long>("l");
|
||||
TestLength<short>("h");
|
||||
TestLength<unsigned short>("h");
|
||||
TestLength<long>("l");
|
||||
TestLength<unsigned long>("l");
|
||||
// TODO: more tests
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user