williamr@2
|
1 |
/*
|
williamr@4
|
2 |
* Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
williamr@2
|
3 |
*
|
williamr@2
|
4 |
* Copyright (c) 1999
|
williamr@2
|
5 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
6 |
*
|
williamr@4
|
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@4
|
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@4
|
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@4
|
24 |
# include <stl/_num_put.h>
|
williamr@2
|
25 |
#endif
|
williamr@2
|
26 |
|
williamr@4
|
27 |
#ifndef _STLP_INTERNAL_LIMITS
|
williamr@4
|
28 |
# include <stl/_limits.h>
|
williamr@2
|
29 |
#endif
|
williamr@2
|
30 |
|
williamr@2
|
31 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
32 |
|
williamr@4
|
33 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
34 |
|
williamr@4
|
35 |
// __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 |
//----------------------------------------------------------------------
|
williamr@2
|
40 |
// num_put facet
|
williamr@2
|
41 |
|
williamr@2
|
42 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
43 |
_OutputIter _STLP_CALL
|
williamr@2
|
44 |
__copy_float_and_fill(const _CharT* __first, const _CharT* __last,
|
williamr@4
|
45 |
_OutputIter __oi,
|
williamr@2
|
46 |
ios_base::fmtflags __flags,
|
williamr@2
|
47 |
streamsize __width, _CharT __fill,
|
williamr@2
|
48 |
_CharT __xplus, _CharT __xminus) {
|
williamr@2
|
49 |
if (__width <= __last - __first)
|
williamr@4
|
50 |
return copy(__first, __last, __oi);
|
williamr@2
|
51 |
else {
|
williamr@2
|
52 |
streamsize __pad = __width - (__last - __first);
|
williamr@2
|
53 |
ios_base::fmtflags __dir = __flags & ios_base::adjustfield;
|
williamr@2
|
54 |
|
williamr@2
|
55 |
if (__dir == ios_base::left) {
|
williamr@4
|
56 |
__oi = copy(__first, __last, __oi);
|
williamr@4
|
57 |
return __fill_n(__oi, __pad, __fill);
|
williamr@2
|
58 |
}
|
williamr@2
|
59 |
else if (__dir == ios_base::internal && __first != __last &&
|
williamr@2
|
60 |
(*__first == __xplus || *__first == __xminus)) {
|
williamr@4
|
61 |
*__oi++ = *__first++;
|
williamr@4
|
62 |
__oi = __fill_n(__oi, __pad, __fill);
|
williamr@4
|
63 |
return copy(__first, __last, __oi);
|
williamr@2
|
64 |
}
|
williamr@2
|
65 |
else {
|
williamr@4
|
66 |
__oi = __fill_n(__oi, __pad, __fill);
|
williamr@4
|
67 |
return copy(__first, __last, __oi);
|
williamr@2
|
68 |
}
|
williamr@2
|
69 |
}
|
williamr@2
|
70 |
}
|
williamr@2
|
71 |
|
williamr@4
|
72 |
#if !defined (_STLP_NO_WCHAR_T)
|
williamr@2
|
73 |
// Helper routine for wchar_t
|
williamr@2
|
74 |
template <class _OutputIter>
|
williamr@2
|
75 |
_OutputIter _STLP_CALL
|
williamr@4
|
76 |
__put_float(__iostring &__str, _OutputIter __oi,
|
williamr@2
|
77 |
ios_base& __f, wchar_t __fill,
|
williamr@4
|
78 |
wchar_t __decimal_point, wchar_t __sep,
|
williamr@4
|
79 |
size_t __group_pos, const string& __grouping) {
|
williamr@4
|
80 |
const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet());
|
williamr@2
|
81 |
|
williamr@4
|
82 |
__iowstring __wbuf;
|
williamr@4
|
83 |
__convert_float_buffer(__str, __wbuf, __ct, __decimal_point);
|
williamr@4
|
84 |
|
williamr@2
|
85 |
if (!__grouping.empty()) {
|
williamr@4
|
86 |
__insert_grouping(__wbuf, __group_pos, __grouping,
|
williamr@4
|
87 |
__sep, __ct.widen('+'), __ct.widen('-'), 0);
|
williamr@2
|
88 |
}
|
williamr@2
|
89 |
|
williamr@4
|
90 |
return __copy_float_and_fill(__CONST_CAST(wchar_t*, __wbuf.data()),
|
williamr@4
|
91 |
__CONST_CAST(wchar_t*, __wbuf.data()) + __wbuf.size(), __oi,
|
williamr@4
|
92 |
__f.flags(), __f.width(0), __fill, __ct.widen('+'), __ct.widen('-'));
|
williamr@2
|
93 |
}
|
williamr@4
|
94 |
#endif /* WCHAR_T */
|
williamr@2
|
95 |
|
williamr@2
|
96 |
// Helper routine for char
|
williamr@2
|
97 |
template <class _OutputIter>
|
williamr@2
|
98 |
_OutputIter _STLP_CALL
|
williamr@4
|
99 |
__put_float(__iostring &__str, _OutputIter __oi,
|
williamr@2
|
100 |
ios_base& __f, char __fill,
|
williamr@4
|
101 |
char __decimal_point, char __sep,
|
williamr@4
|
102 |
size_t __group_pos, const string& __grouping) {
|
williamr@4
|
103 |
if ((__group_pos < __str.size()) && (__str[__group_pos] == '.')) {
|
williamr@4
|
104 |
__str[__group_pos] = __decimal_point;
|
williamr@2
|
105 |
}
|
williamr@2
|
106 |
|
williamr@4
|
107 |
if (!__grouping.empty()) {
|
williamr@4
|
108 |
__insert_grouping(__str, __group_pos,
|
williamr@4
|
109 |
__grouping, __sep, '+', '-', 0);
|
williamr@4
|
110 |
}
|
williamr@4
|
111 |
|
williamr@4
|
112 |
return __copy_float_and_fill(__CONST_CAST(char*, __str.data()),
|
williamr@4
|
113 |
__CONST_CAST(char*, __str.data()) + __str.size(), __oi,
|
williamr@2
|
114 |
__f.flags(), __f.width(0), __fill, '+', '-');
|
williamr@2
|
115 |
}
|
williamr@2
|
116 |
|
williamr@4
|
117 |
template <class _CharT, class _OutputIter, class _Float>
|
williamr@4
|
118 |
_OutputIter _STLP_CALL
|
williamr@4
|
119 |
__do_put_float(_OutputIter __s, ios_base& __f,
|
williamr@4
|
120 |
_CharT __fill, _Float __x) {
|
williamr@4
|
121 |
__iostring __buf;
|
williamr@2
|
122 |
|
williamr@4
|
123 |
size_t __group_pos = __write_float(__buf, __f.flags(), (int)__f.precision(), __x);
|
williamr@2
|
124 |
|
williamr@4
|
125 |
const numpunct<_CharT>& __np = *__STATIC_CAST(const numpunct<_CharT>*, __f._M_numpunct_facet());
|
williamr@4
|
126 |
|
williamr@4
|
127 |
return __put_float(__buf, __s, __f, __fill,
|
williamr@4
|
128 |
__np.decimal_point(), __np.thousands_sep(),
|
williamr@4
|
129 |
__group_pos, __f._M_grouping());
|
williamr@2
|
130 |
}
|
williamr@2
|
131 |
|
williamr@4
|
132 |
inline void __get_money_digits_aux (__iostring &__buf, ios_base &, _STLP_LONGEST_FLOAT_TYPE __x)
|
williamr@4
|
133 |
{ __get_floor_digits(__buf, __x); }
|
williamr@2
|
134 |
|
williamr@4
|
135 |
#if !defined (_STLP_NO_WCHAR_T)
|
williamr@4
|
136 |
inline void __get_money_digits_aux (__iowstring &__wbuf, ios_base &__f, _STLP_LONGEST_FLOAT_TYPE __x) {
|
williamr@4
|
137 |
__iostring __buf;
|
williamr@4
|
138 |
__get_floor_digits(__buf, __x);
|
williamr@4
|
139 |
|
williamr@4
|
140 |
const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet());
|
williamr@4
|
141 |
__convert_float_buffer(__buf, __wbuf, __ct, wchar_t(0), false);
|
williamr@4
|
142 |
}
|
williamr@2
|
143 |
#endif
|
williamr@2
|
144 |
|
williamr@4
|
145 |
template <class _CharT>
|
williamr@4
|
146 |
void _STLP_CALL __get_money_digits(_STLP_BASIC_IOSTRING(_CharT) &__buf, ios_base& __f, _STLP_LONGEST_FLOAT_TYPE __x)
|
williamr@4
|
147 |
{ __get_money_digits_aux(__buf, __f, __x); }
|
williamr@2
|
148 |
|
williamr@2
|
149 |
// _M_do_put_integer and its helper functions.
|
williamr@2
|
150 |
|
williamr@2
|
151 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
152 |
_OutputIter _STLP_CALL
|
williamr@2
|
153 |
__copy_integer_and_fill(const _CharT* __buf, ptrdiff_t __len,
|
williamr@4
|
154 |
_OutputIter __oi,
|
williamr@2
|
155 |
ios_base::fmtflags __flg, streamsize __wid, _CharT __fill,
|
williamr@4
|
156 |
_CharT __xplus, _CharT __xminus) {
|
williamr@2
|
157 |
if (__len >= __wid)
|
williamr@4
|
158 |
return copy(__buf, __buf + __len, __oi);
|
williamr@2
|
159 |
else {
|
williamr@4
|
160 |
//casting numeric_limits<ptrdiff_t>::max to streamsize only works is ptrdiff_t is signed or streamsize representation
|
williamr@4
|
161 |
//is larger than ptrdiff_t one.
|
williamr@4
|
162 |
_STLP_STATIC_ASSERT((sizeof(streamsize) > sizeof(ptrdiff_t)) ||
|
williamr@4
|
163 |
(sizeof(streamsize) == sizeof(ptrdiff_t)) && numeric_limits<ptrdiff_t>::is_signed)
|
williamr@4
|
164 |
ptrdiff_t __pad = __STATIC_CAST(ptrdiff_t, (min) (__STATIC_CAST(streamsize, (numeric_limits<ptrdiff_t>::max)()),
|
williamr@4
|
165 |
__STATIC_CAST(streamsize, __wid - __len)));
|
williamr@2
|
166 |
ios_base::fmtflags __dir = __flg & ios_base::adjustfield;
|
williamr@2
|
167 |
|
williamr@2
|
168 |
if (__dir == ios_base::left) {
|
williamr@4
|
169 |
__oi = copy(__buf, __buf + __len, __oi);
|
williamr@4
|
170 |
return __fill_n(__oi, __pad, __fill);
|
williamr@2
|
171 |
}
|
williamr@2
|
172 |
else if (__dir == ios_base::internal && __len != 0 &&
|
williamr@2
|
173 |
(__buf[0] == __xplus || __buf[0] == __xminus)) {
|
williamr@4
|
174 |
*__oi++ = __buf[0];
|
williamr@4
|
175 |
__oi = __fill_n(__oi, __pad, __fill);
|
williamr@4
|
176 |
return copy(__buf + 1, __buf + __len, __oi);
|
williamr@2
|
177 |
}
|
williamr@4
|
178 |
else if (__dir == ios_base::internal && __len >= 2 &&
|
williamr@2
|
179 |
(__flg & ios_base::showbase) &&
|
williamr@2
|
180 |
(__flg & ios_base::basefield) == ios_base::hex) {
|
williamr@4
|
181 |
*__oi++ = __buf[0];
|
williamr@4
|
182 |
*__oi++ = __buf[1];
|
williamr@4
|
183 |
__oi = __fill_n(__oi, __pad, __fill);
|
williamr@4
|
184 |
return copy(__buf + 2, __buf + __len, __oi);
|
williamr@2
|
185 |
}
|
williamr@2
|
186 |
else {
|
williamr@4
|
187 |
__oi = __fill_n(__oi, __pad, __fill);
|
williamr@4
|
188 |
return copy(__buf, __buf + __len, __oi);
|
williamr@2
|
189 |
}
|
williamr@2
|
190 |
}
|
williamr@2
|
191 |
}
|
williamr@2
|
192 |
|
williamr@4
|
193 |
#if !defined (_STLP_NO_WCHAR_T)
|
williamr@2
|
194 |
// Helper function for wchar_t
|
williamr@2
|
195 |
template <class _OutputIter>
|
williamr@2
|
196 |
_OutputIter _STLP_CALL
|
williamr@2
|
197 |
__put_integer(char* __buf, char* __iend, _OutputIter __s,
|
williamr@2
|
198 |
ios_base& __f,
|
williamr@4
|
199 |
ios_base::fmtflags __flags, wchar_t __fill) {
|
williamr@2
|
200 |
locale __loc = __f.getloc();
|
williamr@4
|
201 |
// const ctype<wchar_t>& __ct = use_facet<ctype<wchar_t> >(__loc);
|
williamr@4
|
202 |
const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet());
|
williamr@2
|
203 |
|
williamr@2
|
204 |
wchar_t __xplus = __ct.widen('+');
|
williamr@2
|
205 |
wchar_t __xminus = __ct.widen('-');
|
williamr@2
|
206 |
|
williamr@2
|
207 |
wchar_t __wbuf[64];
|
williamr@2
|
208 |
__ct.widen(__buf, __iend, __wbuf);
|
williamr@2
|
209 |
ptrdiff_t __len = __iend - __buf;
|
williamr@2
|
210 |
wchar_t* __eend = __wbuf + __len;
|
williamr@2
|
211 |
|
williamr@4
|
212 |
// const numpunct<wchar_t>& __np = use_facet<numpunct<wchar_t> >(__loc);
|
williamr@4
|
213 |
// const string& __grouping = __np.grouping();
|
williamr@2
|
214 |
|
williamr@4
|
215 |
const numpunct<wchar_t>& __np = *__STATIC_CAST(const numpunct<wchar_t>*, __f._M_numpunct_facet());
|
williamr@4
|
216 |
const string& __grouping = __f._M_grouping();
|
williamr@2
|
217 |
|
williamr@2
|
218 |
if (!__grouping.empty()) {
|
williamr@2
|
219 |
int __basechars;
|
williamr@2
|
220 |
if (__flags & ios_base::showbase)
|
williamr@2
|
221 |
switch (__flags & ios_base::basefield) {
|
williamr@4
|
222 |
case ios_base::hex: __basechars = 2; break;
|
williamr@4
|
223 |
case ios_base::oct: __basechars = 1; break;
|
williamr@4
|
224 |
default: __basechars = 0;
|
williamr@2
|
225 |
}
|
williamr@2
|
226 |
else
|
williamr@2
|
227 |
__basechars = 0;
|
williamr@2
|
228 |
|
williamr@2
|
229 |
__len = __insert_grouping(__wbuf, __eend, __grouping, __np.thousands_sep(),
|
williamr@4
|
230 |
__xplus, __xminus, __basechars);
|
williamr@2
|
231 |
}
|
williamr@2
|
232 |
|
williamr@2
|
233 |
return __copy_integer_and_fill((wchar_t*)__wbuf, __len, __s,
|
williamr@2
|
234 |
__flags, __f.width(0), __fill, __xplus, __xminus);
|
williamr@2
|
235 |
}
|
williamr@2
|
236 |
#endif
|
williamr@2
|
237 |
|
williamr@4
|
238 |
// Helper function for char
|
williamr@4
|
239 |
template <class _OutputIter>
|
williamr@2
|
240 |
_OutputIter _STLP_CALL
|
williamr@2
|
241 |
__put_integer(char* __buf, char* __iend, _OutputIter __s,
|
williamr@4
|
242 |
ios_base& __f, ios_base::fmtflags __flags, char __fill) {
|
williamr@4
|
243 |
char __grpbuf[64];
|
williamr@4
|
244 |
ptrdiff_t __len = __iend - __buf;
|
williamr@2
|
245 |
|
williamr@4
|
246 |
// const numpunct<char>& __np = use_facet<numpunct<char> >(__f.getloc());
|
williamr@4
|
247 |
// const string& __grouping = __np.grouping();
|
williamr@2
|
248 |
|
williamr@4
|
249 |
const numpunct<char>& __np = *__STATIC_CAST(const numpunct<char>*, __f._M_numpunct_facet());
|
williamr@4
|
250 |
const string& __grouping = __f._M_grouping();
|
williamr@2
|
251 |
|
williamr@2
|
252 |
if (!__grouping.empty()) {
|
williamr@2
|
253 |
int __basechars;
|
williamr@2
|
254 |
if (__flags & ios_base::showbase)
|
williamr@2
|
255 |
switch (__flags & ios_base::basefield) {
|
williamr@4
|
256 |
case ios_base::hex: __basechars = 2; break;
|
williamr@4
|
257 |
case ios_base::oct: __basechars = 1; break;
|
williamr@4
|
258 |
default: __basechars = 0;
|
williamr@2
|
259 |
}
|
williamr@2
|
260 |
else
|
williamr@2
|
261 |
__basechars = 0;
|
williamr@2
|
262 |
|
williamr@4
|
263 |
// make sure there is room at the end of the buffer
|
williamr@4
|
264 |
// we pass to __insert_grouping
|
williamr@4
|
265 |
copy(__buf, __iend, (char *) __grpbuf);
|
williamr@4
|
266 |
__buf = __grpbuf;
|
williamr@4
|
267 |
__iend = __grpbuf + __len;
|
williamr@2
|
268 |
__len = __insert_grouping(__buf, __iend, __grouping, __np.thousands_sep(),
|
williamr@4
|
269 |
'+', '-', __basechars);
|
williamr@2
|
270 |
}
|
williamr@2
|
271 |
|
williamr@2
|
272 |
return __copy_integer_and_fill(__buf, __len, __s, __flags, __f.width(0), __fill, '+', '-');
|
williamr@2
|
273 |
}
|
williamr@2
|
274 |
|
williamr@4
|
275 |
#if defined (_STLP_LONG_LONG)
|
williamr@2
|
276 |
typedef _STLP_LONG_LONG __max_int_t;
|
williamr@2
|
277 |
typedef unsigned _STLP_LONG_LONG __umax_int_t;
|
williamr@2
|
278 |
#else
|
williamr@2
|
279 |
typedef long __max_int_t;
|
williamr@2
|
280 |
typedef unsigned long __umax_int_t;
|
williamr@2
|
281 |
#endif
|
williamr@2
|
282 |
|
williamr@4
|
283 |
_STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo();
|
williamr@4
|
284 |
_STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi();
|
williamr@2
|
285 |
|
williamr@2
|
286 |
template <class _Integer>
|
williamr@2
|
287 |
inline char* _STLP_CALL
|
williamr@4
|
288 |
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __true_type& /* is_signed */) {
|
williamr@2
|
289 |
const bool __negative = __x < 0 ;
|
williamr@2
|
290 |
__max_int_t __temp = __x;
|
williamr@2
|
291 |
__umax_int_t __utemp = __negative?-__temp:__temp;
|
williamr@2
|
292 |
|
williamr@2
|
293 |
for (; __utemp != 0; __utemp /= 10)
|
williamr@4
|
294 |
*--__ptr = (char)((int)(__utemp % 10) + '0');
|
williamr@2
|
295 |
// put sign if needed or requested
|
williamr@2
|
296 |
if (__negative)
|
williamr@2
|
297 |
*--__ptr = '-';
|
williamr@2
|
298 |
else if (__flags & ios_base::showpos)
|
williamr@2
|
299 |
*--__ptr = '+';
|
williamr@2
|
300 |
return __ptr;
|
williamr@2
|
301 |
}
|
williamr@2
|
302 |
|
williamr@2
|
303 |
template <class _Integer>
|
williamr@2
|
304 |
inline char* _STLP_CALL
|
williamr@4
|
305 |
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __false_type& /* is_signed */) {
|
williamr@2
|
306 |
for (; __x != 0; __x /= 10)
|
williamr@4
|
307 |
*--__ptr = (char)((int)(__x % 10) + '0');
|
williamr@2
|
308 |
// put sign if requested
|
williamr@2
|
309 |
if (__flags & ios_base::showpos)
|
williamr@2
|
310 |
*--__ptr = '+';
|
williamr@2
|
311 |
return __ptr;
|
williamr@2
|
312 |
}
|
williamr@2
|
313 |
|
williamr@2
|
314 |
template <class _Integer>
|
williamr@2
|
315 |
char* _STLP_CALL
|
williamr@4
|
316 |
__write_integer_backward(char* __buf, ios_base::fmtflags __flags, _Integer __x) {
|
williamr@2
|
317 |
char* __ptr = __buf;
|
williamr@2
|
318 |
|
williamr@2
|
319 |
if (__x == 0) {
|
williamr@2
|
320 |
*--__ptr = '0';
|
williamr@4
|
321 |
if ((__flags & ios_base::showpos) && ((__flags & (ios_base::oct | ios_base::hex)) == 0))
|
williamr@2
|
322 |
*--__ptr = '+';
|
williamr@4
|
323 |
// oct or hex base shall not be added to the 0 value (see '#' flag in C formating strings)
|
williamr@2
|
324 |
}
|
williamr@2
|
325 |
else {
|
williamr@2
|
326 |
switch (__flags & ios_base::basefield) {
|
williamr@4
|
327 |
case ios_base::oct:
|
williamr@4
|
328 |
{
|
williamr@4
|
329 |
__umax_int_t __temp = __x;
|
williamr@4
|
330 |
// if the size of integer is less than 8, clear upper part
|
williamr@4
|
331 |
if ( sizeof(__x) < 8 && sizeof(__umax_int_t) >= 8 )
|
williamr@4
|
332 |
__temp &= 0xFFFFFFFF;
|
williamr@2
|
333 |
|
williamr@4
|
334 |
for (; __temp != 0; __temp >>=3)
|
williamr@4
|
335 |
*--__ptr = (char)((((unsigned)__temp)& 0x7) + '0');
|
williamr@2
|
336 |
|
williamr@4
|
337 |
// put leading '0' if showbase is set
|
williamr@4
|
338 |
if (__flags & ios_base::showbase)
|
williamr@4
|
339 |
*--__ptr = '0';
|
williamr@2
|
340 |
}
|
williamr@4
|
341 |
break;
|
williamr@4
|
342 |
case ios_base::hex:
|
williamr@4
|
343 |
{
|
williamr@4
|
344 |
const char* __table_ptr = (__flags & ios_base::uppercase) ?
|
williamr@4
|
345 |
__hex_char_table_hi() : __hex_char_table_lo();
|
williamr@4
|
346 |
__umax_int_t __temp = __x;
|
williamr@4
|
347 |
// if the size of integer is less than 8, clear upper part
|
williamr@4
|
348 |
if ( sizeof(__x) < 8 && sizeof(__umax_int_t) >= 8 )
|
williamr@4
|
349 |
__temp &= 0xFFFFFFFF;
|
williamr@4
|
350 |
|
williamr@4
|
351 |
for (; __temp != 0; __temp >>=4)
|
williamr@4
|
352 |
*--__ptr = __table_ptr[((unsigned)__temp & 0xF)];
|
williamr@4
|
353 |
|
williamr@4
|
354 |
if (__flags & ios_base::showbase) {
|
williamr@4
|
355 |
*--__ptr = __table_ptr[16];
|
williamr@4
|
356 |
*--__ptr = '0';
|
williamr@4
|
357 |
}
|
williamr@4
|
358 |
}
|
williamr@4
|
359 |
break;
|
williamr@4
|
360 |
//case ios_base::dec:
|
williamr@4
|
361 |
default:
|
williamr@4
|
362 |
{
|
williamr@2
|
363 |
#if defined(__HP_aCC) && (__HP_aCC == 1)
|
williamr@4
|
364 |
bool _IsSigned = !((_Integer)-1 > 0);
|
williamr@4
|
365 |
if (_IsSigned)
|
williamr@4
|
366 |
__ptr = __write_decimal_backward(__ptr, __x, __flags, __true_type() );
|
williamr@4
|
367 |
else
|
williamr@4
|
368 |
__ptr = __write_decimal_backward(__ptr, __x, __flags, __false_type() );
|
williamr@2
|
369 |
#else
|
williamr@4
|
370 |
typedef typename __bool2type<numeric_limits<_Integer>::is_signed>::_Ret _IsSigned;
|
williamr@4
|
371 |
__ptr = __write_decimal_backward(__ptr, __x, __flags, _IsSigned());
|
williamr@4
|
372 |
#endif
|
williamr@4
|
373 |
}
|
williamr@4
|
374 |
break;
|
williamr@4
|
375 |
}
|
williamr@2
|
376 |
}
|
williamr@4
|
377 |
|
williamr@2
|
378 |
// return pointer to beginning of the string
|
williamr@2
|
379 |
return __ptr;
|
williamr@2
|
380 |
}
|
williamr@2
|
381 |
|
williamr@4
|
382 |
template <class _CharT, class _OutputIter, class _Integer>
|
williamr@4
|
383 |
_OutputIter _STLP_CALL
|
williamr@4
|
384 |
__do_put_integer(_OutputIter __s, ios_base& __f, _CharT __fill, _Integer __x) {
|
williamr@4
|
385 |
// buffer size = number of bytes * number of digit necessary in the smallest Standard base (base 8, 3 digits/byte)
|
williamr@4
|
386 |
// plus the longest base representation '0x'
|
williamr@4
|
387 |
// Do not use __buf_size to define __buf static buffer, some compilers (HP aCC) do not accept const variable as
|
williamr@4
|
388 |
// the specification of a static buffer size.
|
williamr@4
|
389 |
char __buf[sizeof(_Integer) * 3 + 2];
|
williamr@4
|
390 |
const ptrdiff_t __buf_size = sizeof(__buf) / sizeof(char);
|
williamr@4
|
391 |
ios_base::fmtflags __flags = __f.flags();
|
williamr@4
|
392 |
char* __ibeg = __write_integer_backward((char*)__buf+__buf_size, __flags, __x);
|
williamr@4
|
393 |
return __put_integer(__ibeg, (char*)__buf+__buf_size, __s, __f, __flags, __fill);
|
williamr@4
|
394 |
}
|
williamr@4
|
395 |
|
williamr@4
|
396 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
397 |
|
williamr@2
|
398 |
//
|
williamr@2
|
399 |
// num_put<>
|
williamr@2
|
400 |
//
|
williamr@2
|
401 |
|
williamr@4
|
402 |
#if (_STLP_STATIC_TEMPLATE_DATA > 0)
|
williamr@4
|
403 |
# if !defined(__SYMBIAN32__WSD__)
|
williamr@4
|
404 |
# if !defined (__BORLANDC__) && defined (__SYMBIAN32__) && defined(_STLP_DESIGNATED_DLL)
|
williamr@2
|
405 |
template <class _CharT, class _OutputIterator>
|
williamr@2
|
406 |
locale::id num_put<_CharT, _OutputIterator>::id;
|
williamr@4
|
407 |
# endif
|
williamr@2
|
408 |
|
williamr@4
|
409 |
# if ((defined (__CYGWIN__) || defined (__MINGW32__)) && \
|
williamr@4
|
410 |
defined (_STLP_USE_DYNAMIC_LIB) && !defined (__BUILDING_STLPORT)) || (defined (__SYMBIAN32__) && defined(_STLP_DESIGNATED_DLL))
|
williamr@4
|
411 |
/*
|
williamr@4
|
412 |
* Under cygwin, when STLport is used as a shared library, the id needs
|
williamr@4
|
413 |
* to be specified as imported otherwise they will be duplicated in the
|
williamr@4
|
414 |
* calling executable.
|
williamr@4
|
415 |
*/
|
williamr@4
|
416 |
# if defined(__SYMBIAN32__)
|
williamr@4
|
417 |
template <>
|
williamr@4
|
418 |
locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; //data should not be exported in symbian
|
williamr@4
|
419 |
/*
|
williamr@4
|
420 |
template <>
|
williamr@4
|
421 |
_STLP_DECLSPEC locale::id num_put<char, char*>::id;
|
williamr@4
|
422 |
*/
|
williamr@2
|
423 |
|
williamr@4
|
424 |
# if !defined (_STLP_NO_WCHAR_T)
|
williamr@4
|
425 |
template <>
|
williamr@4
|
426 |
locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
|
williamr@4
|
427 |
/*
|
williamr@4
|
428 |
template <>
|
williamr@4
|
429 |
_STLP_DECLSPEC locale::id num_put<wchar_t, wchar_t*>::id;
|
williamr@4
|
430 |
*/
|
williamr@4
|
431 |
# endif
|
williamr@4
|
432 |
|
williamr@4
|
433 |
# else
|
williamr@4
|
434 |
template <>
|
williamr@4
|
435 |
_STLP_DECLSPEC locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
|
williamr@4
|
436 |
/*
|
williamr@4
|
437 |
template <>
|
williamr@4
|
438 |
_STLP_DECLSPEC locale::id num_put<char, char*>::id;
|
williamr@4
|
439 |
*/
|
williamr@4
|
440 |
|
williamr@4
|
441 |
# if !defined (_STLP_NO_WCHAR_T)
|
williamr@4
|
442 |
template <>
|
williamr@4
|
443 |
_STLP_DECLSPEC locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
|
williamr@4
|
444 |
/*
|
williamr@4
|
445 |
template <>
|
williamr@4
|
446 |
_STLP_DECLSPEC locale::id num_put<wchar_t, wchar_t*>::id;
|
williamr@4
|
447 |
*/
|
williamr@4
|
448 |
# endif
|
williamr@4
|
449 |
|
williamr@4
|
450 |
# endif //__SYMBIAN32__
|
williamr@4
|
451 |
|
williamr@4
|
452 |
# endif /* __CYGWIN__ && _STLP_USE_DYNAMIC_LIB */
|
williamr@4
|
453 |
#endif /*__SYMBIAN32__WSD__ */
|
williamr@4
|
454 |
#else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
|
williamr@4
|
455 |
|
williamr@4
|
456 |
//typedef num_put<char, char*> num_put_char;
|
williamr@4
|
457 |
typedef num_put<char, ostreambuf_iterator<char, char_traits<char> > > num_put_char_2;
|
williamr@4
|
458 |
|
williamr@4
|
459 |
//__DECLARE_INSTANCE(locale::id, num_put_char::id, );
|
williamr@2
|
460 |
__DECLARE_INSTANCE(locale::id, num_put_char_2::id, );
|
williamr@2
|
461 |
|
williamr@4
|
462 |
# if !defined (_STLP_NO_WCHAR_T)
|
williamr@2
|
463 |
|
williamr@4
|
464 |
//typedef num_put<wchar_t, wchar_t*> num_put_wchar_t;
|
williamr@4
|
465 |
typedef num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > num_put_wchar_t_2;
|
williamr@2
|
466 |
|
williamr@4
|
467 |
//__DECLARE_INSTANCE(locale::id, num_put_wchar_t::id, );
|
williamr@2
|
468 |
__DECLARE_INSTANCE(locale::id, num_put_wchar_t_2::id, );
|
williamr@2
|
469 |
|
williamr@4
|
470 |
# endif
|
williamr@2
|
471 |
|
williamr@4
|
472 |
#endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
|
williamr@2
|
473 |
|
williamr@2
|
474 |
// issue 118
|
williamr@2
|
475 |
|
williamr@4
|
476 |
#if !defined (_STLP_NO_BOOL)
|
williamr@4
|
477 |
template <class _CharT, class _OutputIter>
|
williamr@4
|
478 |
_OutputIter
|
williamr@4
|
479 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f,
|
williamr@2
|
480 |
char_type __fill, bool __val) const {
|
williamr@2
|
481 |
if (!(__f.flags() & ios_base::boolalpha))
|
williamr@2
|
482 |
return this->do_put(__s, __f, __fill, __STATIC_CAST(long,__val));
|
williamr@2
|
483 |
|
williamr@2
|
484 |
locale __loc = __f.getloc();
|
williamr@4
|
485 |
// typedef numpunct<_CharT> _Punct;
|
williamr@4
|
486 |
// const _Punct& __np = use_facet<_Punct>(__loc);
|
williamr@2
|
487 |
|
williamr@4
|
488 |
const numpunct<_CharT>& __np = *__STATIC_CAST(const numpunct<_CharT>*, __f._M_numpunct_facet());
|
williamr@2
|
489 |
|
williamr@2
|
490 |
basic_string<_CharT> __str = __val ? __np.truename() : __np.falsename();
|
williamr@2
|
491 |
|
williamr@2
|
492 |
// Reuse __copy_integer_and_fill. Since internal padding makes no
|
williamr@2
|
493 |
// sense for bool, though, make sure we use something else instead.
|
williamr@2
|
494 |
// The last two argument to __copy_integer_and_fill are dummies.
|
williamr@2
|
495 |
ios_base::fmtflags __flags = __f.flags();
|
williamr@2
|
496 |
if ((__flags & ios_base::adjustfield) == ios_base::internal)
|
williamr@2
|
497 |
__flags = (__flags & ~ios_base::adjustfield) | ios_base::right;
|
williamr@2
|
498 |
|
williamr@4
|
499 |
return _STLP_PRIV __copy_integer_and_fill(__str.c_str(), __str.size(), __s,
|
williamr@4
|
500 |
__flags, __f.width(0), __fill,
|
williamr@4
|
501 |
(_CharT) 0, (_CharT) 0);
|
williamr@2
|
502 |
}
|
williamr@2
|
503 |
|
williamr@4
|
504 |
#endif
|
williamr@2
|
505 |
|
williamr@2
|
506 |
template <class _CharT, class _OutputIter>
|
williamr@4
|
507 |
_OutputIter
|
williamr@2
|
508 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@4
|
509 |
long __val) const
|
williamr@4
|
510 |
{ return _STLP_PRIV __do_put_integer(__s, __f, __fill, __val); }
|
williamr@2
|
511 |
|
williamr@4
|
512 |
template <class _CharT, class _OutputIter>
|
williamr@4
|
513 |
_OutputIter
|
williamr@4
|
514 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@4
|
515 |
unsigned long __val) const
|
williamr@4
|
516 |
{ return _STLP_PRIV __do_put_integer(__s, __f, __fill, __val); }
|
williamr@2
|
517 |
|
williamr@4
|
518 |
template <class _CharT, class _OutputIter>
|
williamr@4
|
519 |
_OutputIter
|
williamr@4
|
520 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@4
|
521 |
double __val) const
|
williamr@4
|
522 |
{ return _STLP_PRIV __do_put_float(__s, __f, __fill, __val); }
|
williamr@2
|
523 |
|
williamr@4
|
524 |
#if !defined (_STLP_NO_LONG_DOUBLE)
|
williamr@4
|
525 |
template <class _CharT, class _OutputIter>
|
williamr@4
|
526 |
_OutputIter
|
williamr@2
|
527 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@4
|
528 |
long double __val) const
|
williamr@4
|
529 |
{ return _STLP_PRIV __do_put_float(__s, __f, __fill, __val); }
|
williamr@2
|
530 |
#endif
|
williamr@2
|
531 |
|
williamr@4
|
532 |
#if defined (_STLP_LONG_LONG)
|
williamr@4
|
533 |
template <class _CharT, class _OutputIter>
|
williamr@4
|
534 |
_OutputIter
|
williamr@2
|
535 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@4
|
536 |
_STLP_LONG_LONG __val) const
|
williamr@4
|
537 |
{ return _STLP_PRIV __do_put_integer(__s, __f, __fill, __val); }
|
williamr@2
|
538 |
|
williamr@4
|
539 |
template <class _CharT, class _OutputIter>
|
williamr@4
|
540 |
_OutputIter
|
williamr@2
|
541 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
|
williamr@4
|
542 |
unsigned _STLP_LONG_LONG __val) const
|
williamr@4
|
543 |
{ return _STLP_PRIV __do_put_integer(__s, __f, __fill, __val); }
|
williamr@2
|
544 |
#endif /* _STLP_LONG_LONG */
|
williamr@2
|
545 |
|
williamr@2
|
546 |
|
williamr@2
|
547 |
// lib.facet.num.put.virtuals "12 For conversion from void* the specifier is %p."
|
williamr@2
|
548 |
template <class _CharT, class _OutputIter>
|
williamr@2
|
549 |
_OutputIter
|
williamr@2
|
550 |
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT /*__fill*/,
|
williamr@4
|
551 |
const void* __val) const {
|
williamr@4
|
552 |
const ctype<_CharT>& __c_type = *__STATIC_CAST(const ctype<_CharT>*, __f._M_ctype_facet());
|
williamr@2
|
553 |
ios_base::fmtflags __save_flags = __f.flags();
|
williamr@2
|
554 |
|
williamr@2
|
555 |
__f.setf(ios_base::hex, ios_base::basefield);
|
williamr@2
|
556 |
__f.setf(ios_base::showbase);
|
williamr@2
|
557 |
__f.setf(ios_base::internal, ios_base::adjustfield);
|
williamr@4
|
558 |
__f.width((sizeof(void*) * 2) + 2); // digits in pointer type plus '0x' prefix
|
williamr@2
|
559 |
# if defined(_STLP_LONG_LONG) && !defined(__MRC__) //*ty 11/24/2001 - MrCpp can not cast from void* to long long
|
williamr@2
|
560 |
_OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned _STLP_LONG_LONG,__val));
|
williamr@2
|
561 |
# else
|
williamr@2
|
562 |
_OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned long,__val));
|
williamr@2
|
563 |
# endif
|
williamr@2
|
564 |
__f.flags(__save_flags);
|
williamr@2
|
565 |
return result;
|
williamr@2
|
566 |
}
|
williamr@2
|
567 |
|
williamr@2
|
568 |
_STLP_END_NAMESPACE
|
williamr@2
|
569 |
|
williamr@2
|
570 |
#endif /* _STLP_NUM_PUT_C */
|
williamr@2
|
571 |
|
williamr@2
|
572 |
// Local Variables:
|
williamr@2
|
573 |
// mode:C++
|
williamr@2
|
574 |
// End:
|