2 * Copyright (c) 2002-2004 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"
42 while (!objects
.empty()) {
43 delete objects
.front();
49 ArgList::dump(const string
&format
)
51 list_t::iterator iter
= objects
.begin();
52 list_t::iterator end
= objects
.end();
54 const char *p
= format
.c_str();
57 stream
->flags((ios::fmtflags
)0);
70 bool end_number
= false;
71 bool have_precision
= false;
76 if (*p
>= '0' && *p
<= '9') {
79 } else if (number
> 0)
84 fmt
.format
= Format::string
;
89 fmt
.format
= Format::character
;
97 fmt
.format
= Format::integer
;
98 fmt
.base
= Format::hex
;
99 fmt
.alternate_form
= true;
104 fmt
.uppercase
= true;
106 fmt
.base
= Format::hex
;
107 fmt
.format
= Format::integer
;
112 fmt
.base
= Format::oct
;
113 fmt
.format
= Format::integer
;
120 fmt
.format
= Format::integer
;
125 fmt
.uppercase
= true;
127 fmt
.format
= Format::floating
;
128 fmt
.float_format
= Format::best
;
133 fmt
.uppercase
= true;
135 fmt
.format
= Format::floating
;
136 fmt
.float_format
= Format::scientific
;
141 fmt
.format
= Format::floating
;
142 fmt
.float_format
= Format::fixed
;
147 *stream
<< "we don't do %n!!!\n";
152 fmt
.alternate_form
= true;
156 fmt
.flush_left
= true;
160 fmt
.print_sign
= true;
164 fmt
.blank_space
= true;
170 have_precision
= true;
177 fmt
.fill_zero
= true;
189 number
= number
* 10 + (*p
- '0');
193 assert("we shouldn't get here");
203 fmt
.precision
= number
;
214 ios::fmtflags saved_flags
= stream
->flags();
215 char old_fill
= stream
->fill();
216 int old_precision
= stream
->precision();
218 (*iter
)->process(*stream
, fmt
);
220 stream
->flags(saved_flags
);
221 stream
->fill(old_fill
);
222 stream
->precision(old_precision
);
226 *stream
<< "<missing arg for format>";
244 size_t len
= strcspn(p
, "%\n\r\0");
245 stream
->write(p
, len
);
252 while (iter
!= end
) {
253 *stream
<< "<extra arg>";
259 ArgList::dumpToString(const string
&format
)