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);
60 format_invalid(*stream
);
62 Base
*data
= objects
.front();
66 bool end_number
= false;
67 bool have_precision
= false;
72 if (*p
>= '0' && *p
<= '9') {
75 } else if (number
> 0)
80 fmt
.format
= Format::string
;
85 fmt
.format
= Format::character
;
93 fmt
.format
= Format::integer
;
94 fmt
.base
= Format::hex
;
95 fmt
.alternate_form
= true;
100 fmt
.uppercase
= true;
102 fmt
.base
= Format::hex
;
103 fmt
.format
= Format::integer
;
108 fmt
.base
= Format::oct
;
109 fmt
.format
= Format::integer
;
116 fmt
.format
= Format::integer
;
121 fmt
.uppercase
= true;
123 fmt
.format
= Format::floating
;
124 fmt
.float_format
= Format::best
;
129 fmt
.uppercase
= true;
131 fmt
.format
= Format::floating
;
132 fmt
.float_format
= Format::scientific
;
137 fmt
.format
= Format::floating
;
138 fmt
.float_format
= Format::fixed
;
143 *stream
<< "we don't do %n!!!\n";
148 fmt
.alternate_form
= true;
152 fmt
.flush_left
= true;
156 fmt
.print_sign
= true;
160 fmt
.blank_space
= true;
166 have_precision
= true;
173 fmt
.fill_zero
= true;
185 number
= number
* 10 + (*p
- '0');
189 assert("we shouldn't get here");
199 fmt
.precision
= number
;
208 ios::fmtflags saved_flags
= stream
->flags();
209 char old_fill
= stream
->fill();
210 int old_precision
= stream
->precision();
212 data
->process(*stream
, fmt
);
214 stream
->flags(saved_flags
);
215 stream
->fill(old_fill
);
216 stream
->precision(old_precision
);
235 size_t len
= strcspn(p
, "%\n\r\0");
236 stream
->write(p
, len
);
243 while (!objects
.empty()) {
244 Base
*data
= objects
.front();
245 data
->process(*stream
, fmt
);
252 ArgList::dumpToString(const string
&format
)