2
3
4
5
6
7
8
23template <
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();
51 if (!
IntChecker<
std::numeric_limits<T>::is_signed>::fits_in_int(value))
53 return static_cast<
int>(value);
82template <
typename T,
typename U>
96template <
typename T =
void>
110 visit_any_int(value);
115 visit_any_int(value);
118 template <
typename U>
120 bool is_signed =
type_ ==
'd' ||
type_ ==
'i';
122 is_signed =
std::numeric_limits<U>::is_signed;
126 typedef typename internal::Conditional<
127 is_same<T,
void>::value, U, T>::type TargetType;
128 if (const_check(
sizeof(TargetType) <=
sizeof(
int))) {
131 arg_.type = Arg::INT;
132 arg_.int_value =
static_cast<
int>(
static_cast<TargetType>(value));
134 arg_.type = Arg::UINT;
135 typedef typename internal::MakeUnsigned<TargetType>::Type Unsigned;
136 arg_.uint_value =
static_cast<
unsigned>(
static_cast<Unsigned>(value));
140 arg_.type = Arg::LONG_LONG;
144 arg_.long_long_value =
static_cast<LongLong>(value);
146 arg_.type = Arg::ULONG_LONG;
147 arg_.ulong_long_value =
148 static_cast<
typename internal::MakeUnsigned<U>::Type>(value);
164 template <
typename T>
167 arg_.int_value =
static_cast<
char>(value);
186 template <
typename T>
188 typedef typename internal::IntTraits<T>::MainType UnsignedType;
189 UnsignedType width =
static_cast<UnsignedType>(value);
194 unsigned int_max =
std::numeric_limits<
int>::max();
197 return static_cast<
unsigned>(width);
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219template <
typename Impl,
typename Char,
typename Spec>
220class BasicPrintfArgFormatter :
221 public internal::ArgFormatterBase<Impl, Char, Spec> {
224 this->spec().type_ = 0;
225 this->write(
"(nil)");
232
233
234
235
236
237
239 :
internal::ArgFormatterBase<Impl, Char, Spec>(w, s) {}
243 Spec &fmt_spec =
this->spec();
244 if (fmt_spec.type_ !=
's')
245 return this->visit_any_int(value);
252 const Spec &fmt_spec =
this->spec();
253 BasicWriter<Char> &w =
this->writer();
254 if (fmt_spec.type_ && fmt_spec.type_ !=
'c')
255 w.write_int(value, fmt_spec);
256 typedef typename BasicWriter<Char>::CharPtr CharPtr;
257 CharPtr out = CharPtr();
258 if (fmt_spec.width_ > 1) {
260 out = w.grow_buffer(fmt_spec.width_);
262 std::fill_n(out, fmt_spec.width_ - 1, fill);
263 out += fmt_spec.width_ - 1;
265 std::fill_n(out + 1, fmt_spec.width_ - 1, fill);
268 out = w.grow_buffer(1);
270 *out =
static_cast<Char>(value);
276 Base::visit_cstring(value);
277 else if (
this->spec().type_ ==
'p')
280 this->write(
"(null)");
286 return Base::visit_pointer(value);
287 this->spec().type_ = 0;
293 BasicFormatter<Char> formatter(ArgList(),
this->writer());
294 const Char format_str[] = {
'}', 0};
295 const Char *format = format_str;
296 c.format(&formatter, c.value, &format);
301template <
typename Char>
322 unsigned arg_index = (
std::numeric_limits<
unsigned>::max)());
329
330
331
332
333
334
339 void format(BasicCStringRef<Char> format_str);
342template <
typename Char,
typename AF>
368template <
typename Char,
typename AF>
370 unsigned arg_index) {
373 internal::Arg arg = arg_index ==
std::numeric_limits<
unsigned>::max() ?
380template <
typename Char,
typename AF>
383 unsigned arg_index =
std::numeric_limits<
unsigned>::max();
385 if (c >=
'0' && c <=
'9') {
388 unsigned value =
internal::parse_nonnegative_int(s);
405 if (*s >=
'0' && *s <=
'9') {
407 }
else if (*s ==
'*') {
414template <
typename Char,
typename AF>
416 const Char *start = format_str.c_str();
417 const Char *s = start;
420 if (c !=
'%')
continue;
437 if (
'0' <= *s && *s <=
'9') {
439 }
else if (*s ==
'*') {
452 if (arg.type <= Arg::LAST_NUMERIC_TYPE)
494 spec
.type_ =
static_cast<
char>(*s++);
501 if (arg.type <= Arg::LAST_INTEGER_TYPE) {
522inline void printf(Writer &w, CStringRef format, ArgList args) {
527inline void printf(WWriter &w, WCStringRef format, ArgList args) {
533
534
535
536
537
538
539
540
548inline std::wstring
sprintf(WCStringRef format, ArgList args) {
556
557
558
559
560
561
562
563
568
569
570
571
572
573
574
575
576inline int printf(CStringRef format, ArgList args) {
582
583
584
585
586
587
588
589
590inline int fprintf(
std::ostream &os, CStringRef format_str, ArgList args) {
594 return static_cast<
int>(w.size());
599#ifdef FMT_HEADER_ONLY
void visit_any_int(U value)
ArgConverter(internal::Arg &arg, wchar_t type)
void visit_bool(bool value)
void visit_char(int value)
CharConverter(internal::Arg &arg)
void visit_any_int(T value)
char visit_unhandled_arg()
char visit_pointer(const void *)
bool visit_any_int(T value)
void report_unhandled_arg()
int visit_any_int(T value)
unsigned visit_any_int(T value)
void report_unhandled_arg()
WidthHandler(FormatSpec &spec)
FMT_FUNC void write(std::ostream &os, Writer &w)
FMT_FUNC int fprintf(std::FILE *f, CStringRef format, ArgList args)
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
void printf(WWriter &w, WCStringRef format, ArgList args)
std::wstring sprintf(WCStringRef format, ArgList args)
std::string sprintf(CStringRef format, ArgList args)
void printf(Writer &w, CStringRef format, ArgList args)
int printf(CStringRef format, ArgList args)
int fprintf(std::ostream &os, CStringRef format_str, ArgList args)
static bool fits_in_int(int)
static bool fits_in_int(T value)
static bool fits_in_int(T value)
static bool fits_in_int(bool)