williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@2
|
3 |
*
|
williamr@2
|
4 |
* Copyright (c) 1999
|
williamr@2
|
5 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
6 |
*
|
williamr@2
|
7 |
* Copyright (c) 1999
|
williamr@2
|
8 |
* Boris Fomitchev
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
11 |
* or implied. Any use is at your own risk.
|
williamr@2
|
12 |
*
|
williamr@2
|
13 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
14 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
15 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
16 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
17 |
* modified is included with the above copyright notice.
|
williamr@2
|
18 |
*
|
williamr@2
|
19 |
*/
|
williamr@2
|
20 |
#ifndef _STLP_NUM_PUT_C
|
williamr@2
|
21 |
#define _STLP_NUM_PUT_C
|
williamr@2
|
22 |
|
williamr@2
|
23 |
#ifndef _STLP_INTERNAL_NUM_PUT_H
|
williamr@2
|
24 |
# include <stl/_num_put.h>
|
williamr@2
|
25 |
#endif
|
williamr@2
|
26 |
|
williamr@2
|
27 |
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
|
williamr@2
|
28 |
|
williamr@2
|
29 |
#ifndef _STLP_LIMITS_H
|
williamr@2
|
30 |
# include <stl/_limits.h>
|
williamr@2
|
31 |
#endif
|
williamr@2
|
32 |
|
williamr@2
|
33 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
34 |
|
williamr@2
|
35 |
// _M_do_put_float and its helper functions. Strategy: write the output
|
williamr@2
|
36 |
// to a buffer of char, transform the buffer to _CharT, and then copy
|
williamr@2
|
37 |
// it to the output.
|
williamr@2
|
38 |
|
williamr@2
|
39 |
template <class _CharT, class _OutputIter,class _Float>
|
williamr@2
|
40 |
_OutputIter _STLP_CALL
|
williamr@2
|
41 |
_M_do_put_float(_OutputIter __s, ios_base& __f, _CharT __fill,_Float __x);
|
williamr@2
|
42 |
|
williamr@2
|
43 |
|
williamr@2
|
44 |
//----------------------------------------------------------------------
|
williamr@2
|
45 |
// num_put facet
|
williamr@2
|
46 |
|
williamr@2
|
47 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
48 |
_OutputIter _STLP_CALL
|
williamr@2
|
49 |
__copy_float_and_fill(const _CharT* __first, const _CharT* __last,
|
williamr@2
|
50 |
_OutputIter __stl_out,
|
williamr@2
|
51 |
ios_base::fmtflags __flags,
|
williamr@2
|
52 |
streamsize __width, _CharT __fill,
|
williamr@2
|
53 |
_CharT __xplus, _CharT __xminus) {
|
williamr@2
|
54 |
if (__width <= __last - __first)
|
williamr@2
|
55 |
return copy(__first, __last, __stl_out);
|
williamr@2
|
56 |
else {
|
williamr@2
|
57 |
streamsize __pad = __width - (__last - __first);
|
williamr@2
|
58 |
ios_base::fmtflags __dir = __flags & ios_base::adjustfield;
|
williamr@2
|
59 |
|
williamr@2
|
60 |
if (__dir == ios_base::left) {
|
williamr@2
|
61 |
__stl_out = copy(__first, __last, __stl_out);
|
williamr@2
|
62 |
return fill_n(__stl_out, __pad, __fill);
|
williamr@2
|
63 |
}
|
williamr@2
|
64 |
else if (__dir == ios_base::internal && __first != __last &&
|
williamr@2
|
65 |
(*__first == __xplus || *__first == __xminus)) {
|
williamr@2
|
66 |
*__stl_out++ = *__first++;
|
williamr@2
|
67 |
__stl_out = fill_n(__stl_out, __pad, __fill);
|
williamr@2
|
68 |
return copy(__first, __last, __stl_out);
|
williamr@2
|
69 |
}
|
williamr@2
|
70 |
else {
|
williamr@2
|
71 |
__stl_out = fill_n(__stl_out, __pad, __fill);
|
williamr@2
|
72 |
return copy(__first, __last, __stl_out);
|
williamr@2
|
73 |
}
|
williamr@2
|
74 |
}
|
williamr@2
|
75 |
}
|
williamr@2
|
76 |
|
williamr@2
|
77 |
#ifndef _STLP_NO_WCHAR_T
|
williamr@2
|
78 |
// Helper routine for wchar_t
|
williamr@2
|
79 |
template <class _OutputIter>
|
williamr@2
|
80 |
_OutputIter _STLP_CALL
|
williamr@2
|
81 |
__put_float(char* __ibuf, char* __iend, _OutputIter __stl_out,
|
williamr@2
|
82 |
ios_base& __f, wchar_t __fill,
|
williamr@2
|
83 |
wchar_t __decimal_point,
|
williamr@2
|
84 |
wchar_t __sep, const string& __grouping)
|
williamr@2
|
85 |
{
|
williamr@2
|
86 |
//const ctype<wchar_t>& __ct = *(ctype<wchar_t>*)__f._M_ctype_facet() ;
|
williamr@2
|
87 |
const ctype<wchar_t>& __ct = use_facet< ctype<wchar_t> >(__f.getloc());
|
williamr@2
|
88 |
|
williamr@2
|
89 |
// wchar_t __wbuf[128]; //stdcxx fix
|
williamr@2
|
90 |
wchar_t __wbuf[256+10];
|
williamr@2
|
91 |
wchar_t* __eend = __convert_float_buffer(__ibuf, __iend, __wbuf,
|
williamr@2
|
92 |
__ct, __decimal_point);
|
williamr@2
|
93 |
if (!__grouping.empty()) {
|
williamr@2
|
94 |
// In order to do separator-insertion only to the left of the
|
williamr@2
|
95 |
// decimal point, we adjust the size of the first (right-most)
|
williamr@2
|
96 |
// group. We need to be careful if there is only one entry in
|
williamr@2
|
97 |
// grouping: in this case we need to duplicate the first entry.
|
williamr@2
|
98 |
|
williamr@2
|
99 |
string __new_grouping = __grouping;
|
williamr@2
|
100 |
wchar_t* __decimal_pos = find(__wbuf, __eend, __decimal_point);
|
williamr@2
|
101 |
if (__grouping.size() == 1)
|
williamr@2
|
102 |
__new_grouping.push_back(__grouping[0]);
|
williamr@2
|
103 |
|
williamr@2
|
104 |
// dwa 1/24/00 - try as I might, there doesn't seem to be a way
|
williamr@2
|
105 |
// to suppress the warning
|
williamr@2
|
106 |
__new_grouping[0] += __STATIC_CAST(char, __eend - __decimal_pos);
|
williamr@2
|
107 |
ptrdiff_t __len = __insert_grouping(__wbuf, __eend, __new_grouping,
|
williamr@2
|
108 |
__sep,
|
williamr@2
|
109 |
__ct.widen('+'), __ct.widen('-'),
|
williamr@2
|
110 |
0);
|
williamr@2
|
111 |
__eend = __wbuf + __len;
|
williamr@2
|
112 |
}
|
williamr@2
|
113 |
|
williamr@2
|
114 |
return __copy_float_and_fill(__wbuf, __eend, __stl_out,
|
williamr@2
|
115 |
__f.flags(), __f.width(0), __fill,
|
williamr@2
|
116 |
__ct.widen('+'), __ct.widen('-'));
|
williamr@2
|
117 |
}
|
williamr@2
|
118 |
# endif /* WCHAR_T */
|
williamr@2
|
119 |
|
williamr@2
|
120 |
#ifdef __SYMBIAN32__
|
williamr@2
|
121 |
template<class _CharT>
|
williamr@2
|
122 |
ptrdiff_t _STLP_CALL
|
williamr@2
|
123 |
__insert_grouping(_CharT * first, _CharT * last, const string& grouping,
|
williamr@2
|
124 |
_CharT separator, _CharT Plus, _CharT Minus, int basechars)
|
williamr@2
|
125 |
{
|
williamr@2
|
126 |
int length = last-first;
|
williamr@2
|
127 |
ptrdiff_t res;
|
williamr@2
|
128 |
char* str = new char(length+64); //morespace for seperators
|
williamr@2
|
129 |
memset(str,'\0',length+64);
|
williamr@2
|
130 |
memcpy(str,first, length);
|
williamr@2
|
131 |
char _separator = (char)separator;
|
williamr@2
|
132 |
char _Plus = (char)Plus;
|
williamr@2
|
133 |
char _Minus = (char)Minus;
|
williamr@2
|
134 |
|
williamr@2
|
135 |
res = __insert_grouping(str, str+length, grouping,
|
williamr@2
|
136 |
_separator, _Plus, _Minus, basechars);
|
williamr@2
|
137 |
memcpy(first,str,res);
|
williamr@2
|
138 |
delete str;
|
williamr@2
|
139 |
return res;
|
williamr@2
|
140 |
|
williamr@2
|
141 |
}
|
williamr@2
|
142 |
|
williamr@2
|
143 |
#endif
|
williamr@2
|
144 |
// Helper routine for char
|
williamr@2
|
145 |
template <class _OutputIter>
|
williamr@2
|
146 |
_OutputIter _STLP_CALL
|
williamr@2
|
147 |
__put_float(char* __ibuf, char* __iend, _OutputIter __stl_out,
|
williamr@2
|
148 |
ios_base& __f, char __fill,
|
williamr@2
|
149 |
char __decimal_point,
|
williamr@2
|
150 |
char __sep, const string& __grouping)
|
williamr@2
|
151 |
{
|
williamr@2
|
152 |
__adjust_float_buffer(__ibuf, __iend, __decimal_point);
|
williamr@2
|
153 |
if (!__grouping.empty()) {
|
williamr@2
|
154 |
string __new_grouping = __grouping;
|
williamr@2
|
155 |
const char * __decimal_pos = find(__ibuf, __iend, __decimal_point);
|
williamr@2
|
156 |
if (__grouping.size() == 1)
|
williamr@2
|
157 |
__new_grouping.push_back(__grouping[0]);
|
williamr@2
|
158 |
__new_grouping[0] += __STATIC_CAST(char, (__iend - __decimal_pos));
|
williamr@2
|
159 |
ptrdiff_t __len = __insert_grouping(__ibuf, __iend, __new_grouping,
|
williamr@2
|
160 |
__sep, '+', '-', 0);
|
williamr@2
|
161 |
__iend = __ibuf + __len;
|
williamr@2
|
162 |
}
|
williamr@2
|
163 |
|
williamr@2
|
164 |
return __copy_float_and_fill(__ibuf, __iend, __stl_out,
|
williamr@2
|
165 |
__f.flags(), __f.width(0), __fill, '+', '-');
|
williamr@2
|
166 |
}
|
williamr@2
|
167 |
|
williamr@2
|
168 |
#ifdef __SYMBIAN32__
|
williamr@2
|
169 |
|
williamr@2
|
170 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
171 |
_OutputIter _STLP_CALL
|
williamr@2
|
172 |
__put_float(char* __ibuf, char* __iend, _OutputIter __stl_out,
|
williamr@2
|
173 |
ios_base& __f, _CharT __fill,
|
williamr@2
|
174 |
_CharT __decimal_point,
|
williamr@2
|
175 |
_CharT __sep, const string& __grouping)
|
williamr@2
|
176 |
{
|
williamr@2
|
177 |
__adjust_float_buffer(__ibuf, __iend, __decimal_point);
|
williamr@2
|
178 |
if (!__grouping.empty()) {
|
williamr@2
|
179 |
string __new_grouping = __grouping;
|
williamr@2
|
180 |
const char * __decimal_pos = find(__ibuf, __iend, __decimal_point);
|
williamr@2
|
181 |
if (__grouping.size() == 1)
|
williamr@2
|
182 |
__new_grouping.push_back(__grouping[0]);
|
williamr@2
|
183 |
__new_grouping[0] += __STATIC_CAST(char, (__iend - __decimal_pos));
|
williamr@2
|
184 |
ptrdiff_t __len = __insert_grouping(__ibuf, __iend, __new_grouping,
|
williamr@2
|
185 |
__sep, '+', '-', 0);
|
williamr@2
|
186 |
__iend = __ibuf + __len;
|
williamr@2
|
187 |
}
|
williamr@2
|
188 |
|
williamr@2
|
189 |
_CharT __wbuf[64];
|
williamr@2
|
190 |
locale __loc = __f.getloc();
|
williamr@2
|
191 |
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
|
williamr@2
|
192 |
__ct.widen(__ibuf, __iend, __wbuf);
|
williamr@2
|
193 |
|
williamr@2
|
194 |
ptrdiff_t __len = __iend - __ibuf;
|
williamr@2
|
195 |
return __copy_float_and_fill(__wbuf, __wbuf+__len, __stl_out,
|
williamr@2
|
196 |
__f.flags(), __f.width(0), __fill, (_CharT)'+', (_CharT)'-');
|
williamr@2
|
197 |
}
|
williamr@2
|
198 |
|
williamr@2
|
199 |
|
williamr@2
|
200 |
#endif
|
williamr@2
|
201 |
template <class _CharT, class _OutputIter, class _Float>
|
williamr@2
|
202 |
_OutputIter _STLP_CALL
|
williamr@2
|
203 |
_M_do_put_float(_OutputIter __s, ios_base& __f,
|
williamr@2
|
204 |
_CharT __fill, _Float __x)
|
williamr@2
|
205 |
{
|
williamr@2
|
206 |
string __buf;
|
williamr@2
|
207 |
__buf.reserve(256+10); //+2 - 10/1/07
|
williamr@2
|
208 |
__write_float(__buf, __f.flags(), (int)__f.precision(), __x);
|
williamr@2
|
209 |
|
williamr@2
|
210 |
//const numpunct<_CharT>& __np = *(const numpunct<_CharT>*)__f._M_numpunct_facet();
|
williamr@2
|
211 |
const numpunct<_CharT>& __np = use_facet< numpunct<_CharT> >(__f.getloc());
|
williamr@2
|
212 |
|
williamr@2
|
213 |
return __put_float(__CONST_CAST(char*, __buf.c_str()),
|
williamr@2
|
214 |
__CONST_CAST(char*, __buf.c_str()) + __buf.size(),
|
williamr@2
|
215 |
__s, __f, __fill,
|
williamr@2
|
216 |
__np.decimal_point(),
|
williamr@2
|
217 |
// __np.thousands_sep(), __f._M_grouping()); //stdcxx fix - 17/1/07
|
williamr@2
|
218 |
__np.thousands_sep(), __np.grouping());
|
williamr@2
|
219 |
}
|
williamr@2
|
220 |
|
williamr@2
|
221 |
// _M_do_put_integer and its helper functions.
|
williamr@2
|
222 |
|
williamr@2
|
223 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
224 |
_OutputIter _STLP_CALL
|
williamr@2
|
225 |
__copy_integer_and_fill(const _CharT* __buf, ptrdiff_t __len,
|
williamr@2
|
226 |
_OutputIter __stl_out,
|
williamr@2
|
227 |
ios_base::fmtflags __flg, streamsize __wid, _CharT __fill,
|
williamr@2
|
228 |
_CharT __xplus, _CharT __xminus)
|
williamr@2
|
229 |
{
|
williamr@2
|
230 |
if (__len >= __wid)
|
williamr@2
|
231 |
return copy(__buf, __buf + __len, __stl_out);
|
williamr@2
|
232 |
else {
|
williamr@2
|
233 |
ptrdiff_t __pad = __wid - __len;
|
williamr@2
|
234 |
ios_base::fmtflags __dir = __flg & ios_base::adjustfield;
|
williamr@2
|
235 |
|
williamr@2
|
236 |
if (__dir == ios_base::left) {
|
williamr@2
|
237 |
__stl_out = copy(__buf, __buf + __len, __stl_out);
|
williamr@2
|
238 |
return fill_n(__stl_out, __pad, __fill);
|
williamr@2
|
239 |
}
|
williamr@2
|
240 |
else if (__dir == ios_base::internal && __len != 0 &&
|
williamr@2
|
241 |
(__buf[0] == __xplus || __buf[0] == __xminus)) {
|
williamr@2
|
242 |
*__stl_out++ = __buf[0];
|
williamr@2
|
243 |
__stl_out = fill_n(__stl_out, __pad, __fill);
|
williamr@2
|
244 |
return copy(__buf + 1, __buf + __len, __stl_out);
|
williamr@2
|
245 |
}
|
williamr@2
|
246 |
else if (__dir == ios_base::internal && __len >= 2 &&
|
williamr@2
|
247 |
(__flg & ios_base::showbase) &&
|
williamr@2
|
248 |
(__flg & ios_base::basefield) == ios_base::hex) {
|
williamr@2
|
249 |
*__stl_out++ = __buf[0];
|
williamr@2
|
250 |
*__stl_out++ = __buf[1];
|
williamr@2
|
251 |
__stl_out = fill_n(__stl_out, __pad, __fill);
|
williamr@2
|
252 |
return copy(__buf + 2, __buf + __len, __stl_out);
|
williamr@2
|
253 |
}
|
williamr@2
|
254 |
else {
|
williamr@2
|
255 |
__stl_out = fill_n(__stl_out, __pad, __fill);
|
williamr@2
|
256 |
return copy(__buf, __buf + __len, __stl_out);
|
williamr@2
|
257 |
}
|
williamr@2
|
258 |
}
|
williamr@2
|
259 |
}
|
williamr@2
|
260 |
|
williamr@2
|
261 |
#ifndef _STLP_NO_WCHAR_T
|
williamr@2
|
262 |
// Helper function for wchar_t
|
williamr@2
|
263 |
template <class _OutputIter>
|
williamr@2
|
264 |
_OutputIter _STLP_CALL
|
williamr@2
|
265 |
__put_integer(char* __buf, char* __iend, _OutputIter __s,
|
williamr@2
|
266 |
ios_base& __f,
|
williamr@2
|
267 |
ios_base::fmtflags __flags, wchar_t __fill)
|
williamr@2
|
268 |
{
|
williamr@2
|
269 |
locale __loc = __f.getloc();
|
williamr@2
|
270 |
const ctype<wchar_t>& __ct = use_facet<ctype<wchar_t> >(__loc);
|
williamr@2
|
271 |
//const ctype<wchar_t>& __ct = *(const ctype<wchar_t>*)__f._M_ctype_facet();
|
williamr@2
|
272 |
|
williamr@2
|
273 |
wchar_t __xplus = __ct.widen('+');
|
williamr@2
|
274 |
wchar_t __xminus = __ct.widen('-');
|
williamr@2
|
275 |
|
williamr@2
|
276 |
wchar_t __wbuf[64];
|
williamr@2
|
277 |
__ct.widen(__buf, __iend, __wbuf);
|
williamr@2
|
278 |
ptrdiff_t __len = __iend - __buf;
|
williamr@2
|
279 |
wchar_t* __eend = __wbuf + __len;
|
williamr@2
|
280 |
|
williamr@2
|
281 |
const numpunct<wchar_t>& __np = use_facet<numpunct<wchar_t> >(__loc);
|
williamr@2
|
282 |
const string& __grouping = __np.grouping();
|
williamr@2
|
283 |
|
williamr@2
|
284 |
//const numpunct<wchar_t>& __np = *(const numpunct<wchar_t>*)__f._M_numpunct_facet();
|
williamr@2
|
285 |
// const string& __grouping = __f._M_grouping();
|
williamr@2
|
286 |
|
williamr@2
|
287 |
if (!__grouping.empty()) {
|
williamr@2
|
288 |
int __basechars;
|
williamr@2
|
289 |
if (__flags & ios_base::showbase)
|
williamr@2
|
290 |
switch (__flags & ios_base::basefield) {
|
williamr@2
|
291 |
case ios_base::hex: __basechars = 2; break;
|
williamr@2
|
292 |
case ios_base::oct: __basechars = 1; break;
|
williamr@2
|
293 |
default: __basechars = 0;
|
williamr@2
|
294 |
}
|
williamr@2
|
295 |
else
|
williamr@2
|
296 |
__basechars = 0;
|
williamr@2
|
297 |
|
williamr@2
|
298 |
__len = __insert_grouping(__wbuf, __eend, __grouping, __np.thousands_sep(),
|
williamr@2
|
299 |
__xplus, __xminus, __basechars);
|
williamr@2
|
300 |
}
|
williamr@2
|
301 |
|
williamr@2
|
302 |
return __copy_integer_and_fill((wchar_t*)__wbuf, __len, __s,
|
williamr@2
|
303 |
__flags, __f.width(0), __fill, __xplus, __xminus);
|
williamr@2
|
304 |
}
|
williamr@2
|
305 |
#endif
|
williamr@2
|
306 |
|
williamr@2
|
307 |
#ifdef __SYMBIAN32__
|
williamr@2
|
308 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
309 |
_OutputIter _STLP_CALL
|
williamr@2
|
310 |
__put_integer(char* __buf, char* __iend, _OutputIter __s,
|
williamr@2
|
311 |
ios_base& __f,
|
williamr@2
|
312 |
ios_base::fmtflags __flags, _CharT __fill)
|
williamr@2
|
313 |
{
|
williamr@2
|
314 |
locale __loc = __f.getloc();
|
williamr@2
|
315 |
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
|
williamr@2
|
316 |
//const ctype<wchar_t>& __ct = *(const ctype<wchar_t>*)__f._M_ctype_facet();
|
williamr@2
|
317 |
|
williamr@2
|
318 |
_CharT __xplus = '+';
|
williamr@2
|
319 |
_CharT __xminus = '-';
|
williamr@2
|
320 |
|
williamr@2
|
321 |
_CharT __wbuf[64];
|
williamr@2
|
322 |
|
williamr@2
|
323 |
ptrdiff_t __len = __iend - __buf;
|
williamr@2
|
324 |
_CharT* __eend = __wbuf + __len;
|
williamr@2
|
325 |
|
williamr@2
|
326 |
|
williamr@2
|
327 |
const numpunct<char>& __np = use_facet<numpunct<char> >(__loc);
|
williamr@2
|
328 |
const string& __grouping = __np.grouping();
|
williamr@2
|
329 |
|
williamr@2
|
330 |
//const numpunct<wchar_t>& __np = *(const numpunct<wchar_t>*)__f._M_numpunct_facet();
|
williamr@2
|
331 |
// const string& __grouping = __f._M_grouping();
|
williamr@2
|
332 |
|
williamr@2
|
333 |
if (!__grouping.empty()) {
|
williamr@2
|
334 |
int __basechars;
|
williamr@2
|
335 |
if (__flags & ios_base::showbase)
|
williamr@2
|
336 |
switch (__flags & ios_base::basefield) {
|
williamr@2
|
337 |
case ios_base::hex: __basechars = 2; break;
|
williamr@2
|
338 |
case ios_base::oct: __basechars = 1; break;
|
williamr@2
|
339 |
default: __basechars = 0;
|
williamr@2
|
340 |
}
|
williamr@2
|
341 |
else
|
williamr@2
|
342 |
__basechars = 0;
|
williamr@2
|
343 |
|
williamr@2
|
344 |
__len = __insert_grouping(__buf, __iend, __grouping, __np.thousands_sep(),
|
williamr@2
|
345 |
__ct.narrow( __xplus, '+'), __ct.narrow(__xminus, '-'), __basechars);
|
williamr@2
|
346 |
__ct.widen(__buf, __iend, __wbuf);
|
williamr@2
|
347 |
|
williamr@2
|
348 |
}
|
williamr@2
|
349 |
|
williamr@2
|
350 |
return __copy_integer_and_fill(__wbuf, __len, __s,
|
williamr@2
|
351 |
__flags, __f.width(0), __fill, __xplus, __xminus);
|
williamr@2
|
352 |
}
|
williamr@2
|
353 |
|
williamr@2
|
354 |
|
williamr@2
|
355 |
#endif
|
williamr@2
|
356 |
// Helper function for char
|
williamr@2
|
357 |
template <class _OutputIter>
|
williamr@2
|
358 |
_OutputIter _STLP_CALL
|
williamr@2
|
359 |
__put_integer(char* __buf, char* __iend, _OutputIter __s,
|
williamr@2
|
360 |
ios_base& __f, ios_base::fmtflags __flags, char __fill)
|
williamr@2
|
361 |
{
|
williamr@2
|
362 |
ptrdiff_t __len = __iend - __buf;
|
williamr@2
|
363 |
char __grpbuf[64];
|
williamr@2
|
364 |
|
williamr@2
|
365 |
// const numpunct<char>& __np = use_facet<numpunct<char> >(__f.getloc());
|
williamr@2
|
366 |
// const string& __grouping = __np.grouping();
|
williamr@2
|
367 |
|
williamr@2
|
368 |
const numpunct<char>& __np = *(const numpunct<char>*)__f._M_numpunct_facet();
|
williamr@2
|
369 |
// const string& __grouping = __f._M_grouping(); //stdcxx fix, 17/1/07
|
williamr@2
|
370 |
const string& __grouping = __np.grouping();
|
williamr@2
|
371 |
|
williamr@2
|
372 |
if (!__grouping.empty()) {
|
williamr@2
|
373 |
int __basechars;
|
williamr@2
|
374 |
if (__flags & ios_base::showbase)
|
williamr@2
|
375 |
switch (__flags & ios_base::basefield) {
|
williamr@2
|
376 |
case ios_base::hex: __basechars = 2; break;
|
williamr@2
|
377 |
case ios_base::oct: __basechars = 1; break;
|
williamr@2
|
378 |
default: __basechars = 0;
|
williamr@2
|
379 |
}
|
williamr@2
|
380 |
else
|
williamr@2
|
381 |
__basechars = 0;
|
williamr@2
|
382 |
|
williamr@2
|
383 |
// make sure there is room at the end of the buffer
|
williamr@2
|
384 |
// we pass to __insert_grouping
|
williamr@2
|
385 |
|
williamr@2
|
386 |
copy(__buf, __iend, (char *) __grpbuf);
|
williamr@2
|
387 |
__buf = __grpbuf;
|
williamr@2
|
388 |
__iend = __grpbuf + __len;
|
williamr@2
|
389 |
__len = __insert_grouping(__buf, __iend, __grouping, __np.thousands_sep(),
|
williamr@2
|
390 |
'+', '-', __basechars);
|
williamr@2
|
391 |
}
|
williamr@2
|
392 |
|
williamr@2
|
393 |
return __copy_integer_and_fill(__buf, __len, __s, __flags, __f.width(0), __fill, '+', '-');
|
williamr@2
|
394 |
}
|
williamr@2
|
395 |
|
williamr@2
|
396 |
#ifdef _STLP_LONG_LONG
|
williamr@2
|
397 |
typedef _STLP_LONG_LONG __max_int_t;
|
williamr@2
|
398 |
typedef unsigned _STLP_LONG_LONG __umax_int_t;
|
williamr@2
|
399 |
#else
|
williamr@2
|
400 |
typedef long __max_int_t;
|
williamr@2
|
401 |
typedef unsigned long __umax_int_t;
|
williamr@2
|
402 |
#endif
|
williamr@2
|
403 |
|
williamr@2
|
404 |
extern _STLP_DECLSPEC const char* get_hex_char_table_lo();
|
williamr@2
|
405 |
extern _STLP_DECLSPEC const char* get_hex_char_table_hi();
|
williamr@2
|
406 |
|
williamr@2
|
407 |
template <class _Integer>
|
williamr@2
|
408 |
inline char* _STLP_CALL
|
williamr@2
|
409 |
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __true_type& /* is_signed */)
|
williamr@2
|
410 |
{
|
williamr@2
|
411 |
const bool __negative = __x < 0 ;
|
williamr@2
|
412 |
__max_int_t __temp = __x;
|
williamr@2
|
413 |
__umax_int_t __utemp = __negative?-__temp:__temp;
|
williamr@2
|
414 |
|
williamr@2
|
415 |
for (; __utemp != 0; __utemp /= 10)
|
williamr@2
|
416 |
*--__ptr = (int)(__utemp % 10) + '0';
|
williamr@2
|
417 |
// put sign if needed or requested
|
williamr@2
|
418 |
if (__negative)
|
williamr@2
|
419 |
*--__ptr = '-';
|
williamr@2
|
420 |
else if (__flags & ios_base::showpos)
|
williamr@2
|
421 |
*--__ptr = '+';
|
williamr@2
|
422 |
return __ptr;
|
williamr@2
|
423 |
}
|
williamr@2
|
424 |
|
williamr@2
|
425 |
template <class _Integer>
|
williamr@2
|
426 |
inline char* _STLP_CALL
|
williamr@2
|
427 |
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __false_type& /* is_signed */)
|
williamr@2
|
428 |
{
|
williamr@2
|
429 |
for (; __x != 0; __x /= 10)
|
williamr@2
|
430 |
*--__ptr = (int)(__x % 10) + '0';
|
williamr@2
|
431 |
// put sign if requested
|
williamr@2
|
432 |
if (__flags & ios_base::showpos)
|
williamr@2
|
433 |
*--__ptr = '+';
|
williamr@2
|
434 |
return __ptr;
|
williamr@2
|
435 |
}
|
williamr@2
|
436 |
|
williamr@2
|
437 |
template <class _Integer>
|
williamr@2
|
438 |
char* _STLP_CALL
|
williamr@2
|
439 |
__write_integer_backward(char* __buf, ios_base::fmtflags __flags, _Integer __x)
|
williamr@2
|
440 |
{
|
williamr@2
|
441 |
char* __ptr = __buf;
|
williamr@2
|
442 |
__umax_int_t __temp;
|
williamr@2
|
443 |
|
williamr@2
|
444 |
if (__x == 0) {
|
williamr@2
|
445 |
*--__ptr = '0';
|
williamr@2
|
446 |
if ((__flags & ios_base::showpos) && ( (__flags & (ios_base::hex | ios_base::oct)) == 0 ))
|
williamr@2
|
447 |
*--__ptr = '+';
|
williamr@2
|
448 |
}
|
williamr@2
|
449 |
else {
|
williamr@2
|
450 |
|
williamr@2
|
451 |
switch (__flags & ios_base::basefield) {
|
williamr@2
|
452 |
case ios_base::oct:
|
williamr@2
|
453 |
__temp = __x;
|
williamr@2
|
454 |
// if the size of integer is less than 8, clear upper part
|
williamr@2
|
455 |
if ( sizeof(__x) < 8 && sizeof(__umax_int_t) >= 8 )
|
williamr@2
|
456 |
__temp &= 0xFFFFFFFF;
|
williamr@2
|
457 |
|
williamr@2
|
458 |
for (; __temp != 0; __temp >>=3)
|
williamr@2
|
459 |
*--__ptr = (((unsigned)__temp)& 0x7) + '0';
|
williamr@2
|
460 |
|
williamr@2
|
461 |
// put leading '0' is showbase is set
|
williamr@2
|
462 |
if (__flags & ios_base::showbase)
|
williamr@2
|
463 |
*--__ptr = '0';
|
williamr@2
|
464 |
break;
|
williamr@2
|
465 |
case ios_base::hex:
|
williamr@2
|
466 |
{
|
williamr@2
|
467 |
const char* __table_ptr = (__flags & ios_base::uppercase) ?
|
williamr@2
|
468 |
get_hex_char_table_hi() : get_hex_char_table_lo();
|
williamr@2
|
469 |
__temp = __x;
|
williamr@2
|
470 |
// if the size of integer is less than 8, clear upper part
|
williamr@2
|
471 |
if ( sizeof(__x) < 8 && sizeof(__umax_int_t) >= 8 )
|
williamr@2
|
472 |
__temp &= 0xFFFFFFFF;
|
williamr@2
|
473 |
|
williamr@2
|
474 |
for (; __temp != 0; __temp >>=4)
|
williamr@2
|
475 |
*--__ptr = __table_ptr[((unsigned)__temp & 0xF)];
|
williamr@2
|
476 |
|
williamr@2
|
477 |
if (__flags & ios_base::showbase) {
|
williamr@2
|
478 |
*--__ptr = __table_ptr[16];
|
williamr@2
|
479 |
*--__ptr = '0';
|
williamr@2
|
480 |
}
|
williamr@2
|
481 |
}
|
williamr@2
|
482 |
break;
|
williamr@2
|
483 |
default:
|
williamr@2
|
484 |
{
|
williamr@2
|
485 |
#if defined(__HP_aCC) && (__HP_aCC == 1)
|
williamr@2
|
486 |
bool _IsSigned = !((_Integer)-1 > 0);
|
williamr@2
|
487 |
if (_IsSigned)
|
williamr@2
|
488 |
__ptr = __write_decimal_backward(__ptr, __x, __flags, __true_type() );
|
williamr@2
|
489 |
else
|
williamr@2
|
490 |
__ptr = __write_decimal_backward(__ptr, __x, __flags, __false_type() );
|
williamr@2
|
491 |
#else
|
williamr@2
|
492 |
typedef typename __bool2type<numeric_limits<_Integer>::is_signed>::_Ret _IsSigned;
|
williamr@2
|
493 |
__ptr = __write_decimal_backward(__ptr, __x, __flags, _IsSigned());
|
williamr@2
|
494 |
# endif
|
williamr@2
|
495 |
}
|
williamr@2
|
496 |
break;
|
williamr@2
|
497 |
}
|
williamr@2
|
498 |
}
|
williamr@2
|
499 |
// return pointer to beginning of the string
|
williamr@2
|
500 |
return __ptr;
|
williamr@2
|
501 |
}
|
williamr@2
|
502 |
|
williamr@2
|
503 |
//
|
williamr@2
|
504 |
// num_put<>
|
williamr@2
|
505 |
//
|
williamr@2
|
506 |
|
williamr@2
|
507 |
# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
|
williamr@2
|
508 |
# if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
|
williamr@2
|
509 |
template <class _CharT, class _OutputIterator>
|
williamr@2
|
510 |
locale::id num_put<_CharT, _OutputIterator>::id;
|
williamr@2
|
511 |
#endif
|
williamr@2
|
512 |
# else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
|
williamr@2
|
513 |
|
williamr@2
|
514 |
typedef num_put<char, const char*> num_put_char;
|
williamr@2
|
515 |
typedef num_put<char, char*> num_put_char_2;
|
williamr@2
|
516 |
typedef num_put<char, ostreambuf_iterator<char, char_traits<char> > > num_put_char_3;
|
williamr@2
|
517 |
typedef num_put<char, back_insert_iterator<string> > num_put_char_4;
|
williamr@2
|
518 |
|
williamr@2
|
519 |
#ifndef __SYMBIAN32__
|
williamr@2
|
520 |
__DECLARE_INSTANCE(locale::id, num_put_char::id, );
|
williamr@2
|
521 |
__DECLARE_INSTANCE(locale::id, num_put_char_2::id, );
|
williamr@2
|
522 |
__DECLARE_INSTANCE(locale::id, num_put_char_3::id, );
|
williamr@2
|
523 |
#endif
|
williamr@2
|
524 |
|
williamr@2
|
525 |
# ifndef _STLP_NO_WCHAR_T
|
williamr@2
|
526 |
|
williamr@2
|
527 |
typedef num_put<wchar_t, const wchar_t*> num_put_wchar_t;
|
williamr@2
|
528 |
typedef num_put<wchar_t, wchar_t*> num_put_wchar_t_2;
|
williamr@2
|
529 |
typedef num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > num_put_wchar_t_3;
|
williamr@2
|
530 |
|
williamr@2
|
531 |
#ifndef __SYMBIAN32__
|
williamr@2
|
532 |
__DECLARE_INSTANCE(locale::id, num_put_wchar_t::id, );
|
williamr@2
|
533 |
__DECLARE_INSTANCE(locale::id, num_put_wchar_t_2::id, );
|
williamr@2
|
534 |
__DECLARE_INSTANCE(locale::id, num_put_wchar_t_3::id, );
|
williamr@2
|
535 |
#endif
|
williamr@2
|
536 |
|
williamr@2
|
537 |
# endif
|
williamr@2
|
538 |
|
williamr@2
|
539 |
# endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
|
williamr@2
|
540 |
|
williamr@2
|
541 |
// issue 118
|
williamr@2
|
542 |
|
williamr@2
|
543 |
# ifndef _STLP_NO_BOOL
|
williamr@2
|
544 |
|
williamr@2
|
545 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
546 |
_OutputIter
|
williamr@2
|
547 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f,
|
williamr@2
|
548 |
char_type __fill, bool __val) const {
|
williamr@2
|
549 |
if (!(__f.flags() & ios_base::boolalpha))
|
williamr@2
|
550 |
return this->do_put(__s, __f, __fill, __STATIC_CAST(long,__val));
|
williamr@2
|
551 |
|
williamr@2
|
552 |
locale __loc = __f.getloc();
|
williamr@2
|
553 |
typedef numpunct<_CharT> _Punct;
|
williamr@2
|
554 |
const _Punct& __np = use_facet<_Punct>(__loc);
|
williamr@2
|
555 |
|
williamr@2
|
556 |
//const numpunct<_CharT>& __np = *(const numpunct<_CharT>*)__f._M_numpunct_facet();
|
williamr@2
|
557 |
|
williamr@2
|
558 |
basic_string<_CharT> __str = __val ? __np.truename() : __np.falsename();
|
williamr@2
|
559 |
|
williamr@2
|
560 |
// Reuse __copy_integer_and_fill. Since internal padding makes no
|
williamr@2
|
561 |
// sense for bool, though, make sure we use something else instead.
|
williamr@2
|
562 |
// The last two argument to __copy_integer_and_fill are dummies.
|
williamr@2
|
563 |
ios_base::fmtflags __flags = __f.flags();
|
williamr@2
|
564 |
if ((__flags & ios_base::adjustfield) == ios_base::internal)
|
williamr@2
|
565 |
__flags = (__flags & ~ios_base::adjustfield) | ios_base::right;
|
williamr@2
|
566 |
|
williamr@2
|
567 |
return __copy_integer_and_fill(__str.c_str(), __str.size(), __s,
|
williamr@2
|
568 |
__flags, __f.width(0), __fill,
|
williamr@2
|
569 |
(_CharT) 0, (_CharT) 0);
|
williamr@2
|
570 |
}
|
williamr@2
|
571 |
|
williamr@2
|
572 |
# endif
|
williamr@2
|
573 |
|
williamr@2
|
574 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
575 |
_OutputIter
|
williamr@2
|
576 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@2
|
577 |
long __val) const {
|
williamr@2
|
578 |
|
williamr@2
|
579 |
char __buf[64]; // Large enough for a base 8 64-bit integer,
|
williamr@2
|
580 |
// plus any necessary grouping.
|
williamr@2
|
581 |
ios_base::fmtflags __flags = __f.flags();
|
williamr@2
|
582 |
char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
|
williamr@2
|
583 |
return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
|
williamr@2
|
584 |
}
|
williamr@2
|
585 |
|
williamr@2
|
586 |
|
williamr@2
|
587 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
588 |
_OutputIter
|
williamr@2
|
589 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@2
|
590 |
unsigned long __val) const {
|
williamr@2
|
591 |
char __buf[64]; // Large enough for a base 8 64-bit integer,
|
williamr@2
|
592 |
// plus any necessary grouping.
|
williamr@2
|
593 |
|
williamr@2
|
594 |
ios_base::fmtflags __flags = __f.flags();
|
williamr@2
|
595 |
char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
|
williamr@2
|
596 |
return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
|
williamr@2
|
597 |
}
|
williamr@2
|
598 |
|
williamr@2
|
599 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
600 |
_OutputIter
|
williamr@2
|
601 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@2
|
602 |
double __val) const {
|
williamr@2
|
603 |
return _M_do_put_float(__s, __f, __fill, __val);
|
williamr@2
|
604 |
}
|
williamr@2
|
605 |
|
williamr@2
|
606 |
#ifndef _STLP_NO_LONG_DOUBLE
|
williamr@2
|
607 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
608 |
_OutputIter
|
williamr@2
|
609 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@2
|
610 |
long double __val) const {
|
williamr@2
|
611 |
return _M_do_put_float(__s, __f, __fill, __val);
|
williamr@2
|
612 |
}
|
williamr@2
|
613 |
#endif
|
williamr@2
|
614 |
|
williamr@2
|
615 |
#ifdef _STLP_LONG_LONG
|
williamr@2
|
616 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
617 |
_OutputIter
|
williamr@2
|
618 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@2
|
619 |
_STLP_LONG_LONG __val) const {
|
williamr@2
|
620 |
char __buf[64]; // Large enough for a base 8 64-bit integer,
|
williamr@2
|
621 |
// plus any necessary grouping.
|
williamr@2
|
622 |
|
williamr@2
|
623 |
ios_base::fmtflags __flags = __f.flags();
|
williamr@2
|
624 |
char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
|
williamr@2
|
625 |
return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
|
williamr@2
|
626 |
}
|
williamr@2
|
627 |
|
williamr@2
|
628 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
629 |
_OutputIter
|
williamr@2
|
630 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@2
|
631 |
unsigned _STLP_LONG_LONG __val) const {
|
williamr@2
|
632 |
char __buf[64]; // Large enough for a base 8 64-bit integer,
|
williamr@2
|
633 |
// plus any necessary grouping.
|
williamr@2
|
634 |
|
williamr@2
|
635 |
ios_base::fmtflags __flags = __f.flags();
|
williamr@2
|
636 |
char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
|
williamr@2
|
637 |
return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
|
williamr@2
|
638 |
}
|
williamr@2
|
639 |
|
williamr@2
|
640 |
#endif /* _STLP_LONG_LONG */
|
williamr@2
|
641 |
|
williamr@2
|
642 |
|
williamr@2
|
643 |
// lib.facet.num.put.virtuals "12 For conversion from void* the specifier is %p."
|
williamr@2
|
644 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
645 |
_OutputIter
|
williamr@2
|
646 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT /*__fill*/,
|
williamr@2
|
647 |
const void* __val) const {
|
williamr@2
|
648 |
//const ctype<_CharT>& __c_type = *(const ctype<_CharT>*)__f._M_ctype_facet();
|
williamr@2
|
649 |
const ctype<_CharT>& __c_type = use_facet< ctype<_CharT> >(__f.getloc());
|
williamr@2
|
650 |
ios_base::fmtflags __save_flags = __f.flags();
|
williamr@2
|
651 |
|
williamr@2
|
652 |
__f.setf(ios_base::hex, ios_base::basefield);
|
williamr@2
|
653 |
__f.setf(ios_base::showbase);
|
williamr@2
|
654 |
__f.setf(ios_base::internal, ios_base::adjustfield);
|
williamr@2
|
655 |
//__f.width((sizeof(void*) * 2) + 2); // digits in pointer type plus '0x' prefix //making output equal to linux.
|
williamr@2
|
656 |
# if defined(_STLP_LONG_LONG) && !defined(__MRC__) //*ty 11/24/2001 - MrCpp can not cast from void* to long long
|
williamr@2
|
657 |
_OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned _STLP_LONG_LONG,__val));
|
williamr@2
|
658 |
# else
|
williamr@2
|
659 |
_OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned long,__val));
|
williamr@2
|
660 |
# endif
|
williamr@2
|
661 |
__f.flags(__save_flags);
|
williamr@2
|
662 |
return result;
|
williamr@2
|
663 |
}
|
williamr@2
|
664 |
|
williamr@2
|
665 |
_STLP_END_NAMESPACE
|
williamr@2
|
666 |
|
williamr@2
|
667 |
# endif /* _STLP_EXPOSE_STREAM_IMPLEMENTATION */
|
williamr@2
|
668 |
|
williamr@2
|
669 |
#endif /* _STLP_NUM_PUT_C */
|
williamr@2
|
670 |
|
williamr@2
|
671 |
// Local Variables:
|
williamr@2
|
672 |
// mode:C++
|
williamr@2
|
673 |
// End:
|