mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-02 11:28:20 +00:00
Fix formatting of signed ints in test.
This commit is contained in:
parent
6cd1563eac
commit
566061d1f1
@ -282,12 +282,27 @@ bool IsSupported(const std::string &format) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct MakeSigned { typedef T Type; };
|
||||||
|
|
||||||
|
#define SPECIALIZE_MAKE_SIGNED(T, S) \
|
||||||
|
template <> \
|
||||||
|
struct MakeSigned<T> { typedef S Type; }
|
||||||
|
|
||||||
|
SPECIALIZE_MAKE_SIGNED(char, signed char);
|
||||||
|
SPECIALIZE_MAKE_SIGNED(unsigned char, signed char);
|
||||||
|
SPECIALIZE_MAKE_SIGNED(unsigned short, short);
|
||||||
|
SPECIALIZE_MAKE_SIGNED(unsigned, int);
|
||||||
|
SPECIALIZE_MAKE_SIGNED(unsigned long, long);
|
||||||
|
SPECIALIZE_MAKE_SIGNED(fmt::ULongLong, fmt::LongLong);
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
std::string sprintf_int(std::string format, U value) {
|
std::string sprintf_int(std::string format, U value) {
|
||||||
char buffer[BUFFER_SIZE];
|
char buffer[BUFFER_SIZE];
|
||||||
char type = format[format.size() - 1];
|
char type = format[format.size() - 1];
|
||||||
if (type == 'd' || type == 'i') {
|
if (type == 'd' || type == 'i') {
|
||||||
safe_sprintf(buffer, format.c_str(), static_cast<T>(value));
|
typedef typename MakeSigned<T>::Type Signed;
|
||||||
|
safe_sprintf(buffer, format.c_str(), static_cast<Signed>(value));
|
||||||
} else {
|
} else {
|
||||||
typedef typename fmt::internal::MakeUnsigned<T>::Type Unsigned;
|
typedef typename fmt::internal::MakeUnsigned<T>::Type Unsigned;
|
||||||
safe_sprintf(buffer, format.c_str(), static_cast<Unsigned>(value));
|
safe_sprintf(buffer, format.c_str(), static_cast<Unsigned>(value));
|
||||||
|
Loading…
Reference in New Issue
Block a user