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.
35 #include "base/cprintf.hh"
45 cprintf("%shits%%s + %smisses%%s\n", "test", "test");
46 cprintf("%%s%-10s %c he went home \'\"%d %#o %#x %1.5f %1.2E\n",
47 "hello", 'A', 1, 0xff, 0xfffffffffffffULL
, 3.141592653589, 1.1e10
);
49 cout
<< cformat("%s %#x %s\n") << "hello" << 0 << "foo 0\n";
50 cerr
<< cformat("%s %#x\n") << "hello" << 1 << "foo 1\n";
52 cprintf("another test\n");
55 ccprintf(buffer
, "%-10s %c he home \'\"%d %#o %#x %1.5f %1.2E\n",
56 "hello", 'A', 1, 0xff, 0xfffffffffffffULL
, 3.14159265, 1.1e10
);
58 double f
= 314159.26535897932384;
60 #define ctest(x, y) printf(x, y); cprintf(x, y); cprintf("\n");
68 ctest("%1000.8f\n", f
);
91 f
= 0.00000026535897932384;
109 ctest("%1.10f\n", f
);
110 ctest("%1.11f\n", f
);
111 ctest("%1.12f\n", f
);
112 ctest("%1.13f\n", f
);
113 ctest("%1.14f\n", f
);
114 ctest("%1.15f\n", f
);
115 ctest("%1.16f\n", f
);
116 ctest("%1.17f\n", f
);
117 ctest("%1.18f\n", f
);
119 f
= 0.00000026535897932384;
126 ctest("%12.8e\n", f
);
137 ctest("%1.10e\n", f
);
138 ctest("%1.11e\n", f
);
139 ctest("%1.12e\n", f
);
140 ctest("%1.13e\n", f
);
141 ctest("%1.14e\n", f
);
142 ctest("%1.15e\n", f
);
143 ctest("%1.16e\n", f
);
144 ctest("%1.17e\n", f
);
145 ctest("%1.18e\n", f
);
147 cout
<< buffer
.str();
153 string foo1
= "string test";
154 cprintf("%s\n", foo1
);
157 foo2
<< "stringstream test";
158 cprintf("%s\n", foo2
);
160 cprintf("%c %c\n", 'c', 65);