23 template <
bool IsSigned>
27 unsigned max = std::numeric_limits<int>::max();
37 return value >= std::numeric_limits<int>::min() &&
38 value <= std::numeric_limits<int>::max();
53 return static_cast<int>(value);
64 template <
typename T,
typename U>
78 template <
typename T =
void>
88 : arg_(arg), type_(type) {}
97 bool is_signed = type_ ==
'd' || type_ ==
'i';
101 if (
sizeof(TargetType) <=
sizeof(
int)) {
105 arg_.
int_value =
static_cast<int>(
static_cast<TargetType
>(value));
109 arg_.
uint_value =
static_cast<unsigned>(
static_cast<Unsigned
>(value));
137 template <
typename T>
140 arg_.
int_value =
static_cast<char>(value);
159 template <
typename T>
162 UnsignedType width =
static_cast<UnsignedType
>(value);
167 unsigned int_max = std::numeric_limits<int>::max();
170 return static_cast<unsigned>(width);
174 template <
typename Impl,
typename Char>
178 this->spec().type_ = 0;
179 this->
write(
"(nil)");
190 if (fmt_spec.
type_ !=
's')
191 return this->visit_any_int(value);
202 CharPtr out = CharPtr();
203 if (fmt_spec.
width_ > 1) {
207 std::fill_n(out, fmt_spec.
width_ - 1, fill);
208 out += fmt_spec.
width_ - 1;
210 std::fill_n(out + 1, fmt_spec.
width_ - 1, fill);
215 *out =
static_cast<Char
>(value);
220 Base::visit_cstring(value);
221 else if (this->spec().type_ ==
'p')
222 write_null_pointer();
224 this->
write(
"(null)");
229 return Base::visit_pointer(value);
230 this->spec().type_ = 0;
231 write_null_pointer();
236 const Char format_str[] = {
'}', 0};
237 const Char *
format = format_str;
243 template <
typename Char>
253 template <
typename Char,
typename ArgFormatter = Pr
intfArgFormatter<Char> >
256 void parse_flags(
FormatSpec &spec,
const Char *&s);
260 Arg get_arg(
const Char *s,
261 unsigned arg_index = (std::numeric_limits<unsigned>::max)());
264 unsigned parse_header(
const Char *&s,
FormatSpec &spec);
272 template <
typename Char,
typename AF>
298 template <
typename Char,
typename AF>
301 const char *error = 0;
302 Arg arg = arg_index == std::numeric_limits<unsigned>::max() ?
309 template <
typename Char,
typename AF>
312 unsigned arg_index = std::numeric_limits<unsigned>::max();
314 if (c >=
'0' && c <=
'9') {
332 parse_flags(spec, s);
334 if (*s >=
'0' && *s <=
'9') {
336 }
else if (*s ==
'*') {
343 template <
typename Char,
typename AF>
346 const Char *start = format_str.
c_str();
347 const Char *s = start;
350 if (c !=
'%')
continue;
352 write(writer, start, s);
356 write(writer, start, s - 1);
362 unsigned arg_index = parse_header(s, spec);
367 if (
'0' <= *s && *s <=
'9') {
369 }
else if (*s ==
'*') {
375 Arg arg = get_arg(s, arg_index);
378 if (spec.
fill_ ==
'0') {
420 spec.
type_ =
static_cast<char>(*s++);
423 switch (spec.
type_) {
437 AF(writer, spec).visit(arg);
439 write(writer, start, s);
443 template <
typename Char>
493 return fprintf(stdout, format, args);
498 #endif // FMT_PRINTF_H_
void visit_any_int(U value)
CharConverter(internal::Arg &arg)
bool is_negative(T value)
void visit_any_int(T value)
std::string format(CStringRef format_str, ArgList args)
void report_unhandled_arg()
const Char * c_str() const
void write(const mValue &value, std::ostream &os, unsigned int options=0)
void report_unhandled_arg()
std::basic_string< Char > str() const
unsigned parse_nonnegative_int(const Char *&s)
static bool fits_in_int(int)
void visit_bool(bool value)
CharPtr grow_buffer(std::size_t n)
unsigned visit_any_int(T value)
std::string sprintf(CStringRef format, ArgList args)
WidthHandler(FormatSpec &spec)
FMT_FUNC int fprintf(std::ostream &os, CStringRef format, ArgList args)
void write_int(T value, Spec spec)
internal::CharTraits< Char >::CharPtr CharPtr
static bool fits_in_int(bool)
ArgConverter(internal::Arg &arg, wchar_t type)
int visit_any_int(T value)
internal::NamedArg< char > arg(StringRef name, const T &arg)
ULongLong ulong_long_value
static bool fits_in_int(T value)
bool visit_any_int(T value)
static bool fits_in_int(T value)
FMT_GCC_EXTENSION typedef long long LongLong
Result visit(const Arg &arg)
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)