cprintf_formats.hh (3857:2d724684bef3) cprintf_formats.hh (3940:b87f85bb4275)
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 70 unchanged lines hidden (view full) ---

79template <typename T>
80inline void
81_format_integer(std::ostream &out, const T &data, Format &fmt)
82{
83 using namespace std;
84
85 switch (fmt.base) {
86 case Format::hex:
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 70 unchanged lines hidden (view full) ---

79template <typename T>
80inline void
81_format_integer(std::ostream &out, const T &data, Format &fmt)
82{
83 using namespace std;
84
85 switch (fmt.base) {
86 case Format::hex:
87 out.setf(ios::hex, ios::basefield);
87 out.setf(std::ios::hex, std::ios::basefield);
88 break;
89
90 case Format::oct:
88 break;
89
90 case Format::oct:
91 out.setf(ios::oct, ios::basefield);
91 out.setf(std::ios::oct, std::ios::basefield);
92 break;
93
94 case Format::dec:
92 break;
93
94 case Format::dec:
95 out.setf(ios::dec, ios::basefield);
95 out.setf(std::ios::dec, std::ios::basefield);
96 break;
97 }
98
99 if (fmt.alternate_form) {
100 if (!fmt.fill_zero)
96 break;
97 }
98
99 if (fmt.alternate_form) {
100 if (!fmt.fill_zero)
101 out.setf(ios::showbase);
101 out.setf(std::ios::showbase);
102 else {
103 switch (fmt.base) {
104 case Format::hex:
105 out << "0x";
106 fmt.width -= 2;
107 break;
108 case Format::oct:
109 out << "0";

--- 7 unchanged lines hidden (view full) ---

117
118 if (fmt.fill_zero)
119 out.fill('0');
120
121 if (fmt.width > 0)
122 out.width(fmt.width);
123
124 if (fmt.flush_left && !fmt.fill_zero)
102 else {
103 switch (fmt.base) {
104 case Format::hex:
105 out << "0x";
106 fmt.width -= 2;
107 break;
108 case Format::oct:
109 out << "0";

--- 7 unchanged lines hidden (view full) ---

117
118 if (fmt.fill_zero)
119 out.fill('0');
120
121 if (fmt.width > 0)
122 out.width(fmt.width);
123
124 if (fmt.flush_left && !fmt.fill_zero)
125 out.setf(ios::left);
125 out.setf(std::ios::left);
126
127 if (fmt.print_sign)
126
127 if (fmt.print_sign)
128 out.setf(ios::showpos);
128 out.setf(std::ios::showpos);
129
130 if (fmt.uppercase)
129
130 if (fmt.uppercase)
131 out.setf(ios::uppercase);
131 out.setf(std::ios::uppercase);
132
133 out << data;
134}
135
136template <typename T>
137inline void
138_format_float(std::ostream &out, const T &data, Format &fmt)
139{
140 using namespace std;
141
142 switch (fmt.float_format) {
143 case Format::scientific:
144 if (fmt.precision != -1) {
145 if (fmt.width > 0)
146 out.width(fmt.width);
147
148 if (fmt.precision == 0)
149 fmt.precision = 1;
150 else
132
133 out << data;
134}
135
136template <typename T>
137inline void
138_format_float(std::ostream &out, const T &data, Format &fmt)
139{
140 using namespace std;
141
142 switch (fmt.float_format) {
143 case Format::scientific:
144 if (fmt.precision != -1) {
145 if (fmt.width > 0)
146 out.width(fmt.width);
147
148 if (fmt.precision == 0)
149 fmt.precision = 1;
150 else
151 out.setf(ios::scientific);
151 out.setf(std::ios::scientific);
152
153 out.precision(fmt.precision);
154 } else
155 if (fmt.width > 0)
156 out.width(fmt.width);
157
158 if (fmt.uppercase)
152
153 out.precision(fmt.precision);
154 } else
155 if (fmt.width > 0)
156 out.width(fmt.width);
157
158 if (fmt.uppercase)
159 out.setf(ios::uppercase);
159 out.setf(std::ios::uppercase);
160 break;
161
162 case Format::fixed:
163 if (fmt.precision != -1) {
164 if (fmt.width > 0)
165 out.width(fmt.width);
166
160 break;
161
162 case Format::fixed:
163 if (fmt.precision != -1) {
164 if (fmt.width > 0)
165 out.width(fmt.width);
166
167 out.setf(ios::fixed);
167 out.setf(std::ios::fixed);
168 out.precision(fmt.precision);
169 } else
170 if (fmt.width > 0)
171 out.width(fmt.width);
172
173 break;
174
175 default:

--- 35 unchanged lines hidden (view full) ---

211 } else
212 out << data;
213 } else
214 out << data;
215#else
216 if (fmt.width > 0)
217 out.width(fmt.width);
218 if (fmt.flush_left)
168 out.precision(fmt.precision);
169 } else
170 if (fmt.width > 0)
171 out.width(fmt.width);
172
173 break;
174
175 default:

--- 35 unchanged lines hidden (view full) ---

211 } else
212 out << data;
213 } else
214 out << data;
215#else
216 if (fmt.width > 0)
217 out.width(fmt.width);
218 if (fmt.flush_left)
219 out.setf(ios::left);
219 out.setf(std::ios::left);
220
221 out << data;
222#endif
223}
224
225/////////////////////////////////////////////////////////////////////////////
226//
227// The code below controls the actual usage of formats for various types

--- 128 unchanged lines hidden ---
220
221 out << data;
222#endif
223}
224
225/////////////////////////////////////////////////////////////////////////////
226//
227// The code below controls the actual usage of formats for various types

--- 128 unchanged lines hidden ---