@@ -425,12 +425,17 @@ class BasicArgFormatter : public ArgVisitor<Impl, void> {
425425 BasicWriter<Char> &writer () { return writer_; }
426426 FormatSpec &spec () { return spec_; }
427427
428- void write_bool (bool value) {
428+ void write (bool value) {
429429 const char *str_value = value ? " true" : " false" ;
430430 Arg::StringValue<char > str = { str_value, strlen (str_value) };
431431 writer_.write_str (str, spec_);
432432 }
433433
434+ void write (const char *value) {
435+ Arg::StringValue<char > str = {value, 0 };
436+ writer_.write_str (str, spec_);
437+ }
438+
434439 public:
435440 BasicArgFormatter (BasicWriter<Char> &w, FormatSpec &s)
436441 : writer_(w), spec_(s) {}
@@ -444,7 +449,7 @@ class BasicArgFormatter : public ArgVisitor<Impl, void> {
444449 void visit_bool (bool value) {
445450 if (spec_.type_ )
446451 return visit_any_int (value);
447- write_bool (value);
452+ write (value);
448453 }
449454
450455 void visit_char (int value) {
@@ -479,8 +484,7 @@ class BasicArgFormatter : public ArgVisitor<Impl, void> {
479484 void visit_cstring (const char *value) {
480485 if (spec_.type_ == ' p' )
481486 return write_pointer (value);
482- Arg::StringValue<char > str = {value, 0 };
483- writer_.write_str (str, spec_);
487+ write (value);
484488 }
485489
486490 void visit_string (Arg::StringValue<char > value) {
@@ -522,9 +526,12 @@ class PrintfArgFormatter :
522526 public BasicArgFormatter<PrintfArgFormatter<Char>, Char> {
523527
524528 void write_null_pointer () {
525- this ->writer () << " (nil)" ;
529+ this ->spec ().type_ = 0 ;
530+ this ->write (" (nil)" );
526531 }
527532
533+ typedef BasicArgFormatter<PrintfArgFormatter<Char>, Char> Base;
534+
528535 public:
529536 PrintfArgFormatter (BasicWriter<Char> &w, FormatSpec &s)
530537 : BasicArgFormatter<PrintfArgFormatter<Char>, Char>(w, s) {}
@@ -534,7 +541,7 @@ class PrintfArgFormatter :
534541 if (fmt_spec.type_ != ' s' )
535542 return this ->visit_any_int (value);
536543 fmt_spec.type_ = 0 ;
537- this ->write_bool (value);
544+ this ->write (value);
538545 }
539546
540547 void visit_char (int value) {
@@ -561,18 +568,18 @@ class PrintfArgFormatter :
561568
562569 void visit_cstring (const char *value) {
563570 if (value)
564- BasicArgFormatter<PrintfArgFormatter<Char>, Char> ::visit_cstring (value);
571+ Base ::visit_cstring (value);
565572 else if (this ->spec ().type_ == ' p' )
566573 write_null_pointer ();
567574 else
568- this ->writer () << " (null)" ;
575+ this ->write ( " (null)" ) ;
569576 }
570577
571578 void visit_pointer (const void *value) {
572579 if (value)
573- BasicArgFormatter<PrintfArgFormatter<Char>, Char> ::visit_pointer (value);
574- else
575- write_null_pointer ();
580+ return Base ::visit_pointer (value);
581+ this -> spec (). type_ = 0 ;
582+ write_null_pointer ();
576583 }
577584
578585 void visit_custom (Arg::CustomValue c) {
0 commit comments