mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-11 05:30:05 +00:00
Reduce the number of integer types that need to be handled.
This commit is contained in:
parent
5e6f57ada1
commit
5be9a8de3f
26
format.cc
26
format.cc
@ -507,10 +507,6 @@ fmt::ULongLong fmt::BasicWriter<Char>::GetIntValue(const ArgInfo &arg) {
|
||||
return arg.int_value;
|
||||
case UINT:
|
||||
return arg.uint_value;
|
||||
case LONG:
|
||||
return arg.long_value;
|
||||
case ULONG:
|
||||
return arg.ulong_value;
|
||||
case LONG_LONG:
|
||||
return arg.long_long_value;
|
||||
case ULONG_LONG:
|
||||
@ -556,7 +552,7 @@ void fmt::BasicWriter<Char>::FormatParser::CheckSign(
|
||||
report_error_(s,
|
||||
fmt::Format("format specifier '{}' requires numeric argument") << sign);
|
||||
}
|
||||
if (arg.type == UINT || arg.type == ULONG || arg.type == ULONG_LONG) {
|
||||
if (arg.type == UINT || arg.type == ULONG_LONG) {
|
||||
report_error_(s,
|
||||
fmt::Format("format specifier '{}' requires signed argument") << sign);
|
||||
}
|
||||
@ -767,12 +763,6 @@ void fmt::BasicWriter<Char>::PrintfParser::Format(
|
||||
case UINT:
|
||||
writer.FormatInt(arg.uint_value, spec);
|
||||
break;
|
||||
case LONG:
|
||||
writer.FormatInt(arg.long_value, spec);
|
||||
break;
|
||||
case ULONG:
|
||||
writer.FormatInt(arg.ulong_value, spec);
|
||||
break;
|
||||
case LONG_LONG:
|
||||
writer.FormatInt(arg.long_long_value, spec);
|
||||
break;
|
||||
@ -963,14 +953,6 @@ void fmt::BasicWriter<Char>::FormatParser::Format(
|
||||
case UINT:
|
||||
value = precision_arg.uint_value;
|
||||
break;
|
||||
case LONG:
|
||||
if (precision_arg.long_value < 0)
|
||||
report_error_(s, "negative precision in format");
|
||||
value = precision_arg.long_value;
|
||||
break;
|
||||
case ULONG:
|
||||
value = precision_arg.ulong_value;
|
||||
break;
|
||||
case LONG_LONG:
|
||||
if (precision_arg.long_long_value < 0)
|
||||
report_error_(s, "negative precision in format");
|
||||
@ -1014,12 +996,6 @@ void fmt::BasicWriter<Char>::FormatParser::Format(
|
||||
case UINT:
|
||||
writer.FormatInt(arg.uint_value, spec);
|
||||
break;
|
||||
case LONG:
|
||||
writer.FormatInt(arg.long_value, spec);
|
||||
break;
|
||||
case ULONG:
|
||||
writer.FormatInt(arg.ulong_value, spec);
|
||||
break;
|
||||
case LONG_LONG:
|
||||
writer.FormatInt(arg.long_long_value, spec);
|
||||
break;
|
||||
|
31
format.h
31
format.h
@ -891,11 +891,10 @@ class BasicWriter {
|
||||
void operator<<(typename internal::CharTraits<Char>::UnsupportedStrType);
|
||||
|
||||
enum Type {
|
||||
// Numeric types should go first.
|
||||
INT, UINT, LONG, ULONG, LONG_LONG, ULONG_LONG,
|
||||
LAST_INTEGER_TYPE = ULONG_LONG,
|
||||
DOUBLE, LONG_DOUBLE,
|
||||
LAST_NUMERIC_TYPE = LONG_DOUBLE,
|
||||
// Integer types should go first,
|
||||
INT, UINT, LONG_LONG, ULONG_LONG, LAST_INTEGER_TYPE = ULONG_LONG,
|
||||
// followed by floating-point types.
|
||||
DOUBLE, LONG_DOUBLE, LAST_NUMERIC_TYPE = LONG_DOUBLE,
|
||||
CHAR, STRING, WSTRING, POINTER, CUSTOM
|
||||
};
|
||||
|
||||
@ -920,8 +919,6 @@ class BasicWriter {
|
||||
int int_value;
|
||||
unsigned uint_value;
|
||||
double double_value;
|
||||
long long_value;
|
||||
unsigned long ulong_value;
|
||||
LongLong long_long_value;
|
||||
ULongLong ulong_long_value;
|
||||
long double long_double_value;
|
||||
@ -962,8 +959,24 @@ class BasicWriter {
|
||||
BasicArg(unsigned short value) { type = UINT; this->int_value = value; }
|
||||
BasicArg(int value) { type = INT; this->int_value = value; }
|
||||
BasicArg(unsigned value) { type = UINT; this->uint_value = value; }
|
||||
BasicArg(long value) { type = LONG; this->long_value = value; }
|
||||
BasicArg(unsigned long value) { type = ULONG; this->ulong_value = value; }
|
||||
BasicArg(long value) {
|
||||
if (sizeof(long) == sizeof(int)) {
|
||||
type = INT;
|
||||
this->int_value = static_cast<int>(value);
|
||||
} else {
|
||||
type = LONG_LONG;
|
||||
this->long_long_value = value;
|
||||
}
|
||||
}
|
||||
BasicArg(unsigned long value) {
|
||||
if (sizeof(unsigned long) == sizeof(unsigned)) {
|
||||
type = UINT;
|
||||
this->uint_value = static_cast<unsigned>(value);
|
||||
} else {
|
||||
type = ULONG_LONG;
|
||||
this->ulong_long_value = value;
|
||||
}
|
||||
}
|
||||
BasicArg(LongLong value) {
|
||||
type = LONG_LONG;
|
||||
this->long_long_value = value;
|
||||
|
Loading…
Reference in New Issue
Block a user