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_MONETARY_C
|
williamr@2
|
21 |
#define _STLP_MONETARY_C
|
williamr@2
|
22 |
|
williamr@2
|
23 |
# ifndef _STLP_INTERNAL_MONETARY_H
|
williamr@2
|
24 |
# include <stl/_monetary.h>
|
williamr@2
|
25 |
# endif
|
williamr@2
|
26 |
|
williamr@2
|
27 |
#ifndef _STLP_INTERNAL_IOS_H
|
williamr@2
|
28 |
# include <stl/_ios.h>
|
williamr@2
|
29 |
#endif
|
williamr@2
|
30 |
|
williamr@2
|
31 |
#ifndef _STLP_INTERNAL_NUM_PUT_H
|
williamr@2
|
32 |
# include <stl/_num_put.h>
|
williamr@2
|
33 |
#endif
|
williamr@2
|
34 |
|
williamr@2
|
35 |
#ifndef _STLP_INTERNAL_NUM_GET_H
|
williamr@2
|
36 |
# include <stl/_num_get.h>
|
williamr@2
|
37 |
#endif
|
williamr@2
|
38 |
|
williamr@2
|
39 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
40 |
|
williamr@4
|
41 |
#if (_STLP_STATIC_TEMPLATE_DATA > 0)
|
williamr@4
|
42 |
#if !defined(__SYMBIAN32__WSD__)
|
williamr@4
|
43 |
|
williamr@4
|
44 |
# if !defined (__BORLANDC__) && (defined (__SYMBIAN32__) && defined(_STLP_DESIGNATED_DLL))
|
williamr@2
|
45 |
template <class _CharT, class _InputIterator>
|
williamr@2
|
46 |
locale::id money_get<_CharT, _InputIterator>::id;
|
williamr@2
|
47 |
|
williamr@2
|
48 |
template <class _CharT, class _OutputIterator>
|
williamr@2
|
49 |
locale::id money_put<_CharT, _OutputIterator>::id;
|
williamr@4
|
50 |
# endif
|
williamr@4
|
51 |
|
williamr@4
|
52 |
# if ((defined (__CYGWIN__) || defined (__MINGW32__)) && \
|
williamr@4
|
53 |
defined (_STLP_USE_DYNAMIC_LIB) && !defined (__BUILDING_STLPORT)) || (defined (__SYMBIAN32__) && defined(_STLP_DESIGNATED_DLL))
|
williamr@4
|
54 |
/*
|
williamr@4
|
55 |
* Under cygwin, when STLport is used as a shared library, the id needs
|
williamr@4
|
56 |
* to be specified as imported otherwise they will be duplicated in the
|
williamr@4
|
57 |
* calling executable.
|
williamr@4
|
58 |
*/
|
williamr@4
|
59 |
#if defined (__SYMBIAN32__)
|
williamr@4
|
60 |
template <>
|
williamr@4
|
61 |
locale::id money_get<char, istreambuf_iterator<char, char_traits<char> > >::id; //_STLP_DECLSPEC removed; data should not be exported in symbian.
|
williamr@4
|
62 |
/*
|
williamr@4
|
63 |
template <>
|
williamr@4
|
64 |
_STLP_DECLSPEC locale::id money_get<char, const char*>::id;
|
williamr@4
|
65 |
*/
|
williamr@4
|
66 |
|
williamr@4
|
67 |
template <>
|
williamr@4
|
68 |
locale::id money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
|
williamr@4
|
69 |
template <>
|
williamr@4
|
70 |
locale::id money_put<char, char*>::id;
|
williamr@4
|
71 |
|
williamr@4
|
72 |
# if !defined (_STLP_NO_WCHAR_T)
|
williamr@4
|
73 |
template <>
|
williamr@4
|
74 |
locale::id money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
|
williamr@4
|
75 |
template <>
|
williamr@4
|
76 |
locale::id money_get<wchar_t, const wchar_t*>::id;
|
williamr@4
|
77 |
|
williamr@4
|
78 |
template <>
|
williamr@4
|
79 |
locale::id money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
|
williamr@4
|
80 |
template <>
|
williamr@4
|
81 |
locale::id money_put<wchar_t, wchar_t*>::id;
|
williamr@4
|
82 |
# endif /* _STLP_NO_WCHAR_T */
|
williamr@4
|
83 |
|
williamr@4
|
84 |
#else
|
williamr@4
|
85 |
template <>
|
williamr@4
|
86 |
_STLP_DECLSPEC locale::id money_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
|
williamr@4
|
87 |
/*
|
williamr@4
|
88 |
template <>
|
williamr@4
|
89 |
_STLP_DECLSPEC locale::id money_get<char, const char*>::id;
|
williamr@4
|
90 |
*/
|
williamr@4
|
91 |
|
williamr@4
|
92 |
template <>
|
williamr@4
|
93 |
_STLP_DECLSPEC locale::id money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
|
williamr@4
|
94 |
template <>
|
williamr@4
|
95 |
_STLP_DECLSPEC locale::id money_put<char, char*>::id;
|
williamr@4
|
96 |
|
williamr@4
|
97 |
# if !defined (_STLP_NO_WCHAR_T)
|
williamr@4
|
98 |
template <>
|
williamr@4
|
99 |
_STLP_DECLSPEC locale::id money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
|
williamr@4
|
100 |
template <>
|
williamr@4
|
101 |
_STLP_DECLSPEC locale::id money_get<wchar_t, const wchar_t*>::id;
|
williamr@4
|
102 |
|
williamr@4
|
103 |
template <>
|
williamr@4
|
104 |
_STLP_DECLSPEC locale::id money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
|
williamr@4
|
105 |
template <>
|
williamr@4
|
106 |
_STLP_DECLSPEC locale::id money_put<wchar_t, wchar_t*>::id;
|
williamr@4
|
107 |
# endif /* _STLP_NO_WCHAR_T */
|
williamr@4
|
108 |
|
williamr@2
|
109 |
#endif
|
williamr@2
|
110 |
|
williamr@4
|
111 |
#endif /* (defined (__CYGWIN__) || defined (__MINGW32__)) */
|
williamr@4
|
112 |
#endif /* __SYMBIAN32__WSD__ */
|
williamr@4
|
113 |
|
williamr@4
|
114 |
#else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
|
williamr@4
|
115 |
|
williamr@4
|
116 |
//typedef money_get<char, const char*> money_get_char;
|
williamr@4
|
117 |
//typedef money_put<char, char*> money_put_char;
|
williamr@2
|
118 |
typedef money_get<char, istreambuf_iterator<char, char_traits<char> > > money_get_char_2;
|
williamr@2
|
119 |
typedef money_put<char, ostreambuf_iterator<char, char_traits<char> > > money_put_char_2;
|
williamr@2
|
120 |
|
williamr@4
|
121 |
//__DECLARE_INSTANCE(locale::id, money_get_char::id, );
|
williamr@4
|
122 |
//__DECLARE_INSTANCE(locale::id, money_put_char::id, );
|
williamr@2
|
123 |
__DECLARE_INSTANCE(locale::id, money_get_char_2::id, );
|
williamr@2
|
124 |
__DECLARE_INSTANCE(locale::id, money_put_char_2::id, );
|
williamr@2
|
125 |
|
williamr@4
|
126 |
# ifndef _STLP_NO_WCHAR_T
|
williamr@2
|
127 |
|
williamr@4
|
128 |
//typedef money_get<wchar_t, const wchar_t*> money_get_wchar_t;
|
williamr@4
|
129 |
//typedef money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > money_get_wchar_t_2;
|
williamr@2
|
130 |
typedef money_put<wchar_t, wchar_t*> money_put_wchar_t;
|
williamr@2
|
131 |
typedef money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > money_put_wchar_t_2;
|
williamr@2
|
132 |
|
williamr@4
|
133 |
//__DECLARE_INSTANCE(locale::id, money_get_wchar_t::id, );
|
williamr@4
|
134 |
//__DECLARE_INSTANCE(locale::id, money_put_wchar_t::id, );
|
williamr@2
|
135 |
__DECLARE_INSTANCE(locale::id, money_get_wchar_t_2::id, );
|
williamr@2
|
136 |
__DECLARE_INSTANCE(locale::id, money_put_wchar_t_2::id, );
|
williamr@2
|
137 |
|
williamr@4
|
138 |
# endif /* _STLP_NO_WCHAR_T */
|
williamr@4
|
139 |
#endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
|
williamr@2
|
140 |
|
williamr@2
|
141 |
// money_get facets
|
williamr@2
|
142 |
|
williamr@4
|
143 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@2
|
144 |
|
williamr@2
|
145 |
// helper functions for do_get
|
williamr@2
|
146 |
template <class _InIt1, class _InIt2>
|
williamr@4
|
147 |
pair<_InIt1, bool> __get_string( _InIt1 __first, _InIt1 __last,
|
williamr@4
|
148 |
_InIt2 __str_first, _InIt2 __str_last) {
|
williamr@4
|
149 |
while ( __first != __last && __str_first != __str_last && *__first == *__str_first ) {
|
williamr@4
|
150 |
++__first;
|
williamr@4
|
151 |
++__str_first;
|
williamr@4
|
152 |
}
|
williamr@4
|
153 |
return make_pair(__first, __str_first == __str_last);
|
williamr@2
|
154 |
}
|
williamr@2
|
155 |
|
williamr@2
|
156 |
template <class _InIt, class _OuIt, class _CharT>
|
williamr@2
|
157 |
bool
|
williamr@4
|
158 |
__get_monetary_value(_InIt& __first, _InIt __last, _OuIt __out_ite,
|
williamr@2
|
159 |
const ctype<_CharT>& _c_type,
|
williamr@4
|
160 |
_CharT __point, int __frac_digits, _CharT __sep,
|
williamr@4
|
161 |
const string& __grouping, bool &__syntax_ok) {
|
williamr@2
|
162 |
if (__first == __last || !_c_type.is(ctype_base::digit, *__first))
|
williamr@2
|
163 |
return false;
|
williamr@2
|
164 |
|
williamr@2
|
165 |
char __group_sizes[128];
|
williamr@4
|
166 |
char* __group_sizes_end = __grouping.empty()? 0 : __group_sizes;
|
williamr@2
|
167 |
char __current_group_size = 0;
|
williamr@2
|
168 |
|
williamr@2
|
169 |
while (__first != __last) {
|
williamr@2
|
170 |
if (_c_type.is(ctype_base::digit, *__first)) {
|
williamr@2
|
171 |
++__current_group_size;
|
williamr@4
|
172 |
*__out_ite++ = *__first++;
|
williamr@2
|
173 |
}
|
williamr@2
|
174 |
else if (__group_sizes_end) {
|
williamr@2
|
175 |
if (*__first == __sep) {
|
williamr@4
|
176 |
*__group_sizes_end++ = __current_group_size;
|
williamr@4
|
177 |
__current_group_size = 0;
|
williamr@4
|
178 |
++__first;
|
williamr@2
|
179 |
}
|
williamr@2
|
180 |
else break;
|
williamr@2
|
181 |
}
|
williamr@2
|
182 |
else
|
williamr@2
|
183 |
break;
|
williamr@2
|
184 |
}
|
williamr@2
|
185 |
|
williamr@4
|
186 |
if (__grouping.empty())
|
williamr@2
|
187 |
__syntax_ok = true;
|
williamr@2
|
188 |
else {
|
williamr@2
|
189 |
if (__group_sizes_end != __group_sizes)
|
williamr@4
|
190 |
*__group_sizes_end++ = __current_group_size;
|
williamr@4
|
191 |
|
williamr@2
|
192 |
__syntax_ok = __valid_grouping(__group_sizes, __group_sizes_end,
|
williamr@4
|
193 |
__grouping.data(), __grouping.data()+ __grouping.size());
|
williamr@4
|
194 |
|
williamr@2
|
195 |
if (__first == __last || *__first != __point) {
|
williamr@2
|
196 |
for (int __digits = 0; __digits != __frac_digits; ++__digits)
|
williamr@4
|
197 |
*__out_ite++ = _CharT('0');
|
williamr@2
|
198 |
return true; // OK not to have decimal point
|
williamr@2
|
199 |
}
|
williamr@2
|
200 |
}
|
williamr@2
|
201 |
|
williamr@4
|
202 |
++__first;
|
williamr@2
|
203 |
|
williamr@4
|
204 |
int __digits = 0;
|
williamr@2
|
205 |
|
williamr@4
|
206 |
while (__first != __last && _c_type.is(ctype_base::digit, *__first)) {
|
williamr@4
|
207 |
*__out_ite++ = *__first++;
|
williamr@4
|
208 |
++__digits;
|
williamr@2
|
209 |
}
|
williamr@2
|
210 |
|
williamr@4
|
211 |
__syntax_ok = __syntax_ok && (__digits == __frac_digits);
|
williamr@2
|
212 |
|
williamr@2
|
213 |
return true;
|
williamr@2
|
214 |
}
|
williamr@2
|
215 |
|
williamr@2
|
216 |
|
williamr@4
|
217 |
template <class _CharT, class _InputIter, class _StrType>
|
williamr@4
|
218 |
_InputIter __money_do_get(_InputIter __s, _InputIter __end, bool __intl,
|
williamr@4
|
219 |
ios_base& __str, ios_base::iostate& __err,
|
williamr@4
|
220 |
_StrType& __digits, bool &__is_positive, _CharT* /*__dummy*/) {
|
williamr@2
|
221 |
if (__s == __end) {
|
williamr@2
|
222 |
__err |= ios_base::eofbit;
|
williamr@2
|
223 |
return __s;
|
williamr@2
|
224 |
}
|
williamr@2
|
225 |
|
williamr@4
|
226 |
typedef _CharT char_type;
|
williamr@4
|
227 |
typedef _StrType string_type;
|
williamr@4
|
228 |
typedef _InputIter iter_type;
|
williamr@4
|
229 |
typedef moneypunct<char_type, false> _Punct;
|
williamr@4
|
230 |
typedef moneypunct<char_type, true> _Punct_intl;
|
williamr@4
|
231 |
typedef ctype<char_type> _Ctype;
|
williamr@2
|
232 |
|
williamr@2
|
233 |
locale __loc = __str.getloc();
|
williamr@2
|
234 |
const _Punct& __punct = use_facet<_Punct>(__loc) ;
|
williamr@2
|
235 |
const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ;
|
williamr@4
|
236 |
const _Ctype& __c_type = use_facet<_Ctype>(__loc) ;
|
williamr@4
|
237 |
|
williamr@2
|
238 |
money_base::pattern __format = __intl ? __punct_intl.neg_format()
|
williamr@2
|
239 |
: __punct.neg_format();
|
williamr@2
|
240 |
string_type __ns = __intl ? __punct_intl.negative_sign()
|
williamr@2
|
241 |
: __punct.negative_sign();
|
williamr@2
|
242 |
string_type __ps = __intl ? __punct_intl.positive_sign()
|
williamr@2
|
243 |
: __punct.positive_sign();
|
williamr@2
|
244 |
int __i;
|
williamr@4
|
245 |
bool __symbol_required = (__str.flags() & ios_base::showbase) != 0;
|
williamr@2
|
246 |
string_type __buf;
|
williamr@4
|
247 |
back_insert_iterator<string_type> __out_ite(__buf);
|
williamr@2
|
248 |
|
williamr@2
|
249 |
for (__i = 0; __i < 4; ++__i) {
|
williamr@2
|
250 |
switch (__format.field[__i]) {
|
williamr@4
|
251 |
case money_base::none:
|
williamr@2
|
252 |
if (__i == 3) {
|
williamr@4
|
253 |
if (__c_type.is(ctype_base::space, *__s)) {
|
williamr@2
|
254 |
__err = ios_base::failbit;
|
williamr@2
|
255 |
return __s;
|
williamr@2
|
256 |
}
|
williamr@4
|
257 |
break;
|
williamr@2
|
258 |
}
|
williamr@2
|
259 |
while (__s != __end && __c_type.is(ctype_base::space, *__s))
|
williamr@2
|
260 |
++__s;
|
williamr@2
|
261 |
break;
|
williamr@4
|
262 |
case money_base::space:
|
williamr@2
|
263 |
if (!__c_type.is(ctype_base::space, *__s)) {
|
williamr@2
|
264 |
__err = ios_base::failbit;
|
williamr@2
|
265 |
return __s;
|
williamr@2
|
266 |
}
|
williamr@2
|
267 |
++__s;
|
williamr@2
|
268 |
while (__s != __end && __c_type.is(ctype_base::space, *__s))
|
williamr@2
|
269 |
++__s;
|
williamr@2
|
270 |
break;
|
williamr@2
|
271 |
case money_base::symbol: {
|
williamr@2
|
272 |
string_type __curs = __intl ? __punct_intl.curr_symbol()
|
williamr@4
|
273 |
: __punct.curr_symbol();
|
williamr@2
|
274 |
pair<iter_type, bool>
|
williamr@2
|
275 |
__result = __get_string(__s, __end, __curs.begin(), __curs.end());
|
williamr@2
|
276 |
if (!__result.second && __symbol_required)
|
williamr@2
|
277 |
__err = ios_base::failbit;
|
williamr@2
|
278 |
__s = __result.first;
|
williamr@2
|
279 |
break;
|
williamr@2
|
280 |
}
|
williamr@2
|
281 |
case money_base::sign: {
|
williamr@2
|
282 |
if (__s == __end) {
|
williamr@4
|
283 |
if (__ps.empty())
|
williamr@2
|
284 |
break;
|
williamr@4
|
285 |
if (__ns.empty()) {
|
williamr@2
|
286 |
__is_positive = false;
|
williamr@2
|
287 |
break;
|
williamr@2
|
288 |
}
|
williamr@2
|
289 |
__err = ios_base::failbit;
|
williamr@2
|
290 |
return __s;
|
williamr@2
|
291 |
}
|
williamr@2
|
292 |
else {
|
williamr@4
|
293 |
if (__ps.empty()) {
|
williamr@4
|
294 |
if (__ns.empty())
|
williamr@2
|
295 |
break;
|
williamr@2
|
296 |
if (*__s == __ns[0]) {
|
williamr@2
|
297 |
++__s;
|
williamr@2
|
298 |
__is_positive = false;
|
williamr@2
|
299 |
}
|
williamr@4
|
300 |
break;
|
williamr@4
|
301 |
}
|
williamr@2
|
302 |
else {
|
williamr@2
|
303 |
if (*__s == __ps[0]) {
|
williamr@2
|
304 |
++__s;
|
williamr@2
|
305 |
break;
|
williamr@2
|
306 |
}
|
williamr@4
|
307 |
if (__ns.empty())
|
williamr@2
|
308 |
break;
|
williamr@2
|
309 |
if (*__s == __ns[0]) {
|
williamr@2
|
310 |
++__s;
|
williamr@2
|
311 |
__is_positive = false;
|
williamr@2
|
312 |
break;
|
williamr@2
|
313 |
}
|
williamr@2
|
314 |
__err = ios_base::failbit;
|
williamr@2
|
315 |
}
|
williamr@2
|
316 |
}
|
williamr@2
|
317 |
return __s;
|
williamr@2
|
318 |
}
|
williamr@2
|
319 |
case money_base::value: {
|
williamr@4
|
320 |
char_type __point = __intl ? __punct_intl.decimal_point()
|
williamr@4
|
321 |
: __punct.decimal_point();
|
williamr@2
|
322 |
int __frac_digits = __intl ? __punct_intl.frac_digits()
|
williamr@2
|
323 |
: __punct.frac_digits();
|
williamr@2
|
324 |
string __grouping = __intl ? __punct_intl.grouping()
|
williamr@2
|
325 |
: __punct.grouping();
|
williamr@2
|
326 |
bool __syntax_ok = true;
|
williamr@2
|
327 |
|
williamr@2
|
328 |
bool __result;
|
williamr@2
|
329 |
|
williamr@4
|
330 |
char_type __sep = __grouping.empty() ? char_type() :
|
williamr@4
|
331 |
__intl ? __punct_intl.thousands_sep() : __punct.thousands_sep();
|
williamr@2
|
332 |
|
williamr@4
|
333 |
__result = __get_monetary_value(__s, __end, __out_ite, __c_type,
|
williamr@2
|
334 |
__point, __frac_digits,
|
williamr@2
|
335 |
__sep,
|
williamr@4
|
336 |
__grouping, __syntax_ok);
|
williamr@2
|
337 |
|
williamr@2
|
338 |
if (!__syntax_ok)
|
williamr@2
|
339 |
__err |= ios_base::failbit;
|
williamr@2
|
340 |
if (!__result) {
|
williamr@2
|
341 |
__err = ios_base::failbit;
|
williamr@2
|
342 |
return __s;
|
williamr@2
|
343 |
}
|
williamr@2
|
344 |
break;
|
williamr@4
|
345 |
|
williamr@2
|
346 |
} // Close money_base::value case
|
williamr@2
|
347 |
} // Close switch statement
|
williamr@2
|
348 |
} // Close for loop
|
williamr@2
|
349 |
|
williamr@2
|
350 |
if (__is_positive) {
|
williamr@2
|
351 |
if (__ps.size() > 1) {
|
williamr@2
|
352 |
pair<_InputIter, bool>
|
williamr@2
|
353 |
__result = __get_string(__s, __end, __ps.begin() + 1, __ps.end());
|
williamr@2
|
354 |
__s = __result.first;
|
williamr@2
|
355 |
if (!__result.second)
|
williamr@4
|
356 |
__err |= ios::failbit;
|
williamr@2
|
357 |
}
|
williamr@2
|
358 |
if (!(__err & ios_base::failbit))
|
williamr@2
|
359 |
__digits = __buf;
|
williamr@2
|
360 |
}
|
williamr@2
|
361 |
else {
|
williamr@2
|
362 |
if (__ns.size() > 1) {
|
williamr@2
|
363 |
pair<_InputIter, bool>
|
williamr@2
|
364 |
__result = __get_string(__s, __end, __ns.begin() + 1, __ns.end());
|
williamr@2
|
365 |
__s = __result.first;
|
williamr@2
|
366 |
if (!__result.second)
|
williamr@4
|
367 |
__err |= ios::failbit;
|
williamr@2
|
368 |
}
|
williamr@4
|
369 |
if (!(__err & ios::failbit)) {
|
williamr@4
|
370 |
__digits = __c_type.widen('-');
|
williamr@4
|
371 |
__digits += __buf;
|
williamr@2
|
372 |
}
|
williamr@2
|
373 |
}
|
williamr@2
|
374 |
if (__s == __end)
|
williamr@2
|
375 |
__err |= ios::eofbit;
|
williamr@2
|
376 |
|
williamr@2
|
377 |
return __s;
|
williamr@2
|
378 |
}
|
williamr@2
|
379 |
|
williamr@4
|
380 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
381 |
|
williamr@4
|
382 |
//===== methods ======
|
williamr@4
|
383 |
template <class _CharT, class _InputIter>
|
williamr@4
|
384 |
_InputIter
|
williamr@4
|
385 |
money_get<_CharT, _InputIter>::do_get(_InputIter __s, _InputIter __end, bool __intl,
|
williamr@4
|
386 |
ios_base& __str, ios_base::iostate& __err_,
|
williamr@4
|
387 |
_STLP_LONGEST_FLOAT_TYPE& __units) const {
|
williamr@4
|
388 |
ios_base::iostate __err = 0;
|
williamr@4
|
389 |
string_type __buf;
|
williamr@4
|
390 |
bool __is_positive = true;
|
williamr@4
|
391 |
__s = _STLP_PRIV __money_do_get(__s, __end, __intl, __str, __err, __buf, __is_positive, (_CharT*)0);
|
williamr@4
|
392 |
|
williamr@4
|
393 |
if (__err == ios_base::goodbit || __err == ios_base::eofbit) {
|
williamr@4
|
394 |
typename string_type::iterator __b = __buf.begin(), __e = __buf.end();
|
williamr@4
|
395 |
|
williamr@4
|
396 |
if (!__is_positive) ++__b;
|
williamr@4
|
397 |
// Can't use atold, since it might be wchar_t. Don't get confused by name below :
|
williamr@4
|
398 |
// it's perfectly capable of reading long double.
|
williamr@4
|
399 |
_STLP_PRIV __get_decimal_integer(__b, __e, __units, (_CharT*)0);
|
williamr@4
|
400 |
|
williamr@4
|
401 |
if (!__is_positive) {
|
williamr@4
|
402 |
__units = -__units;
|
williamr@4
|
403 |
}
|
williamr@4
|
404 |
}
|
williamr@4
|
405 |
if ( (__err & ios_base::failbit == 1) || (__err & ios_base::eofbit == 1) ) {
|
williamr@4
|
406 |
__err_ |= __err;
|
williamr@4
|
407 |
}
|
williamr@4
|
408 |
return __s;
|
williamr@4
|
409 |
}
|
williamr@4
|
410 |
|
williamr@4
|
411 |
template <class _CharT, class _InputIter>
|
williamr@4
|
412 |
_InputIter
|
williamr@4
|
413 |
money_get<_CharT, _InputIter>::do_get(iter_type __s, iter_type __end, bool __intl,
|
williamr@4
|
414 |
ios_base& __str, ios_base::iostate& __err,
|
williamr@4
|
415 |
string_type& __digits) const {
|
williamr@4
|
416 |
bool __is_positive = true;
|
williamr@4
|
417 |
return _STLP_PRIV __money_do_get(__s, __end, __intl, __str, __err, __digits, __is_positive, (_CharT*)0);
|
williamr@4
|
418 |
}
|
williamr@4
|
419 |
|
williamr@2
|
420 |
// money_put facets
|
williamr@2
|
421 |
|
williamr@4
|
422 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
423 |
|
williamr@4
|
424 |
template <class _CharT, class _OutputIter, class _Str_Type, class _Str>
|
williamr@4
|
425 |
_OutputIter __money_do_put(_OutputIter __s, bool __intl, ios_base& __str,
|
williamr@4
|
426 |
_CharT __fill, const _Str& __digits, bool __check_digits,
|
williamr@4
|
427 |
_Str_Type * /*__dummy*/) {
|
williamr@4
|
428 |
typedef _CharT char_type;
|
williamr@4
|
429 |
typedef _Str_Type string_type;
|
williamr@4
|
430 |
typedef ctype<char_type> _Ctype;
|
williamr@4
|
431 |
typedef moneypunct<char_type, false> _Punct;
|
williamr@4
|
432 |
typedef moneypunct<char_type, true> _Punct_intl;
|
williamr@2
|
433 |
|
williamr@2
|
434 |
locale __loc = __str.getloc();
|
williamr@4
|
435 |
const _Ctype& __c_type = use_facet<_Ctype>(__loc) ;
|
williamr@2
|
436 |
const _Punct& __punct = use_facet<_Punct>(__loc) ;
|
williamr@2
|
437 |
const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ;
|
williamr@2
|
438 |
|
williamr@2
|
439 |
// some special characters
|
williamr@2
|
440 |
char_type __minus = __c_type.widen('-');
|
williamr@2
|
441 |
char_type __plus = __c_type.widen('+');
|
williamr@2
|
442 |
char_type __space = __c_type.widen(' ');
|
williamr@2
|
443 |
char_type __zero = __c_type.widen('0');
|
williamr@4
|
444 |
char_type __point = __intl ? __punct_intl.decimal_point()
|
williamr@4
|
445 |
: __punct.decimal_point();
|
williamr@2
|
446 |
|
williamr@2
|
447 |
char_type __sep = __intl ? __punct_intl.thousands_sep()
|
williamr@4
|
448 |
: __punct.thousands_sep();
|
williamr@2
|
449 |
|
williamr@2
|
450 |
string __grouping = __intl ? __punct_intl.grouping()
|
williamr@4
|
451 |
: __punct.grouping();
|
williamr@4
|
452 |
|
williamr@4
|
453 |
int __frac_digits = __intl ? __punct_intl.frac_digits()
|
williamr@2
|
454 |
: __punct.frac_digits();
|
williamr@2
|
455 |
|
williamr@4
|
456 |
string_type __curr_sym = __intl ? __punct_intl.curr_symbol()
|
williamr@2
|
457 |
: __punct.curr_symbol();
|
williamr@2
|
458 |
|
williamr@4
|
459 |
// if there are no digits we are going to return __s. If there
|
williamr@4
|
460 |
// are digits, but not enough to fill the frac_digits, we are
|
williamr@4
|
461 |
// going to add zeros. I don't know whether this is right or
|
williamr@4
|
462 |
// not.
|
williamr@4
|
463 |
if (__digits.empty())
|
williamr@2
|
464 |
return __s;
|
williamr@2
|
465 |
|
williamr@2
|
466 |
typename string_type::const_iterator __digits_first = __digits.begin();
|
williamr@2
|
467 |
typename string_type::const_iterator __digits_last = __digits.end();
|
williamr@2
|
468 |
|
williamr@2
|
469 |
bool __is_negative = *__digits_first == __minus;
|
williamr@2
|
470 |
if (__is_negative)
|
williamr@2
|
471 |
++__digits_first;
|
williamr@2
|
472 |
|
williamr@4
|
473 |
#if !defined (__BORLANDC__)
|
williamr@4
|
474 |
string_type __sign = __intl ? __is_negative ? __punct_intl.negative_sign()
|
williamr@4
|
475 |
: __punct_intl.positive_sign()
|
williamr@4
|
476 |
: __is_negative ? __punct.negative_sign()
|
williamr@4
|
477 |
: __punct.positive_sign();
|
williamr@4
|
478 |
#else
|
williamr@4
|
479 |
string_type __sign;
|
williamr@4
|
480 |
if (__intl) {
|
williamr@4
|
481 |
if (__is_negative)
|
williamr@4
|
482 |
__sign = __punct_intl.negative_sign();
|
williamr@4
|
483 |
else
|
williamr@4
|
484 |
__sign = __punct_intl.positive_sign();
|
williamr@4
|
485 |
}
|
williamr@4
|
486 |
else {
|
williamr@4
|
487 |
if (__is_negative)
|
williamr@4
|
488 |
__sign = __punct.negative_sign();
|
williamr@4
|
489 |
else
|
williamr@4
|
490 |
__sign = __punct.positive_sign();
|
williamr@4
|
491 |
}
|
williamr@4
|
492 |
#endif
|
williamr@4
|
493 |
|
williamr@4
|
494 |
if (__check_digits) {
|
williamr@4
|
495 |
typename string_type::const_iterator __cp = __digits_first;
|
williamr@4
|
496 |
while (__cp != __digits_last && __c_type.is(ctype_base::digit, *__cp))
|
williamr@4
|
497 |
++__cp;
|
williamr@4
|
498 |
if (__cp == __digits_first)
|
williamr@4
|
499 |
return __s;
|
williamr@4
|
500 |
__digits_last = __cp;
|
williamr@4
|
501 |
}
|
williamr@2
|
502 |
|
williamr@2
|
503 |
// If grouping is required, we make a copy of __digits and
|
williamr@2
|
504 |
// insert the grouping.
|
williamr@4
|
505 |
_STLP_BASIC_IOSTRING(char_type) __new_digits;
|
williamr@4
|
506 |
if (!__grouping.empty()) {
|
williamr@4
|
507 |
__new_digits.assign(__digits_first, __digits_last);
|
williamr@4
|
508 |
__insert_grouping(__new_digits,
|
williamr@4
|
509 |
__new_digits.size() - __frac_digits,
|
williamr@4
|
510 |
__grouping,
|
williamr@4
|
511 |
__sep, __plus, __minus, 0);
|
williamr@4
|
512 |
__digits_first = __new_digits.begin(); // <<--
|
williamr@4
|
513 |
__digits_last = __new_digits.end(); // <<--
|
williamr@2
|
514 |
}
|
williamr@2
|
515 |
|
williamr@4
|
516 |
// Determine the amount of padding required, if any.
|
williamr@4
|
517 |
streamsize __width = __str.width();
|
williamr@2
|
518 |
|
williamr@4
|
519 |
#if defined (_STLP_DEBUG) && (defined(__HP_aCC) && (__HP_aCC <= 1))
|
williamr@2
|
520 |
size_t __value_length = operator -(__digits_last, __digits_first);
|
williamr@2
|
521 |
#else
|
williamr@2
|
522 |
size_t __value_length = __digits_last - __digits_first;
|
williamr@2
|
523 |
#endif
|
williamr@2
|
524 |
|
williamr@4
|
525 |
size_t __length = __value_length + __sign.size();
|
williamr@4
|
526 |
|
williamr@2
|
527 |
if (__frac_digits != 0)
|
williamr@2
|
528 |
++__length;
|
williamr@2
|
529 |
|
williamr@2
|
530 |
bool __generate_curr = (__str.flags() & ios_base::showbase) !=0;
|
williamr@2
|
531 |
if (__generate_curr)
|
williamr@2
|
532 |
__length += __curr_sym.size();
|
williamr@4
|
533 |
money_base::pattern __format = __intl ? (__is_negative ? __punct_intl.neg_format()
|
williamr@4
|
534 |
: __punct_intl.pos_format())
|
williamr@4
|
535 |
: (__is_negative ? __punct.neg_format()
|
williamr@4
|
536 |
: __punct.pos_format());
|
williamr@2
|
537 |
{
|
williamr@4
|
538 |
//For the moment the following is commented for decoding reason.
|
williamr@4
|
539 |
//No reason to add a space last if the money symbol do not have to be display
|
williamr@4
|
540 |
//if (__format.field[3] == (char) money_base::symbol && !__generate_curr) {
|
williamr@4
|
541 |
// if (__format.field[2] == (char) money_base::space) {
|
williamr@4
|
542 |
// __format.field[2] = (char) money_base::none;
|
williamr@4
|
543 |
// }
|
williamr@4
|
544 |
//}
|
williamr@4
|
545 |
//space can only be second or third and only once (22.2.6.3-1):
|
williamr@4
|
546 |
if ((__format.field[1] == (char) money_base::space) ||
|
williamr@4
|
547 |
(__format.field[2] == (char) money_base::space))
|
williamr@4
|
548 |
++__length;
|
williamr@2
|
549 |
}
|
williamr@2
|
550 |
|
williamr@4
|
551 |
const bool __need_fill = (((sizeof(streamsize) > sizeof(size_t)) && (__STATIC_CAST(streamsize, __length) < __width)) ||
|
williamr@4
|
552 |
((sizeof(streamsize) <= sizeof(size_t)) && (__length < __STATIC_CAST(size_t, __width))));
|
williamr@4
|
553 |
streamsize __fill_amt = __need_fill ? __width - __length : 0;
|
williamr@2
|
554 |
|
williamr@2
|
555 |
ios_base::fmtflags __fill_pos = __str.flags() & ios_base::adjustfield;
|
williamr@2
|
556 |
|
williamr@2
|
557 |
if (__fill_amt != 0 &&
|
williamr@2
|
558 |
!(__fill_pos & (ios_base::left | ios_base::internal)))
|
williamr@4
|
559 |
__s = __fill_n(__s, __fill_amt, __fill);
|
williamr@4
|
560 |
|
williamr@2
|
561 |
for (int __i = 0; __i < 4; ++__i) {
|
williamr@2
|
562 |
char __ffield = __format.field[__i];
|
williamr@4
|
563 |
switch (__ffield) {
|
williamr@4
|
564 |
case money_base::none:
|
williamr@4
|
565 |
if (__fill_amt != 0 && __fill_pos == ios_base::internal)
|
williamr@4
|
566 |
__s = __fill_n(__s, __fill_amt, __fill);
|
williamr@4
|
567 |
break;
|
williamr@4
|
568 |
case money_base::space:
|
williamr@4
|
569 |
if( !__need_fill )
|
williamr@4
|
570 |
{
|
williamr@4
|
571 |
*__s++ = __space;
|
williamr@4
|
572 |
}
|
williamr@4
|
573 |
else
|
williamr@4
|
574 |
{
|
williamr@4
|
575 |
*__s++ = __fill;
|
williamr@4
|
576 |
}
|
williamr@4
|
577 |
if (__fill_amt != 0 && __fill_pos == ios_base::internal)
|
williamr@4
|
578 |
__s = __fill_n(__s, __fill_amt, __fill);
|
williamr@4
|
579 |
break;
|
williamr@4
|
580 |
case money_base::symbol:
|
williamr@4
|
581 |
if (__generate_curr)
|
williamr@4
|
582 |
__s = copy(__curr_sym.begin(), __curr_sym.end(), __s);
|
williamr@4
|
583 |
break;
|
williamr@4
|
584 |
case money_base::sign:
|
williamr@4
|
585 |
if (!__sign.empty())
|
williamr@4
|
586 |
*__s++ = __sign[0];
|
williamr@4
|
587 |
break;
|
williamr@4
|
588 |
case money_base::value:
|
williamr@4
|
589 |
if (__frac_digits == 0) {
|
williamr@2
|
590 |
__s = copy(__digits_first, __digits_last, __s);
|
williamr@4
|
591 |
} else {
|
williamr@4
|
592 |
if ((int)__value_length <= __frac_digits) {
|
williamr@4
|
593 |
// if we see '9' here, we should out 0.09
|
williamr@4
|
594 |
*__s++ = __zero; // integer part is zero
|
williamr@4
|
595 |
*__s++ = __point; // decimal point
|
williamr@4
|
596 |
__s = __fill_n(__s, __frac_digits - __value_length, __zero); // zeros
|
williamr@4
|
597 |
__s = copy(__digits_first, __digits_last, __s); // digits
|
williamr@4
|
598 |
} else {
|
williamr@4
|
599 |
__s = copy(__digits_first, __digits_last - __frac_digits, __s);
|
williamr@4
|
600 |
if (__frac_digits != 0) {
|
williamr@4
|
601 |
*__s++ = __point;
|
williamr@4
|
602 |
__s = copy(__digits_last - __frac_digits, __digits_last, __s);
|
williamr@4
|
603 |
}
|
williamr@2
|
604 |
}
|
williamr@2
|
605 |
}
|
williamr@4
|
606 |
break;
|
williamr@4
|
607 |
} //Close for switch
|
williamr@2
|
608 |
} // Close for loop
|
williamr@2
|
609 |
|
williamr@2
|
610 |
// Ouput rest of sign if necessary.
|
williamr@2
|
611 |
if (__sign.size() > 1)
|
williamr@2
|
612 |
__s = copy(__sign.begin() + 1, __sign.end(), __s);
|
williamr@4
|
613 |
if (__fill_amt != 0 &&
|
williamr@4
|
614 |
!(__fill_pos & (ios_base::right | ios_base::internal)))
|
williamr@4
|
615 |
__s = __fill_n(__s, __fill_amt, __fill);
|
williamr@4
|
616 |
|
williamr@2
|
617 |
return __s;
|
williamr@2
|
618 |
}
|
williamr@2
|
619 |
|
williamr@4
|
620 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@2
|
621 |
|
williamr@4
|
622 |
template <class _CharT, class _OutputIter>
|
williamr@4
|
623 |
_OutputIter
|
williamr@4
|
624 |
money_put<_CharT, _OutputIter>
|
williamr@4
|
625 |
::do_put(_OutputIter __s, bool __intl, ios_base& __str,
|
williamr@4
|
626 |
char_type __fill, _STLP_LONGEST_FLOAT_TYPE __units) const {
|
williamr@4
|
627 |
_STLP_BASIC_IOSTRING(char_type) __digits;
|
williamr@4
|
628 |
_STLP_PRIV __get_money_digits(__digits, __str, __units);
|
williamr@4
|
629 |
return _STLP_PRIV __money_do_put(__s, __intl, __str, __fill, __digits, false, __STATIC_CAST(string_type*, 0));
|
williamr@2
|
630 |
}
|
williamr@2
|
631 |
|
williamr@4
|
632 |
template <class _CharT, class _OutputIter>
|
williamr@4
|
633 |
_OutputIter
|
williamr@4
|
634 |
money_put<_CharT, _OutputIter>
|
williamr@4
|
635 |
::do_put(_OutputIter __s, bool __intl, ios_base& __str,
|
williamr@4
|
636 |
char_type __fill, const string_type& __digits) const {
|
williamr@4
|
637 |
return _STLP_PRIV __money_do_put(__s, __intl, __str, __fill, __digits, true, __STATIC_CAST(string_type*, 0));
|
williamr@2
|
638 |
}
|
williamr@2
|
639 |
|
williamr@2
|
640 |
_STLP_END_NAMESPACE
|
williamr@2
|
641 |
|
williamr@4
|
642 |
#endif /* _STLP_MONETARY_C */
|
williamr@2
|
643 |
|
williamr@4
|
644 |
// Local Variables:
|
williamr@4
|
645 |
// mode:C++
|
williamr@4
|
646 |
// End:
|