fixed formatting
This commit is contained in:
parent
49e6c114ef
commit
8cc8ca1548
56
fmt/printf.h
56
fmt/printf.h
@ -49,8 +49,7 @@ class PrecisionHandler : public ArgVisitor<PrecisionHandler, int> {
|
||||
|
||||
template <typename T>
|
||||
int visit_any_int(T value) {
|
||||
if (!IntChecker<std::numeric_limits<T>::is_signed>::fits_in_int(
|
||||
value))
|
||||
if (!IntChecker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
|
||||
FMT_THROW(FormatError("number is too big"));
|
||||
return static_cast<int>(value);
|
||||
}
|
||||
@ -110,8 +109,7 @@ class ArgConverter : public ArgVisitor<ArgConverter<T>, void> {
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(ArgConverter);
|
||||
|
||||
public:
|
||||
ArgConverter(internal::Arg &arg, wchar_t type)
|
||||
: arg_(arg), type_(type) {}
|
||||
ArgConverter(internal::Arg &arg, wchar_t type) : arg_(arg), type_(type) {}
|
||||
|
||||
void visit_bool(bool value) {
|
||||
if (type_ != 's') visit_any_int(value);
|
||||
@ -129,20 +127,17 @@ class ArgConverter : public ArgVisitor<ArgConverter<T>, void> {
|
||||
}
|
||||
|
||||
using internal::Arg;
|
||||
typedef typename internal::Conditional<is_same<T, void>::value,
|
||||
U, T>::type TargetType;
|
||||
typedef typename internal::Conditional<is_same<T, void>::value, U, T>::type
|
||||
TargetType;
|
||||
if (sizeof(TargetType) <= sizeof(int)) {
|
||||
// Extra casts are used to silence warnings.
|
||||
if (is_signed) {
|
||||
arg_.type = Arg::INT;
|
||||
arg_.int_value = static_cast<int>(
|
||||
static_cast<TargetType>(value));
|
||||
arg_.int_value = static_cast<int>(static_cast<TargetType>(value));
|
||||
} else {
|
||||
arg_.type = Arg::UINT;
|
||||
typedef typename internal::MakeUnsigned<
|
||||
TargetType>::Type Unsigned;
|
||||
arg_.uint_value = static_cast<unsigned>(
|
||||
static_cast<Unsigned>(value));
|
||||
typedef typename internal::MakeUnsigned<TargetType>::Type Unsigned;
|
||||
arg_.uint_value = static_cast<unsigned>(static_cast<Unsigned>(value));
|
||||
}
|
||||
} else {
|
||||
if (is_signed) {
|
||||
@ -153,13 +148,11 @@ class ArgConverter : public ArgVisitor<ArgConverter<T>, void> {
|
||||
// "4294967254"
|
||||
// but we don't have to do the same because it's
|
||||
// a UB.
|
||||
arg_.long_long_value =
|
||||
static_cast<LongLong>(value);
|
||||
arg_.long_long_value = static_cast<LongLong>(value);
|
||||
} else {
|
||||
arg_.type = Arg::ULONG_LONG;
|
||||
arg_.ulong_long_value = static_cast<
|
||||
typename internal::MakeUnsigned<U>::Type>(
|
||||
value);
|
||||
arg_.ulong_long_value =
|
||||
static_cast<typename internal::MakeUnsigned<U>::Type>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -206,8 +199,7 @@ class WidthHandler : public ArgVisitor<WidthHandler, unsigned> {
|
||||
width = 0 - width;
|
||||
}
|
||||
unsigned int_max = std::numeric_limits<int>::max();
|
||||
if (width > int_max)
|
||||
FMT_THROW(FormatError("number is too big"));
|
||||
if (width > int_max) FMT_THROW(FormatError("number is too big"));
|
||||
return static_cast<unsigned>(width);
|
||||
}
|
||||
};
|
||||
@ -265,8 +257,7 @@ class BasicPrintfArgFormatter
|
||||
void visit_char(int value) {
|
||||
const Spec &fmt_spec = this->spec();
|
||||
BasicWriter<Char> &w = this->writer();
|
||||
if (fmt_spec.type_ && fmt_spec.type_ != 'c')
|
||||
w.write_int(value, fmt_spec);
|
||||
if (fmt_spec.type_ && fmt_spec.type_ != 'c') w.write_int(value, fmt_spec);
|
||||
typedef typename BasicWriter<Char>::CharPtr CharPtr;
|
||||
CharPtr out = CharPtr();
|
||||
if (fmt_spec.width_ > 1) {
|
||||
@ -318,8 +309,8 @@ class PrintfArgFormatter
|
||||
public:
|
||||
/** Constructs an argument formatter object. */
|
||||
PrintfArgFormatter(BasicWriter<Char> &w, FormatSpec &s)
|
||||
: BasicPrintfArgFormatter<PrintfArgFormatter<Char>, Char,
|
||||
FormatSpec>(w, s) {}
|
||||
: BasicPrintfArgFormatter<PrintfArgFormatter<Char>, Char, FormatSpec>(
|
||||
w, s) {}
|
||||
};
|
||||
|
||||
/** This template formats data and writes the output to a writer. */
|
||||
@ -390,8 +381,7 @@ internal::Arg PrintfFormatter<Char, AF>::get_arg(const Char *s,
|
||||
internal::Arg arg = arg_index == std::numeric_limits<unsigned>::max()
|
||||
? next_arg(error)
|
||||
: FormatterBase::get_arg(arg_index - 1, error);
|
||||
if (error)
|
||||
FMT_THROW(FormatError(!*s ? "invalid format string" : error));
|
||||
if (error) FMT_THROW(FormatError(!*s ? "invalid format string" : error));
|
||||
return arg;
|
||||
}
|
||||
|
||||
@ -454,13 +444,10 @@ void PrintfFormatter<Char, AF>::format(BasicCStringRef<Char> format_str) {
|
||||
if (*s == '.') {
|
||||
++s;
|
||||
if ('0' <= *s && *s <= '9') {
|
||||
spec.precision_ = static_cast<int>(
|
||||
internal::parse_nonnegative_int(s));
|
||||
spec.precision_ = static_cast<int>(internal::parse_nonnegative_int(s));
|
||||
} else if (*s == '*') {
|
||||
++s;
|
||||
spec.precision_ =
|
||||
internal::PrecisionHandler().visit(
|
||||
get_arg(s));
|
||||
spec.precision_ = internal::PrecisionHandler().visit(get_arg(s));
|
||||
} else {
|
||||
spec.precision_ = 0;
|
||||
}
|
||||
@ -483,15 +470,13 @@ void PrintfFormatter<Char, AF>::format(BasicCStringRef<Char> format_str) {
|
||||
switch (*s++) {
|
||||
case 'h':
|
||||
if (*s == 'h')
|
||||
ArgConverter<signed char>(arg, *++s)
|
||||
.visit(arg);
|
||||
ArgConverter<signed char>(arg, *++s).visit(arg);
|
||||
else
|
||||
ArgConverter<short>(arg, *s).visit(arg);
|
||||
break;
|
||||
case 'l':
|
||||
if (*s == 'l')
|
||||
ArgConverter<fmt::LongLong>(arg, *++s)
|
||||
.visit(arg);
|
||||
ArgConverter<fmt::LongLong>(arg, *++s).visit(arg);
|
||||
else
|
||||
ArgConverter<long>(arg, *s).visit(arg);
|
||||
break;
|
||||
@ -502,8 +487,7 @@ void PrintfFormatter<Char, AF>::format(BasicCStringRef<Char> format_str) {
|
||||
ArgConverter<std::size_t>(arg, *s).visit(arg);
|
||||
break;
|
||||
case 't':
|
||||
ArgConverter<std::ptrdiff_t>(arg, *s).visit(
|
||||
arg);
|
||||
ArgConverter<std::ptrdiff_t>(arg, *s).visit(arg);
|
||||
break;
|
||||
case 'L':
|
||||
// printf produces garbage when 'L' is omitted
|
||||
|
||||
Loading…
Reference in New Issue
Block a user