2 * Copyright (c) 2003 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "base/cprintf.hh"
41 ArgList::dump(const string
&format
)
43 const char *p
= format
.c_str();
46 stream
->flags((ios::fmtflags
)0);
59 bool end_number
= false;
60 bool have_precision
= false;
65 if (*p
>= '0' && *p
<= '9') {
68 } else if (number
> 0)
73 fmt
.format
= Format::string
;
78 fmt
.format
= Format::character
;
86 fmt
.format
= Format::integer
;
87 fmt
.base
= Format::hex
;
88 fmt
.alternate_form
= true;
95 fmt
.base
= Format::hex
;
96 fmt
.format
= Format::integer
;
101 fmt
.base
= Format::oct
;
102 fmt
.format
= Format::integer
;
109 fmt
.format
= Format::integer
;
114 fmt
.uppercase
= true;
116 fmt
.format
= Format::floating
;
117 fmt
.float_format
= Format::best
;
122 fmt
.uppercase
= true;
124 fmt
.format
= Format::floating
;
125 fmt
.float_format
= Format::scientific
;
130 fmt
.format
= Format::floating
;
131 fmt
.float_format
= Format::fixed
;
136 *stream
<< "we don't do %n!!!\n";
141 fmt
.alternate_form
= true;
145 fmt
.flush_left
= true;
149 fmt
.print_sign
= true;
153 fmt
.blank_space
= true;
159 have_precision
= true;
166 fmt
.fill_zero
= true;
178 number
= number
* 10 + (*p
- '0');
182 assert("we shouldn't get here");
192 fmt
.precision
= number
;
201 if (!objects
.empty())
203 Base
*data
= objects
.front();
206 ios::fmtflags saved_flags
= stream
->flags();
207 char old_fill
= stream
->fill();
208 int old_precision
= stream
->precision();
210 data
->process(*stream
, fmt
);
212 stream
->flags(saved_flags
);
213 stream
->fill(old_fill
);
214 stream
->precision(old_precision
);
218 *stream
<< "<missing arg for format>";
236 size_t len
= strcspn(p
, "%\n\r\0");
237 stream
->write(p
, len
);
244 while (!objects
.empty()) {
245 *stream
<< "<extra arg>";
246 Base
*data
= objects
.front();
253 ArgList::dumpToString(const string
&format
)