]>
Commit | Line | Data |
---|---|---|
725dc051 BK |
1 | // Locale support -*- C++ -*- |
2 | ||
e6686813 | 3 | // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 |
4b9aaf63 | 4 | // Free Software Foundation, Inc. |
725dc051 BK |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 2, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING. If not, write to the Free | |
19 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
20 | // USA. | |
21 | ||
22 | // As a special exception, you may use this file as part of a free software | |
23 | // library without restriction. Specifically, if other files instantiate | |
24 | // templates or use macros or inline functions from this file, or you compile | |
25 | // this file and link it with other files to produce an executable, this | |
26 | // file does not by itself cause the resulting executable to be covered by | |
27 | // the GNU General Public License. This exception does not however | |
28 | // invalidate any other reasons why the executable file might be covered by | |
29 | // the GNU General Public License. | |
30 | ||
5b1a7610 | 31 | // Warning: this file is not meant for user inclusion. Use <locale>. |
725dc051 | 32 | |
3d7c150e BK |
33 | #ifndef _LOCALE_FACETS_TCC |
34 | #define _LOCALE_FACETS_TCC 1 | |
725dc051 | 35 | |
3b794528 BK |
36 | #pragma GCC system_header |
37 | ||
e6686813 BK |
38 | #include <limits> // For numeric_limits |
39 | #include <typeinfo> // For bad_cast. | |
4b9aaf63 | 40 | #include <bits/streambuf_iterator.h> |
725dc051 BK |
41 | |
42 | namespace std | |
43 | { | |
44 | template<typename _Facet> | |
45 | locale | |
ba317c52 | 46 | locale::combine(const locale& __other) const |
725dc051 | 47 | { |
1f46fc8e | 48 | _Impl* __tmp = new _Impl(*_M_impl, 1); |
155f6fbb PC |
49 | try |
50 | { | |
51 | __tmp->_M_replace_facet(__other._M_impl, &_Facet::id); | |
52 | } | |
53 | catch(...) | |
54 | { | |
55 | __tmp->_M_remove_reference(); | |
56 | __throw_exception_again; | |
57 | } | |
13f83598 | 58 | return locale(__tmp); |
725dc051 BK |
59 | } |
60 | ||
61 | template<typename _CharT, typename _Traits, typename _Alloc> | |
62 | bool | |
63 | locale::operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1, | |
64 | const basic_string<_CharT, _Traits, _Alloc>& __s2) const | |
65 | { | |
725dc051 | 66 | typedef std::collate<_CharT> __collate_type; |
86ade44c BK |
67 | const __collate_type& __collate = use_facet<__collate_type>(*this); |
68 | return (__collate.compare(__s1.data(), __s1.data() + __s1.length(), | |
69 | __s2.data(), __s2.data() + __s2.length()) < 0); | |
725dc051 BK |
70 | } |
71 | ||
72 | template<typename _Facet> | |
0cd1de6f BK |
73 | inline bool |
74 | has_facet(const locale& __loc) throw() | |
725dc051 | 75 | { |
905df1fb | 76 | const size_t __i = _Facet::id._M_id(); |
064994a3 | 77 | const locale::facet** __facets = __loc._M_impl->_M_facets; |
0cd1de6f | 78 | return (__i < __loc._M_impl->_M_facets_size && __facets[__i]); |
725dc051 BK |
79 | } |
80 | ||
81 | template<typename _Facet> | |
0cd1de6f BK |
82 | inline const _Facet& |
83 | use_facet(const locale& __loc) | |
725dc051 | 84 | { |
905df1fb | 85 | const size_t __i = _Facet::id._M_id(); |
064994a3 | 86 | const locale::facet** __facets = __loc._M_impl->_M_facets; |
0cd1de6f BK |
87 | if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i])) |
88 | __throw_bad_cast(); | |
89 | return static_cast<const _Facet&>(*__facets[__i]); | |
725dc051 BK |
90 | } |
91 | ||
215f9e28 BK |
92 | // Routine to access a cache for the facet. If the cache didn't |
93 | // exist before, it gets constructed on the fly. | |
94 | template<typename _Facet> | |
cde63840 BK |
95 | struct __use_cache |
96 | { | |
97 | const _Facet* | |
98 | operator() (const locale& __loc) const; | |
99 | }; | |
215f9e28 | 100 | |
cde63840 BK |
101 | template<typename _CharT> |
102 | struct __use_cache<__numpunct_cache<_CharT> > | |
103 | { | |
104 | const __numpunct_cache<_CharT>* | |
105 | operator() (const locale& __loc) const | |
106 | { | |
905df1fb | 107 | const size_t __i = numpunct<_CharT>::id._M_id(); |
cde63840 BK |
108 | const locale::facet** __caches = __loc._M_impl->_M_caches; |
109 | if (!__caches[__i]) | |
110 | { | |
11f10e6b | 111 | __numpunct_cache<_CharT>* __tmp = NULL; |
cde63840 BK |
112 | try |
113 | { | |
114 | __tmp = new __numpunct_cache<_CharT>; | |
115 | __tmp->_M_cache(__loc); | |
116 | } | |
117 | catch(...) | |
118 | { | |
119 | delete __tmp; | |
120 | __throw_exception_again; | |
121 | } | |
122 | __loc._M_impl->_M_install_cache(__tmp, __i); | |
123 | } | |
124 | return static_cast<const __numpunct_cache<_CharT>*>(__caches[__i]); | |
125 | } | |
126 | }; | |
725dc051 | 127 | |
1ab65677 | 128 | template<typename _CharT, typename _InIter> |
631ba05e | 129 | _InIter |
1ab65677 | 130 | num_get<_CharT, _InIter>:: |
86ade44c | 131 | _M_extract_float(_InIter __beg, _InIter __end, ios_base& __io, |
823b4f7d | 132 | ios_base::iostate& __err, string& __xtrc) const |
725dc051 | 133 | { |
7942afdc BK |
134 | typedef char_traits<_CharT> __traits_type; |
135 | typedef typename numpunct<_CharT>::__cache_type __cache_type; | |
136 | __use_cache<__cache_type> __uc; | |
137 | const locale& __loc = __io._M_getloc(); | |
138 | const __cache_type* __lc = __uc(__loc); | |
139 | const _CharT* __lit = __lc->_M_atoms_in; | |
86ade44c | 140 | |
4b9aaf63 | 141 | // First check for sign. |
f20d2b78 | 142 | if (__beg != __end) |
86ade44c | 143 | { |
f20d2b78 PC |
144 | const char_type __c = *__beg; |
145 | const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]); | |
146 | if (__plus || __traits_type::eq(__c, __lit[_S_iminus])) | |
147 | { | |
148 | __xtrc += __plus ? _S_atoms_in[_S_iplus] | |
149 | : _S_atoms_in[_S_iminus]; | |
150 | ++__beg; | |
151 | } | |
86ade44c | 152 | } |
f20d2b78 PC |
153 | |
154 | // Next, look for a zero... | |
155 | bool __found_mantissa = false; | |
156 | if (__beg != __end && __traits_type::eq(*__beg, __lit[_S_izero])) | |
823b4f7d | 157 | { |
655d7821 | 158 | __xtrc += _S_atoms_in[_S_izero]; |
f20d2b78 PC |
159 | __found_mantissa = true; |
160 | ++__beg; | |
161 | // ... and skip the additional ones. | |
162 | for (; __beg != __end | |
163 | && __traits_type::eq(*__beg, __lit[_S_izero]); ++__beg); | |
823b4f7d | 164 | } |
86ade44c BK |
165 | |
166 | // Only need acceptable digits for floating point numbers. | |
86ade44c BK |
167 | bool __found_dec = false; |
168 | bool __found_sci = false; | |
86ade44c | 169 | string __found_grouping; |
86ade44c | 170 | int __sep_pos = 0; |
7942afdc | 171 | bool __e; |
58c9703f | 172 | while (__beg != __end) |
86ade44c BK |
173 | { |
174 | // Only look in digits. | |
f20d2b78 | 175 | const char_type __c = *__beg; |
7942afdc BK |
176 | const char_type* __p = __traits_type::find(__lit + _S_izero, 10, |
177 | __c); | |
89a2fb90 | 178 | if (__p) |
86ade44c BK |
179 | { |
180 | // Try first for acceptable digit; record it if found. | |
7942afdc | 181 | __xtrc += _S_atoms_in[__p - __lit]; |
f20d2b78 | 182 | __found_mantissa = true; |
86ade44c | 183 | ++__sep_pos; |
58c9703f | 184 | ++__beg; |
86ade44c | 185 | } |
7942afdc | 186 | else if (__traits_type::eq(__c, __lc->_M_thousands_sep) |
905df1fb | 187 | && __lc->_M_use_grouping && !__found_dec) |
86ade44c BK |
188 | { |
189 | // NB: Thousands separator at the beginning of a string | |
190 | // is a no-no, as is two consecutive thousands separators. | |
191 | if (__sep_pos) | |
192 | { | |
193 | __found_grouping += static_cast<char>(__sep_pos); | |
194 | __sep_pos = 0; | |
58c9703f | 195 | ++__beg; |
86ade44c BK |
196 | } |
197 | else | |
198 | { | |
199 | __err |= ios_base::failbit; | |
200 | break; | |
201 | } | |
202 | } | |
7942afdc BK |
203 | else if (__traits_type::eq(__c, __lc->_M_decimal_point) |
204 | && !__found_dec) | |
86ade44c | 205 | { |
84eb4879 PC |
206 | // According to the standard, if no grouping chars are seen, |
207 | // no grouping check is applied. Therefore __found_grouping | |
208 | // must be adjusted only if __dec comes after some __sep. | |
209 | if (__found_grouping.size()) | |
210 | __found_grouping += static_cast<char>(__sep_pos); | |
823b4f7d | 211 | __xtrc += '.'; |
86ade44c | 212 | __found_dec = true; |
58c9703f | 213 | ++__beg; |
86ade44c | 214 | } |
7942afdc BK |
215 | else if ((__e = __traits_type::eq(__c, __lit[_S_ie]) |
216 | || __traits_type::eq(__c, __lit[_S_iE])) | |
f20d2b78 | 217 | && __found_mantissa && !__found_sci) |
86ade44c BK |
218 | { |
219 | // Scientific notation. | |
7942afdc | 220 | __xtrc += __e ? _S_atoms_in[_S_ie] : _S_atoms_in[_S_iE]; |
58c9703f PC |
221 | __found_sci = true; |
222 | ||
86ade44c | 223 | // Remove optional plus or minus sign, if they exist. |
6bf0b59c | 224 | if (++__beg != __end) |
86ade44c | 225 | { |
f20d2b78 PC |
226 | const bool __plus = __traits_type::eq(*__beg, __lit[_S_iplus]); |
227 | if (__plus || __traits_type::eq(*__beg, __lit[_S_iminus])) | |
58c9703f PC |
228 | { |
229 | __xtrc += __plus ? _S_atoms_in[_S_iplus] | |
230 | : _S_atoms_in[_S_iminus]; | |
231 | ++__beg; | |
232 | } | |
86ade44c | 233 | } |
86ade44c BK |
234 | } |
235 | else | |
236 | // Not a valid input item. | |
237 | break; | |
238 | } | |
239 | ||
240 | // Digit grouping is checked. If grouping and found_grouping don't | |
241 | // match, then get very very upset, and set failbit. | |
7942afdc | 242 | if (__lc->_M_use_grouping && __found_grouping.size()) |
86ade44c BK |
243 | { |
244 | // Add the ending grouping if a decimal wasn't found. | |
245 | if (!__found_dec) | |
246 | __found_grouping += static_cast<char>(__sep_pos); | |
7942afdc BK |
247 | |
248 | const string __grouping = __lc->_M_grouping; | |
391cfc46 | 249 | if (!std::__verify_grouping(__grouping, __found_grouping)) |
823b4f7d | 250 | __err |= ios_base::failbit; |
86ade44c BK |
251 | } |
252 | ||
7942afdc | 253 | // Finish up. |
823b4f7d | 254 | __xtrc += char(); |
86ade44c BK |
255 | if (__beg == __end) |
256 | __err |= ios_base::eofbit; | |
631ba05e | 257 | return __beg; |
725dc051 BK |
258 | } |
259 | ||
86ade44c | 260 | template<typename _CharT, typename _InIter> |
631ba05e | 261 | _InIter |
86ade44c BK |
262 | num_get<_CharT, _InIter>:: |
263 | _M_extract_int(_InIter __beg, _InIter __end, ios_base& __io, | |
5b1a7610 | 264 | ios_base::iostate& __err, string& __xtrc, int& __base) const |
86ade44c | 265 | { |
7942afdc BK |
266 | typedef char_traits<_CharT> __traits_type; |
267 | typedef typename numpunct<_CharT>::__cache_type __cache_type; | |
268 | __use_cache<__cache_type> __uc; | |
269 | const locale& __loc = __io._M_getloc(); | |
270 | const __cache_type* __lc = __uc(__loc); | |
271 | const _CharT* __lit = __lc->_M_atoms_in; | |
823b4f7d | 272 | |
823b4f7d | 273 | // NB: Iff __basefield == 0, this can change based on contents. |
a761195b | 274 | const ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield; |
86ade44c BK |
275 | if (__basefield == ios_base::oct) |
276 | __base = 8; | |
277 | else if (__basefield == ios_base::hex) | |
278 | __base = 16; | |
279 | else | |
280 | __base = 10; | |
281 | ||
f13a69ec | 282 | // First check for sign. |
f20d2b78 | 283 | if (__beg != __end) |
86ade44c | 284 | { |
f20d2b78 PC |
285 | const char_type __c = *__beg; |
286 | const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]); | |
287 | if (__plus || __traits_type::eq(__c, __lit[_S_iminus])) | |
288 | { | |
289 | __xtrc += __plus ? _S_atoms_in[_S_iplus] | |
290 | : _S_atoms_in[_S_iminus]; | |
291 | ++__beg; | |
292 | } | |
86ade44c BK |
293 | } |
294 | ||
f20d2b78 PC |
295 | // Next, look for leading zeros and check required digits for base formats. |
296 | if (__builtin_expect(__base == 10, true)) | |
86ade44c | 297 | { |
f20d2b78 PC |
298 | // Look for a zero... |
299 | if (__beg != __end && __traits_type::eq(*__beg, __lit[_S_izero])) | |
823b4f7d | 300 | { |
655d7821 | 301 | __xtrc += _S_atoms_in[_S_izero]; |
f20d2b78 PC |
302 | ++__beg; |
303 | // ... and skip the additional ones. | |
304 | for (; __beg != __end | |
305 | && __traits_type::eq(*__beg, __lit[_S_izero]); ++__beg); | |
306 | ||
307 | // Check required digits. | |
308 | if (__beg != __end && __basefield == 0) | |
309 | { | |
310 | const bool __x = __traits_type::eq(*__beg, __lit[_S_ix]); | |
311 | if (__x || __traits_type::eq(*__beg, __lit[_S_iX])) | |
823b4f7d | 312 | { |
f20d2b78 PC |
313 | __xtrc += __x ? _S_atoms_in[_S_ix] |
314 | : _S_atoms_in[_S_iX]; | |
823b4f7d | 315 | __base = 16; |
f20d2b78 | 316 | ++__beg; |
823b4f7d BK |
317 | } |
318 | else | |
319 | __base = 8; | |
f20d2b78 | 320 | } |
823b4f7d | 321 | } |
86ade44c | 322 | } |
823b4f7d | 323 | else if (__base == 16) |
86ade44c | 324 | { |
f20d2b78 | 325 | if (__beg != __end && __traits_type::eq(*__beg, __lit[_S_izero])) |
86ade44c | 326 | { |
655d7821 | 327 | __xtrc += _S_atoms_in[_S_izero]; |
f20d2b78 | 328 | |
6bf0b59c | 329 | if (++__beg != __end) |
823b4f7d | 330 | { |
f20d2b78 PC |
331 | const bool __x = __traits_type::eq(*__beg, __lit[_S_ix]); |
332 | if (__x || __traits_type::eq(*__beg, __lit[_S_iX])) | |
333 | { | |
334 | __xtrc += __x ? _S_atoms_in[_S_ix] | |
335 | : _S_atoms_in[_S_iX]; | |
336 | ++__beg; | |
337 | } | |
823b4f7d | 338 | } |
86ade44c BK |
339 | } |
340 | } | |
341 | ||
342 | // At this point, base is determined. If not hex, only allow | |
343 | // base digits as valid input. | |
a761195b | 344 | const size_t __len = __base == 16 ? _S_iend : __base; |
86ade44c | 345 | |
823b4f7d | 346 | // Extract. |
86ade44c | 347 | string __found_grouping; |
86ade44c | 348 | int __sep_pos = 0; |
f20d2b78 | 349 | for (; __beg != __end; ++__beg) |
86ade44c | 350 | { |
f20d2b78 PC |
351 | const char_type __c = *__beg; |
352 | const char_type* __p = __traits_type::find(__lit + _S_izero, | |
353 | __len, __c); | |
89a2fb90 | 354 | if (__p) |
86ade44c BK |
355 | { |
356 | // Try first for acceptable digit; record it if found. | |
7942afdc | 357 | __xtrc += _S_atoms_in[__p - __lit]; |
86ade44c | 358 | ++__sep_pos; |
86ade44c | 359 | } |
f20d2b78 PC |
360 | else if (__traits_type::eq(__c, __lc->_M_thousands_sep) |
361 | && __lc->_M_use_grouping) | |
86ade44c BK |
362 | { |
363 | // NB: Thousands separator at the beginning of a string | |
364 | // is a no-no, as is two consecutive thousands separators. | |
365 | if (__sep_pos) | |
366 | { | |
367 | __found_grouping += static_cast<char>(__sep_pos); | |
368 | __sep_pos = 0; | |
86ade44c BK |
369 | } |
370 | else | |
371 | { | |
372 | __err |= ios_base::failbit; | |
373 | break; | |
374 | } | |
375 | } | |
376 | else | |
377 | // Not a valid input item. | |
378 | break; | |
379 | } | |
380 | ||
381 | // Digit grouping is checked. If grouping and found_grouping don't | |
382 | // match, then get very very upset, and set failbit. | |
7942afdc | 383 | if (__lc->_M_use_grouping && __found_grouping.size()) |
86ade44c | 384 | { |
823b4f7d | 385 | // Add the ending grouping. |
86ade44c | 386 | __found_grouping += static_cast<char>(__sep_pos); |
7942afdc BK |
387 | |
388 | const string __grouping = __lc->_M_grouping; | |
391cfc46 | 389 | if (!std::__verify_grouping(__grouping, __found_grouping)) |
823b4f7d | 390 | __err |= ios_base::failbit; |
86ade44c BK |
391 | } |
392 | ||
5b1a7610 BK |
393 | // Finish up. |
394 | __xtrc += char(); | |
86ade44c BK |
395 | if (__beg == __end) |
396 | __err |= ios_base::eofbit; | |
631ba05e | 397 | return __beg; |
86ade44c | 398 | } |
1ab65677 | 399 | |
f5677b15 PC |
400 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
401 | // 17. Bad bool parsing | |
1ab65677 BK |
402 | template<typename _CharT, typename _InIter> |
403 | _InIter | |
404 | num_get<_CharT, _InIter>:: | |
405 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
406 | ios_base::iostate& __err, bool& __v) const | |
725dc051 | 407 | { |
1ab65677 | 408 | if (!(__io.flags() & ios_base::boolalpha)) |
725dc051 | 409 | { |
7942afdc | 410 | // Parse bool values as unsigned long. |
1ab65677 BK |
411 | // NB: We can't just call do_get(long) here, as it might |
412 | // refer to a derived class. | |
5b1a7610 | 413 | string __xtrc; |
1ab65677 | 414 | int __base; |
5b1a7610 | 415 | __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base); |
725dc051 | 416 | |
4b9aaf63 | 417 | unsigned long __ul; |
7942afdc | 418 | std::__convert_to_v(__xtrc.c_str(), __ul, __err, |
8ae81136 | 419 | _S_get_c_locale(), __base); |
4b9aaf63 BK |
420 | if (!(__err & ios_base::failbit) && __ul <= 1) |
421 | __v = __ul; | |
422 | else | |
1ab65677 BK |
423 | __err |= ios_base::failbit; |
424 | } | |
1ab65677 | 425 | else |
725dc051 | 426 | { |
7942afdc | 427 | // Parse bool values as alphanumeric. |
f13a69ec | 428 | typedef char_traits<_CharT> __traits_type; |
7942afdc BK |
429 | typedef typename numpunct<_CharT>::__cache_type __cache_type; |
430 | __use_cache<__cache_type> __uc; | |
431 | const locale& __loc = __io._M_getloc(); | |
432 | const __cache_type* __lc = __uc(__loc); | |
433 | const size_t __tn = __traits_type::length(__lc->_M_truename) - 1; | |
434 | const size_t __fn = __traits_type::length(__lc->_M_falsename) - 1; | |
86ade44c | 435 | |
7942afdc BK |
436 | bool __testf = false; |
437 | bool __testt = false; | |
86ade44c | 438 | for (size_t __n = 0; __beg != __end; ++__n) |
1ab65677 | 439 | { |
dff186db PC |
440 | const char_type __c = *__beg; |
441 | ++__beg; | |
7942afdc BK |
442 | |
443 | if (__n <= __fn) | |
444 | __testf = __traits_type::eq(__c, __lc->_M_falsename[__n]); | |
445 | ||
446 | if (__n <= __tn) | |
447 | __testt = __traits_type::eq(__c, __lc->_M_truename[__n]); | |
448 | ||
1ab65677 BK |
449 | if (!(__testf || __testt)) |
450 | { | |
451 | __err |= ios_base::failbit; | |
452 | break; | |
453 | } | |
7942afdc | 454 | else if (__testf && __n == __fn) |
1ab65677 BK |
455 | { |
456 | __v = 0; | |
457 | break; | |
458 | } | |
7942afdc | 459 | else if (__testt && __n == __tn) |
1ab65677 BK |
460 | { |
461 | __v = 1; | |
462 | break; | |
463 | } | |
464 | } | |
465 | if (__beg == __end) | |
466 | __err |= ios_base::eofbit; | |
725dc051 | 467 | } |
1ab65677 | 468 | return __beg; |
725dc051 BK |
469 | } |
470 | ||
1ab65677 BK |
471 | template<typename _CharT, typename _InIter> |
472 | _InIter | |
473 | num_get<_CharT, _InIter>:: | |
474 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
475 | ios_base::iostate& __err, long& __v) const | |
476 | { | |
5b1a7610 | 477 | string __xtrc; |
1ab65677 | 478 | int __base; |
5b1a7610 | 479 | __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base); |
8ae81136 BK |
480 | std::__convert_to_v(__xtrc.c_str(), __v, __err, |
481 | _S_get_c_locale(), __base); | |
1ab65677 BK |
482 | return __beg; |
483 | } | |
fb678854 | 484 | |
1ab65677 BK |
485 | template<typename _CharT, typename _InIter> |
486 | _InIter | |
487 | num_get<_CharT, _InIter>:: | |
488 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
86ade44c | 489 | ios_base::iostate& __err, unsigned short& __v) const |
1ab65677 | 490 | { |
5b1a7610 | 491 | string __xtrc; |
1ab65677 | 492 | int __base; |
5b1a7610 | 493 | __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base); |
4b9aaf63 | 494 | unsigned long __ul; |
8ae81136 BK |
495 | std::__convert_to_v(__xtrc.c_str(), __ul, __err, |
496 | _S_get_c_locale(), __base); | |
5b1a7610 BK |
497 | if (!(__err & ios_base::failbit) |
498 | && __ul <= numeric_limits<unsigned short>::max()) | |
4b9aaf63 BK |
499 | __v = static_cast<unsigned short>(__ul); |
500 | else | |
501 | __err |= ios_base::failbit; | |
1ab65677 BK |
502 | return __beg; |
503 | } | |
fb678854 | 504 | |
1ab65677 BK |
505 | template<typename _CharT, typename _InIter> |
506 | _InIter | |
507 | num_get<_CharT, _InIter>:: | |
508 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
86ade44c | 509 | ios_base::iostate& __err, unsigned int& __v) const |
1ab65677 | 510 | { |
5b1a7610 | 511 | string __xtrc; |
1ab65677 | 512 | int __base; |
5b1a7610 | 513 | __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base); |
4b9aaf63 | 514 | unsigned long __ul; |
8ae81136 BK |
515 | std::__convert_to_v(__xtrc.c_str(), __ul, __err, |
516 | _S_get_c_locale(), __base); | |
5b1a7610 BK |
517 | if (!(__err & ios_base::failbit) |
518 | && __ul <= numeric_limits<unsigned int>::max()) | |
4b9aaf63 BK |
519 | __v = static_cast<unsigned int>(__ul); |
520 | else | |
521 | __err |= ios_base::failbit; | |
1ab65677 BK |
522 | return __beg; |
523 | } | |
fb678854 | 524 | |
1ab65677 BK |
525 | template<typename _CharT, typename _InIter> |
526 | _InIter | |
527 | num_get<_CharT, _InIter>:: | |
528 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
86ade44c | 529 | ios_base::iostate& __err, unsigned long& __v) const |
1ab65677 | 530 | { |
5b1a7610 | 531 | string __xtrc; |
1ab65677 | 532 | int __base; |
5b1a7610 | 533 | __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base); |
8ae81136 BK |
534 | std::__convert_to_v(__xtrc.c_str(), __v, __err, |
535 | _S_get_c_locale(), __base); | |
1ab65677 | 536 | return __beg; |
69971cd8 BK |
537 | } |
538 | ||
3d7c150e | 539 | #ifdef _GLIBCXX_USE_LONG_LONG |
1ab65677 BK |
540 | template<typename _CharT, typename _InIter> |
541 | _InIter | |
542 | num_get<_CharT, _InIter>:: | |
543 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
86ade44c | 544 | ios_base::iostate& __err, long long& __v) const |
1ab65677 | 545 | { |
5b1a7610 | 546 | string __xtrc; |
1ab65677 | 547 | int __base; |
5b1a7610 | 548 | __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base); |
8ae81136 BK |
549 | std::__convert_to_v(__xtrc.c_str(), __v, __err, |
550 | _S_get_c_locale(), __base); | |
1ab65677 BK |
551 | return __beg; |
552 | } | |
69971cd8 | 553 | |
1ab65677 BK |
554 | template<typename _CharT, typename _InIter> |
555 | _InIter | |
556 | num_get<_CharT, _InIter>:: | |
557 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
558 | ios_base::iostate& __err, unsigned long long& __v) const | |
559 | { | |
5b1a7610 | 560 | string __xtrc; |
1ab65677 | 561 | int __base; |
5b1a7610 | 562 | __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base); |
8ae81136 BK |
563 | std::__convert_to_v(__xtrc.c_str(), __v, __err, |
564 | _S_get_c_locale(), __base); | |
1ab65677 | 565 | return __beg; |
69971cd8 | 566 | } |
1ab65677 | 567 | #endif |
69971cd8 | 568 | |
725dc051 | 569 | template<typename _CharT, typename _InIter> |
1ab65677 | 570 | _InIter |
725dc051 | 571 | num_get<_CharT, _InIter>:: |
86ade44c BK |
572 | do_get(iter_type __beg, iter_type __end, ios_base& __io, |
573 | ios_base::iostate& __err, float& __v) const | |
725dc051 | 574 | { |
823b4f7d BK |
575 | string __xtrc; |
576 | __xtrc.reserve(32); | |
631ba05e | 577 | __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc); |
8ae81136 BK |
578 | std::__convert_to_v(__xtrc.c_str(), __v, __err, |
579 | _S_get_c_locale()); | |
1ab65677 BK |
580 | return __beg; |
581 | } | |
725dc051 | 582 | |
725dc051 BK |
583 | template<typename _CharT, typename _InIter> |
584 | _InIter | |
585 | num_get<_CharT, _InIter>:: | |
586 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
1ab65677 | 587 | ios_base::iostate& __err, double& __v) const |
725dc051 | 588 | { |
823b4f7d BK |
589 | string __xtrc; |
590 | __xtrc.reserve(32); | |
631ba05e | 591 | __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc); |
8ae81136 | 592 | std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale()); |
725dc051 BK |
593 | return __beg; |
594 | } | |
595 | ||
596 | template<typename _CharT, typename _InIter> | |
597 | _InIter | |
598 | num_get<_CharT, _InIter>:: | |
599 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
1ab65677 | 600 | ios_base::iostate& __err, long double& __v) const |
725dc051 | 601 | { |
823b4f7d BK |
602 | string __xtrc; |
603 | __xtrc.reserve(32); | |
631ba05e | 604 | __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc); |
8ae81136 | 605 | std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale()); |
725dc051 BK |
606 | return __beg; |
607 | } | |
608 | ||
725dc051 BK |
609 | template<typename _CharT, typename _InIter> |
610 | _InIter | |
611 | num_get<_CharT, _InIter>:: | |
612 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
1ab65677 | 613 | ios_base::iostate& __err, void*& __v) const |
725dc051 | 614 | { |
7942afdc | 615 | // Prepare for hex formatted input. |
1ab65677 | 616 | typedef ios_base::fmtflags fmtflags; |
905df1fb PC |
617 | const fmtflags __fmt = __io.flags(); |
618 | const fmtflags __fmtmask = ~(ios_base::showpos | ios_base::basefield | |
619 | | ios_base::uppercase | ios_base::internal); | |
1ab65677 BK |
620 | __io.flags(__fmt & __fmtmask | (ios_base::hex | ios_base::showbase)); |
621 | ||
5b1a7610 | 622 | string __xtrc; |
725dc051 | 623 | int __base; |
5b1a7610 | 624 | __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base); |
725dc051 | 625 | |
7942afdc | 626 | // Reset from hex formatted input. |
1ab65677 | 627 | __io.flags(__fmt); |
4b9aaf63 BK |
628 | |
629 | unsigned long __ul; | |
12841eb3 | 630 | std::__convert_to_v(__xtrc.c_str(), __ul, __err, |
8ae81136 | 631 | _S_get_c_locale(), __base); |
4b9aaf63 BK |
632 | if (!(__err & ios_base::failbit)) |
633 | __v = reinterpret_cast<void*>(__ul); | |
634 | else | |
635 | __err |= ios_base::failbit; | |
725dc051 BK |
636 | return __beg; |
637 | } | |
725dc051 | 638 | |
ce3039af JQ |
639 | // For use by integer and floating-point types after they have been |
640 | // converted into a char_type string. | |
641 | template<typename _CharT, typename _OutIter> | |
642 | void | |
643 | num_put<_CharT, _OutIter>:: | |
644 | _M_pad(_CharT __fill, streamsize __w, ios_base& __io, | |
645 | _CharT* __new, const _CharT* __cs, int& __len) const | |
646 | { | |
647 | // [22.2.2.2.2] Stage 3. | |
648 | // If necessary, pad. | |
649 | __pad<_CharT, char_traits<_CharT> >::_S_pad(__io, __fill, __new, __cs, | |
650 | __w, __len, true); | |
651 | __len = static_cast<int>(__w); | |
652 | } | |
653 | ||
654 | // Forwarding functions to peel signed from unsigned integer types. | |
655 | template<typename _CharT> | |
656 | inline int | |
3c21d6e0 PC |
657 | __int_to_char(_CharT* __bufend, long __v, const _CharT* __lit, |
658 | ios_base::fmtflags __flags) | |
ce3039af JQ |
659 | { |
660 | unsigned long __ul = static_cast<unsigned long>(__v); | |
661 | bool __neg = false; | |
662 | if (__v < 0) | |
663 | { | |
664 | __ul = -__ul; | |
665 | __neg = true; | |
666 | } | |
3c21d6e0 | 667 | return __int_to_char(__bufend, __ul, __lit, __flags, __neg); |
ce3039af JQ |
668 | } |
669 | ||
670 | template<typename _CharT> | |
671 | inline int | |
3c21d6e0 PC |
672 | __int_to_char(_CharT* __bufend, unsigned long __v, const _CharT* __lit, |
673 | ios_base::fmtflags __flags) | |
674 | { return __int_to_char(__bufend, __v, __lit, __flags, false); } | |
ce3039af | 675 | |
3d7c150e | 676 | #ifdef _GLIBCXX_USE_LONG_LONG |
ce3039af JQ |
677 | template<typename _CharT> |
678 | inline int | |
3c21d6e0 PC |
679 | __int_to_char(_CharT* __bufend, long long __v, const _CharT* __lit, |
680 | ios_base::fmtflags __flags) | |
ce3039af JQ |
681 | { |
682 | unsigned long long __ull = static_cast<unsigned long long>(__v); | |
683 | bool __neg = false; | |
684 | if (__v < 0) | |
685 | { | |
686 | __ull = -__ull; | |
687 | __neg = true; | |
688 | } | |
3c21d6e0 | 689 | return __int_to_char(__bufend, __ull, __lit, __flags, __neg); |
ce3039af JQ |
690 | } |
691 | ||
692 | template<typename _CharT> | |
693 | inline int | |
3c21d6e0 PC |
694 | __int_to_char(_CharT* __bufend, unsigned long long __v, const _CharT* __lit, |
695 | ios_base::fmtflags __flags) | |
696 | { return __int_to_char(__bufend, __v, __lit, __flags, false); } | |
ce3039af JQ |
697 | #endif |
698 | ||
699 | template<typename _CharT, typename _ValueT> | |
700 | int | |
3c21d6e0 PC |
701 | __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit, |
702 | ios_base::fmtflags __flags, bool __neg) | |
ce3039af JQ |
703 | { |
704 | // Don't write base if already 0. | |
705 | const bool __showbase = (__flags & ios_base::showbase) && __v; | |
706 | const ios_base::fmtflags __basefield = __flags & ios_base::basefield; | |
a761195b | 707 | _CharT* __buf = __bufend - 1; |
ce3039af | 708 | |
d542f114 BK |
709 | if (__builtin_expect(__basefield != ios_base::oct && |
710 | __basefield != ios_base::hex, true)) | |
711 | { | |
712 | // Decimal. | |
713 | do | |
714 | { | |
715 | *__buf-- = __lit[(__v % 10) + __num_base::_S_odigits]; | |
716 | __v /= 10; | |
717 | } | |
718 | while (__v != 0); | |
719 | if (__neg) | |
720 | *__buf-- = __lit[__num_base::_S_ominus]; | |
721 | else if (__flags & ios_base::showpos) | |
722 | *__buf-- = __lit[__num_base::_S_oplus]; | |
723 | } | |
5b577977 | 724 | else if (__basefield == ios_base::oct) |
ce3039af JQ |
725 | { |
726 | // Octal. | |
727 | do | |
728 | { | |
655d7821 | 729 | *__buf-- = __lit[(__v & 0x7) + __num_base::_S_odigits]; |
ce3039af JQ |
730 | __v >>= 3; |
731 | } | |
732 | while (__v != 0); | |
733 | if (__showbase) | |
655d7821 | 734 | *__buf-- = __lit[__num_base::_S_odigits]; |
ce3039af | 735 | } |
d542f114 | 736 | else |
ce3039af JQ |
737 | { |
738 | // Hex. | |
739 | const bool __uppercase = __flags & ios_base::uppercase; | |
905df1fb PC |
740 | const int __case_offset = __uppercase ? __num_base::_S_oudigits |
741 | : __num_base::_S_odigits; | |
ce3039af JQ |
742 | do |
743 | { | |
744 | *__buf-- = __lit[(__v & 0xf) + __case_offset]; | |
745 | __v >>= 4; | |
746 | } | |
747 | while (__v != 0); | |
748 | if (__showbase) | |
749 | { | |
750 | // 'x' or 'X' | |
655d7821 | 751 | *__buf-- = __lit[__num_base::_S_ox + __uppercase]; |
ce3039af | 752 | // '0' |
655d7821 | 753 | *__buf-- = __lit[__num_base::_S_odigits]; |
ce3039af JQ |
754 | } |
755 | } | |
a761195b | 756 | return __bufend - __buf - 1; |
ce3039af JQ |
757 | } |
758 | ||
759 | template<typename _CharT, typename _OutIter> | |
760 | void | |
761 | num_put<_CharT, _OutIter>:: | |
762 | _M_group_int(const string& __grouping, _CharT __sep, ios_base& __io, | |
763 | _CharT* __new, _CharT* __cs, int& __len) const | |
764 | { | |
c2466393 | 765 | // By itself __add_grouping cannot deal correctly with __cs when |
ce3039af JQ |
766 | // ios::showbase is set and ios_base::oct || ios_base::hex. |
767 | // Therefore we take care "by hand" of the initial 0, 0x or 0X. | |
768 | // However, remember that the latter do not occur if the number | |
769 | // printed is '0' (__len == 1). | |
770 | streamsize __off = 0; | |
771 | const ios_base::fmtflags __basefield = __io.flags() | |
772 | & ios_base::basefield; | |
773 | if ((__io.flags() & ios_base::showbase) && __len > 1) | |
774 | if (__basefield == ios_base::oct) | |
775 | { | |
776 | __off = 1; | |
5b577977 | 777 | __new[0] = __cs[0]; |
ce3039af JQ |
778 | } |
779 | else if (__basefield == ios_base::hex) | |
780 | { | |
781 | __off = 2; | |
5b577977 PC |
782 | __new[0] = __cs[0]; |
783 | __new[1] = __cs[1]; | |
ce3039af JQ |
784 | } |
785 | _CharT* __p; | |
761faeec PC |
786 | __p = std::__add_grouping(__new + __off, __sep, __grouping.data(), |
787 | __grouping.data() + __grouping.size(), | |
7942afdc | 788 | __cs + __off, __cs + __len); |
ce3039af JQ |
789 | __len = __p - __new; |
790 | } | |
791 | ||
792 | template<typename _CharT, typename _OutIter> | |
793 | template<typename _ValueT> | |
794 | _OutIter | |
795 | num_put<_CharT, _OutIter>:: | |
7942afdc | 796 | _M_insert_int(_OutIter __s, ios_base& __io, _CharT __fill, |
ce3039af JQ |
797 | _ValueT __v) const |
798 | { | |
7942afdc | 799 | typedef typename numpunct<_CharT>::__cache_type __cache_type; |
cde63840 | 800 | __use_cache<__cache_type> __uc; |
215f9e28 | 801 | const locale& __loc = __io._M_getloc(); |
cde63840 BK |
802 | const __cache_type* __lc = __uc(__loc); |
803 | const _CharT* __lit = __lc->_M_atoms_out; | |
ce3039af | 804 | |
215f9e28 | 805 | // Long enough to hold hex, dec, and octal representations. |
a761195b | 806 | const int __ilen = 4 * sizeof(_ValueT); |
ce3039af JQ |
807 | _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
808 | * __ilen)); | |
a761195b | 809 | |
ce3039af JQ |
810 | // [22.2.2.2.2] Stage 1, numeric conversion to character. |
811 | // Result is returned right-justified in the buffer. | |
812 | int __len; | |
3c21d6e0 | 813 | __len = __int_to_char(__cs + __ilen, __v, __lit, __io.flags()); |
a761195b | 814 | __cs += __ilen - __len; |
ce3039af JQ |
815 | |
816 | // Add grouping, if necessary. | |
cde63840 | 817 | if (__lc->_M_use_grouping) |
ce3039af JQ |
818 | { |
819 | // Grouping can add (almost) as many separators as the | |
820 | // number of digits, but no more. | |
f6a7db9e PC |
821 | _CharT* __cs2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
822 | * __len * 2)); | |
cde63840 | 823 | _M_group_int(__lc->_M_grouping, __lc->_M_thousands_sep, __io, |
ce3039af JQ |
824 | __cs2, __cs, __len); |
825 | __cs = __cs2; | |
826 | } | |
827 | ||
828 | // Pad. | |
905df1fb | 829 | const streamsize __w = __io.width(); |
ce3039af JQ |
830 | if (__w > static_cast<streamsize>(__len)) |
831 | { | |
f6a7db9e PC |
832 | _CharT* __cs3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
833 | * __w)); | |
ce3039af JQ |
834 | _M_pad(__fill, __w, __io, __cs3, __cs, __len); |
835 | __cs = __cs3; | |
836 | } | |
837 | __io.width(0); | |
838 | ||
839 | // [22.2.2.2.2] Stage 4. | |
840 | // Write resulting, fully-formatted string to output iterator. | |
391cfc46 | 841 | return std::__write(__s, __cs, __len); |
ce3039af JQ |
842 | } |
843 | ||
844 | template<typename _CharT, typename _OutIter> | |
845 | void | |
846 | num_put<_CharT, _OutIter>:: | |
847 | _M_group_float(const string& __grouping, _CharT __sep, const _CharT* __p, | |
848 | _CharT* __new, _CharT* __cs, int& __len) const | |
849 | { | |
f5677b15 PC |
850 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
851 | // 282. What types does numpunct grouping refer to? | |
ce3039af JQ |
852 | // Add grouping, if necessary. |
853 | _CharT* __p2; | |
a761195b | 854 | const int __declen = __p ? __p - __cs : __len; |
761faeec PC |
855 | __p2 = std::__add_grouping(__new, __sep, __grouping.data(), |
856 | __grouping.data() + __grouping.size(), | |
391cfc46 | 857 | __cs, __cs + __declen); |
ce3039af JQ |
858 | |
859 | // Tack on decimal part. | |
860 | int __newlen = __p2 - __new; | |
861 | if (__p) | |
862 | { | |
863 | char_traits<_CharT>::copy(__p2, __p, __len - __declen); | |
864 | __newlen += __len - __declen; | |
865 | } | |
866 | __len = __newlen; | |
ce3039af JQ |
867 | } |
868 | ||
869 | // The following code uses snprintf (or sprintf(), when | |
3d7c150e | 870 | // _GLIBCXX_USE_C99 is not defined) to convert floating point values |
ce3039af JQ |
871 | // for insertion into a stream. An optimization would be to replace |
872 | // them with code that works directly on a wide buffer and then use | |
873 | // __pad to do the padding. It would be good to replace them anyway | |
874 | // to gain back the efficiency that C++ provides by knowing up front | |
875 | // the type of the values to insert. Also, sprintf is dangerous | |
876 | // since may lead to accidental buffer overruns. This | |
877 | // implementation follows the C++ standard fairly directly as | |
6d8e16a4 | 878 | // outlined in 22.2.2.2 [lib.locale.num.put] |
1ab65677 | 879 | template<typename _CharT, typename _OutIter> |
86ade44c BK |
880 | template<typename _ValueT> |
881 | _OutIter | |
882 | num_put<_CharT, _OutIter>:: | |
7942afdc | 883 | _M_insert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod, |
86ade44c BK |
884 | _ValueT __v) const |
885 | { | |
7942afdc BK |
886 | typedef typename numpunct<_CharT>::__cache_type __cache_type; |
887 | __use_cache<__cache_type> __uc; | |
888 | const locale& __loc = __io._M_getloc(); | |
889 | const __cache_type* __lc = __uc(__loc); | |
890 | ||
ce3039af JQ |
891 | // Note: digits10 is rounded down: add 1 to ensure the maximum |
892 | // available precision. Then, in general, one more 1 needs to | |
893 | // be added since, when the %{g,G} conversion specifiers are | |
894 | // chosen inside _S_format_float, the precision field is "the | |
895 | // maximum number of significant digits", *not* the "number of | |
896 | // digits to appear after the decimal point", as happens for | |
897 | // %{e,E,f,F} (C99, 7.19.6.1,4). | |
87117aa2 | 898 | const int __max_digits = numeric_limits<_ValueT>::digits10 + 2; |
6d8e16a4 | 899 | |
ce3039af JQ |
900 | // Use default precision if out of range. |
901 | streamsize __prec = __io.precision(); | |
0228de0c BK |
902 | if (__prec > static_cast<streamsize>(__max_digits)) |
903 | __prec = static_cast<streamsize>(__max_digits); | |
5dc91152 | 904 | else if (__prec < static_cast<streamsize>(0)) |
5dc91152 | 905 | __prec = static_cast<streamsize>(6); |
86ade44c | 906 | |
ce3039af JQ |
907 | // [22.2.2.2.2] Stage 1, numeric conversion to character. |
908 | int __len; | |
86ade44c BK |
909 | // Long enough for the max format spec. |
910 | char __fbuf[16]; | |
0228de0c | 911 | |
3d7c150e | 912 | #ifdef _GLIBCXX_USE_C99 |
ce3039af JQ |
913 | // First try a buffer perhaps big enough (for sure sufficient |
914 | // for non-ios_base::fixed outputs) | |
6d8e16a4 PC |
915 | int __cs_size = __max_digits * 3; |
916 | char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); | |
917 | ||
5dc91152 | 918 | _S_format_float(__io, __fbuf, __mod); |
391cfc46 | 919 | __len = std::__convert_from_v(__cs, __cs_size, __fbuf, __v, |
8ae81136 | 920 | _S_get_c_locale(), __prec); |
6d8e16a4 PC |
921 | |
922 | // If the buffer was not large enough, try again with the correct size. | |
923 | if (__len >= __cs_size) | |
924 | { | |
925 | __cs_size = __len + 1; | |
926 | __cs = static_cast<char*>(__builtin_alloca(__cs_size)); | |
391cfc46 | 927 | __len = std::__convert_from_v(__cs, __cs_size, __fbuf, __v, |
8ae81136 | 928 | _S_get_c_locale(), __prec); |
6d8e16a4 PC |
929 | } |
930 | #else | |
0228de0c BK |
931 | // Consider the possibility of long ios_base::fixed outputs |
932 | const bool __fixed = __io.flags() & ios_base::fixed; | |
933 | const int __max_exp = numeric_limits<_ValueT>::max_exponent10; | |
ce3039af | 934 | |
7942afdc | 935 | // The size of the output string is computed as follows. |
46d36062 PC |
936 | // ios_base::fixed outputs may need up to __max_exp+1 chars |
937 | // for the integer part + up to __max_digits chars for the | |
938 | // fractional part + 3 chars for sign, decimal point, '\0'. On | |
939 | // the other hand, for non-fixed outputs __max_digits*3 chars | |
940 | // are largely sufficient. | |
0228de0c | 941 | const int __cs_size = __fixed ? __max_exp + __max_digits + 4 |
46d36062 | 942 | : __max_digits * 3; |
0228de0c BK |
943 | char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); |
944 | ||
5dc91152 | 945 | _S_format_float(__io, __fbuf, __mod); |
7942afdc | 946 | __len = std::__convert_from_v(__cs, 0, __fbuf, __v, |
8ae81136 | 947 | _S_get_c_locale(), __prec); |
6d8e16a4 | 948 | #endif |
725dc051 | 949 | |
86ade44c BK |
950 | // [22.2.2.2.2] Stage 2, convert to char_type, using correct |
951 | // numpunct.decimal_point() values for '.' and adding grouping. | |
86ade44c | 952 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); |
ce3039af | 953 | |
0228de0c BK |
954 | _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
955 | * __len)); | |
86ade44c BK |
956 | __ctype.widen(__cs, __cs + __len, __ws); |
957 | ||
86ade44c | 958 | // Replace decimal point. |
ce3039af | 959 | const _CharT __cdec = __ctype.widen('.'); |
cde63840 | 960 | const _CharT __dec = __lc->_M_decimal_point; |
86ade44c | 961 | const _CharT* __p; |
ce3039af JQ |
962 | if (__p = char_traits<_CharT>::find(__ws, __len, __cdec)) |
963 | __ws[__p - __ws] = __dec; | |
86ade44c | 964 | |
2d13abcf | 965 | // Add grouping, if necessary. |
cde63840 | 966 | if (__lc->_M_use_grouping) |
86ade44c | 967 | { |
5b577977 PC |
968 | // Grouping can add (almost) as many separators as the |
969 | // number of digits, but no more. | |
f6a7db9e PC |
970 | _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
971 | * __len * 2)); | |
5b577977 PC |
972 | _M_group_float(__lc->_M_grouping, __lc->_M_thousands_sep, __p, |
973 | __ws2, __ws, __len); | |
974 | __ws = __ws2; | |
86ade44c | 975 | } |
725dc051 | 976 | |
ce3039af | 977 | // Pad. |
905df1fb | 978 | const streamsize __w = __io.width(); |
86ade44c BK |
979 | if (__w > static_cast<streamsize>(__len)) |
980 | { | |
f6a7db9e PC |
981 | _CharT* __ws3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
982 | * __w)); | |
ce3039af JQ |
983 | _M_pad(__fill, __w, __io, __ws3, __ws, __len); |
984 | __ws = __ws3; | |
86ade44c BK |
985 | } |
986 | __io.width(0); | |
ce3039af | 987 | |
86ade44c BK |
988 | // [22.2.2.2.2] Stage 4. |
989 | // Write resulting, fully-formatted string to output iterator. | |
391cfc46 | 990 | return std::__write(__s, __ws, __len); |
ce3039af | 991 | } |
725dc051 | 992 | |
fb678854 | 993 | template<typename _CharT, typename _OutIter> |
725dc051 BK |
994 | _OutIter |
995 | num_put<_CharT, _OutIter>:: | |
996 | do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const | |
997 | { | |
905df1fb | 998 | const ios_base::fmtflags __flags = __io.flags(); |
725dc051 BK |
999 | if ((__flags & ios_base::boolalpha) == 0) |
1000 | { | |
1001 | unsigned long __uv = __v; | |
7942afdc | 1002 | __s = _M_insert_int(__s, __io, __fill, __uv); |
725dc051 BK |
1003 | } |
1004 | else | |
1005 | { | |
7942afdc | 1006 | typedef typename numpunct<_CharT>::__cache_type __cache_type; |
cde63840 | 1007 | __use_cache<__cache_type> __uc; |
215f9e28 | 1008 | const locale& __loc = __io._M_getloc(); |
cde63840 | 1009 | const __cache_type* __lc = __uc(__loc); |
215f9e28 | 1010 | |
7942afdc | 1011 | const _CharT* __name; |
5b577977 | 1012 | __name = __v ? __lc->_M_truename : __lc->_M_falsename; |
7942afdc | 1013 | int __len = char_traits<_CharT>::length(__name); |
ce3039af | 1014 | |
7942afdc | 1015 | _CharT* __cs; |
905df1fb | 1016 | const streamsize __w = __io.width(); |
ce3039af JQ |
1017 | if (__w > static_cast<streamsize>(__len)) |
1018 | { | |
7942afdc | 1019 | __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
ce3039af | 1020 | * __w)); |
7942afdc BK |
1021 | _M_pad(__fill, __w, __io, __cs, __name, __len); |
1022 | __name = __cs; | |
ce3039af JQ |
1023 | } |
1024 | __io.width(0); | |
7942afdc | 1025 | __s = std::__write(__s, __name, __len); |
86ade44c BK |
1026 | } |
1027 | return __s; | |
1ab65677 BK |
1028 | } |
1029 | ||
1030 | template<typename _CharT, typename _OutIter> | |
1031 | _OutIter | |
1032 | num_put<_CharT, _OutIter>:: | |
1033 | do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const | |
7942afdc | 1034 | { return _M_insert_int(__s, __io, __fill, __v); } |
1ab65677 BK |
1035 | |
1036 | template<typename _CharT, typename _OutIter> | |
1037 | _OutIter | |
1038 | num_put<_CharT, _OutIter>:: | |
1039 | do_put(iter_type __s, ios_base& __io, char_type __fill, | |
1040 | unsigned long __v) const | |
7942afdc | 1041 | { return _M_insert_int(__s, __io, __fill, __v); } |
1ab65677 | 1042 | |
3d7c150e | 1043 | #ifdef _GLIBCXX_USE_LONG_LONG |
1ab65677 BK |
1044 | template<typename _CharT, typename _OutIter> |
1045 | _OutIter | |
1046 | num_put<_CharT, _OutIter>:: | |
1047 | do_put(iter_type __s, ios_base& __b, char_type __fill, long long __v) const | |
7942afdc | 1048 | { return _M_insert_int(__s, __b, __fill, __v); } |
1ab65677 BK |
1049 | |
1050 | template<typename _CharT, typename _OutIter> | |
1051 | _OutIter | |
1052 | num_put<_CharT, _OutIter>:: | |
1053 | do_put(iter_type __s, ios_base& __io, char_type __fill, | |
1054 | unsigned long long __v) const | |
7942afdc | 1055 | { return _M_insert_int(__s, __io, __fill, __v); } |
1ab65677 BK |
1056 | #endif |
1057 | ||
1ab65677 BK |
1058 | template<typename _CharT, typename _OutIter> |
1059 | _OutIter | |
1060 | num_put<_CharT, _OutIter>:: | |
1061 | do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const | |
7942afdc | 1062 | { return _M_insert_float(__s, __io, __fill, char(), __v); } |
1ab65677 BK |
1063 | |
1064 | template<typename _CharT, typename _OutIter> | |
1065 | _OutIter | |
1066 | num_put<_CharT, _OutIter>:: | |
86ade44c BK |
1067 | do_put(iter_type __s, ios_base& __io, char_type __fill, |
1068 | long double __v) const | |
7942afdc | 1069 | { return _M_insert_float(__s, __io, __fill, 'L', __v); } |
1ab65677 BK |
1070 | |
1071 | template<typename _CharT, typename _OutIter> | |
1072 | _OutIter | |
1073 | num_put<_CharT, _OutIter>:: | |
1074 | do_put(iter_type __s, ios_base& __io, char_type __fill, | |
1075 | const void* __v) const | |
1076 | { | |
905df1fb PC |
1077 | const ios_base::fmtflags __flags = __io.flags(); |
1078 | const ios_base::fmtflags __fmt = ~(ios_base::showpos | ios_base::basefield | |
1079 | | ios_base::uppercase | ios_base::internal); | |
86ade44c BK |
1080 | __io.flags(__flags & __fmt | (ios_base::hex | ios_base::showbase)); |
1081 | try | |
1082 | { | |
7942afdc BK |
1083 | __s = _M_insert_int(__s, __io, __fill, |
1084 | reinterpret_cast<unsigned long>(__v)); | |
86ade44c BK |
1085 | __io.flags(__flags); |
1086 | } | |
1087 | catch (...) | |
1088 | { | |
1089 | __io.flags(__flags); | |
1090 | __throw_exception_again; | |
1091 | } | |
1092 | return __s; | |
1ab65677 BK |
1093 | } |
1094 | ||
1095 | ||
1096 | template<typename _CharT, typename _InIter> | |
1097 | _InIter | |
1098 | money_get<_CharT, _InIter>:: | |
1099 | do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io, | |
1100 | ios_base::iostate& __err, long double& __units) const | |
1101 | { | |
1102 | string_type __str; | |
87a9c33c | 1103 | __beg = this->do_get(__beg, __end, __intl, __io, __err, __str); |
1ab65677 | 1104 | |
761faeec PC |
1105 | const int __cs_size = __str.size() + 1; |
1106 | char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); | |
1ab65677 BK |
1107 | const locale __loc = __io.getloc(); |
1108 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
1109 | const _CharT* __wcs = __str.c_str(); | |
761faeec | 1110 | __ctype.narrow(__wcs, __wcs + __cs_size, char(), __cs); |
8ae81136 | 1111 | std::__convert_to_v(__cs, __units, __err, _S_get_c_locale()); |
1ab65677 BK |
1112 | return __beg; |
1113 | } | |
1114 | ||
1115 | template<typename _CharT, typename _InIter> | |
1116 | _InIter | |
1117 | money_get<_CharT, _InIter>:: | |
1118 | do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io, | |
1119 | ios_base::iostate& __err, string_type& __units) const | |
1120 | { | |
1121 | // These contortions are quite unfortunate. | |
1122 | typedef moneypunct<_CharT, true> __money_true; | |
1123 | typedef moneypunct<_CharT, false> __money_false; | |
1124 | typedef money_base::part part; | |
1125 | typedef typename string_type::size_type size_type; | |
1126 | ||
1127 | const locale __loc = __io.getloc(); | |
1128 | const __money_true& __mpt = use_facet<__money_true>(__loc); | |
1129 | const __money_false& __mpf = use_facet<__money_false>(__loc); | |
1130 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
1131 | ||
1132 | const money_base::pattern __p = __intl ? __mpt.neg_format() | |
1133 | : __mpf.neg_format(); | |
1134 | ||
157f3283 PC |
1135 | const string_type __pos_sign = __intl ? __mpt.positive_sign() |
1136 | : __mpf.positive_sign(); | |
1137 | const string_type __neg_sign = __intl ? __mpt.negative_sign() | |
1138 | : __mpf.negative_sign(); | |
1ab65677 BK |
1139 | const char_type __d = __intl ? __mpt.decimal_point() |
1140 | : __mpf.decimal_point(); | |
1141 | const char_type __sep = __intl ? __mpt.thousands_sep() | |
1142 | : __mpf.thousands_sep(); | |
1143 | ||
1144 | const string __grouping = __intl ? __mpt.grouping() : __mpf.grouping(); | |
1145 | ||
1146 | // Set to deduced positive or negative sign, depending. | |
1147 | string_type __sign; | |
1148 | // String of grouping info from thousands_sep plucked from __units. | |
1149 | string __grouping_tmp; | |
1150 | // Marker for thousands_sep position. | |
1151 | int __sep_pos = 0; | |
1152 | // If input iterator is in a valid state. | |
1153 | bool __testvalid = true; | |
1154 | // Flag marking when a decimal point is found. | |
1155 | bool __testdecfound = false; | |
1156 | ||
e07554eb | 1157 | // The tentative returned string is stored here. |
655d7821 | 1158 | string_type __tmp_units; |
e07554eb | 1159 | |
1ab65677 BK |
1160 | for (int __i = 0; __beg != __end && __i < 4 && __testvalid; ++__i) |
1161 | { | |
157f3283 | 1162 | char_type __c; |
905df1fb | 1163 | const part __which = static_cast<part>(__p.field[__i]); |
1ab65677 | 1164 | switch (__which) |
157f3283 PC |
1165 | { |
1166 | case money_base::symbol: | |
1167 | if (__io.flags() & ios_base::showbase | |
1168 | || __i < 2 || __sign.size() > 1 | |
1169 | || ((static_cast<part>(__p.field[3]) != money_base::none) | |
1170 | && __i == 2)) | |
1ab65677 | 1171 | { |
157f3283 PC |
1172 | // According to 22.2.6.1.2.2, symbol is required |
1173 | // if (__io.flags() & ios_base::showbase), | |
1174 | // otherwise is optional and consumed only if | |
1175 | // other characters are needed to complete the | |
1176 | // format. | |
1177 | const string_type __symbol = __intl ? __mpt.curr_symbol() | |
1178 | : __mpf.curr_symbol(); | |
1179 | const size_type __len = __symbol.size(); | |
1180 | size_type __j = 0; | |
1181 | for (; __beg != __end && __j < __len | |
1182 | && *__beg == __symbol[__j]; ++__beg, ++__j); | |
1183 | // When (__io.flags() & ios_base::showbase) | |
1184 | // symbol is required. | |
1185 | if (__j != __len && (__io.flags() & ios_base::showbase)) | |
1186 | __testvalid = false; | |
1187 | } | |
1188 | break; | |
1189 | case money_base::sign: | |
1190 | // Sign might not exist, or be more than one character long. | |
1191 | if (__pos_sign.size() && *__beg == __pos_sign[0]) | |
1192 | { | |
1193 | __sign = __pos_sign; | |
1194 | ++__beg; | |
1195 | } | |
1196 | else if (__neg_sign.size() && *__beg == __neg_sign[0]) | |
1197 | { | |
1198 | __sign = __neg_sign; | |
1199 | ++__beg; | |
1200 | } | |
1201 | else if (__pos_sign.size() && __neg_sign.size()) | |
1202 | { | |
1203 | // Sign is mandatory. | |
1204 | __testvalid = false; | |
1205 | } | |
1206 | break; | |
1207 | case money_base::value: | |
1208 | // Extract digits, remove and stash away the | |
1209 | // grouping of found thousands separators. | |
1210 | for (; __beg != __end; ++__beg) | |
1211 | if (__ctype.is(ctype_base::digit, __c = *__beg)) | |
1212 | { | |
1213 | __tmp_units += __c; | |
1214 | ++__sep_pos; | |
1215 | } | |
1216 | else if (__c == __d && !__testdecfound) | |
1217 | { | |
1218 | __grouping_tmp += static_cast<char>(__sep_pos); | |
1219 | __sep_pos = 0; | |
1220 | __testdecfound = true; | |
1221 | } | |
1222 | else if (__c == __sep) | |
1223 | { | |
1224 | if (__grouping.size()) | |
1225 | { | |
1226 | // Mark position for later analysis. | |
1227 | __grouping_tmp += static_cast<char>(__sep_pos); | |
1228 | __sep_pos = 0; | |
1229 | } | |
1230 | else | |
1231 | { | |
1ab65677 | 1232 | __testvalid = false; |
157f3283 PC |
1233 | break; |
1234 | } | |
1235 | } | |
1236 | else | |
1ab65677 | 1237 | break; |
157f3283 PC |
1238 | break; |
1239 | case money_base::space: | |
1240 | case money_base::none: | |
1241 | // Only if not at the end of the pattern. | |
1242 | if (__i != 3) | |
1243 | for (; __beg != __end | |
1244 | && __ctype.is(ctype_base::space, *__beg); ++__beg); | |
1245 | break; | |
1246 | } | |
1ab65677 | 1247 | } |
157f3283 | 1248 | |
cdd5cf72 | 1249 | // Need to get the rest of the sign characters, if they exist. |
cdd5cf72 PC |
1250 | if (__sign.size() > 1) |
1251 | { | |
1252 | const size_type __len = __sign.size(); | |
1253 | size_type __i = 1; | |
157f3283 PC |
1254 | for (; __beg != __end && __i < __len; ++__i) |
1255 | for (; __beg != __end | |
1256 | && *__beg != __sign[__i]; ++__beg); | |
cdd5cf72 PC |
1257 | |
1258 | if (__i != __len) | |
1259 | __testvalid = false; | |
1260 | } | |
1261 | ||
bf22935f | 1262 | if (__testvalid && __tmp_units.size()) |
14628700 PC |
1263 | { |
1264 | const char_type __zero = __ctype.widen('0'); | |
1265 | ||
1266 | // Strip leading zeros. | |
1267 | if (__tmp_units.size() > 1) | |
1268 | { | |
1269 | const size_type __first = __tmp_units.find_first_not_of(__zero); | |
1270 | const bool __only_zeros = __first == string_type::npos; | |
1271 | if (__first) | |
1272 | __tmp_units.erase(0, __only_zeros ? __tmp_units.size() - 1 | |
1273 | : __first); | |
1274 | } | |
bf22935f PC |
1275 | |
1276 | // 22.2.6.1.2, p4 | |
1277 | if (__sign.size() && __sign == __neg_sign | |
1278 | && __tmp_units[0] != __zero) | |
1279 | __tmp_units.insert(__tmp_units.begin(), __ctype.widen('-')); | |
14628700 | 1280 | |
bf22935f PC |
1281 | // Test for grouping fidelity. |
1282 | if (__grouping.size() && __grouping_tmp.size()) | |
14628700 | 1283 | { |
bf22935f PC |
1284 | if (!std::__verify_grouping(__grouping, __grouping_tmp)) |
1285 | __testvalid = false; | |
1286 | } | |
1287 | ||
1288 | // Iff not enough digits were supplied after the decimal-point. | |
1289 | if (__testdecfound) | |
1290 | { | |
1291 | const int __frac = __intl ? __mpt.frac_digits() | |
1292 | : __mpf.frac_digits(); | |
1293 | if (__frac > 0 && __sep_pos != __frac) | |
1294 | __testvalid = false; | |
14628700 | 1295 | } |
14628700 | 1296 | } |
bf22935f PC |
1297 | else |
1298 | __testvalid = false; | |
14628700 | 1299 | |
60aa9fc3 | 1300 | // Iff no more characters are available. |
157f3283 | 1301 | if (__beg == __end) |
60aa9fc3 | 1302 | __err |= ios_base::eofbit; |
87a7c5a1 | 1303 | |
1ab65677 | 1304 | // Iff valid sequence is not recognized. |
60aa9fc3 | 1305 | if (!__testvalid) |
1ab65677 | 1306 | __err |= ios_base::failbit; |
e07554eb | 1307 | else |
655d7821 BK |
1308 | // Use the "swap trick" to copy __tmp_units into __units. |
1309 | __tmp_units.swap(__units); | |
e07554eb | 1310 | |
1ab65677 BK |
1311 | return __beg; |
1312 | } | |
1313 | ||
1314 | template<typename _CharT, typename _OutIter> | |
1315 | _OutIter | |
1316 | money_put<_CharT, _OutIter>:: | |
1317 | do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, | |
1318 | long double __units) const | |
1319 | { | |
1320 | const locale __loc = __io.getloc(); | |
3039874b | 1321 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); |
3d7c150e | 1322 | #ifdef _GLIBCXX_USE_C99 |
6d8e16a4 PC |
1323 | // First try a buffer perhaps big enough. |
1324 | int __cs_size = 64; | |
99b629fa | 1325 | char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); |
7c752655 PC |
1326 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1327 | // 328. Bad sprintf format modifier in money_put<>::do_put() | |
1328 | int __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units, | |
8ae81136 | 1329 | _S_get_c_locale()); |
6d8e16a4 PC |
1330 | // If the buffer was not large enough, try again with the correct size. |
1331 | if (__len >= __cs_size) | |
1332 | { | |
1333 | __cs_size = __len + 1; | |
99b629fa | 1334 | __cs = static_cast<char*>(__builtin_alloca(__cs_size)); |
7c752655 | 1335 | __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units, |
8ae81136 | 1336 | _S_get_c_locale()); |
6d8e16a4 PC |
1337 | } |
1338 | #else | |
7c752655 PC |
1339 | // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'. |
1340 | const int __cs_size = numeric_limits<long double>::max_exponent10 + 3; | |
99b629fa | 1341 | char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); |
7c752655 | 1342 | int __len = std::__convert_from_v(__cs, 0, "%.0Lf", __units, |
8ae81136 | 1343 | _S_get_c_locale()); |
6d8e16a4 | 1344 | #endif |
2e2a38cd BK |
1345 | _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
1346 | * __cs_size)); | |
1ab65677 BK |
1347 | __ctype.widen(__cs, __cs + __len, __ws); |
1348 | string_type __digits(__ws); | |
1349 | return this->do_put(__s, __intl, __io, __fill, __digits); | |
1350 | } | |
1351 | ||
1352 | template<typename _CharT, typename _OutIter> | |
1353 | _OutIter | |
1354 | money_put<_CharT, _OutIter>:: | |
1355 | do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, | |
1356 | const string_type& __digits) const | |
1357 | { | |
1358 | typedef typename string_type::size_type size_type; | |
1359 | typedef money_base::part part; | |
1360 | ||
1361 | const locale __loc = __io.getloc(); | |
1362 | const size_type __width = static_cast<size_type>(__io.width()); | |
1363 | ||
1364 | // These contortions are quite unfortunate. | |
1365 | typedef moneypunct<_CharT, true> __money_true; | |
1366 | typedef moneypunct<_CharT, false> __money_false; | |
1367 | const __money_true& __mpt = use_facet<__money_true>(__loc); | |
1368 | const __money_false& __mpf = use_facet<__money_false>(__loc); | |
1369 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
1370 | ||
1371 | // Determine if negative or positive formats are to be used, and | |
1372 | // discard leading negative_sign if it is present. | |
1373 | const char_type* __beg = __digits.data(); | |
1374 | const char_type* __end = __beg + __digits.size(); | |
1375 | money_base::pattern __p; | |
1376 | string_type __sign; | |
1377 | if (*__beg != __ctype.widen('-')) | |
1378 | { | |
1379 | __p = __intl ? __mpt.pos_format() : __mpf.pos_format(); | |
a761195b | 1380 | __sign = __intl ? __mpt.positive_sign() : __mpf.positive_sign(); |
1ab65677 BK |
1381 | } |
1382 | else | |
1383 | { | |
1384 | __p = __intl ? __mpt.neg_format() : __mpf.neg_format(); | |
a761195b | 1385 | __sign = __intl ? __mpt.negative_sign() : __mpf.negative_sign(); |
1ab65677 BK |
1386 | ++__beg; |
1387 | } | |
1388 | ||
1389 | // Look for valid numbers in the current ctype facet within input digits. | |
1390 | __end = __ctype.scan_not(ctype_base::digit, __beg, __end); | |
1391 | if (__beg != __end) | |
1392 | { | |
1393 | // Assume valid input, and attempt to format. | |
1394 | // Break down input numbers into base components, as follows: | |
1395 | // final_value = grouped units + (decimal point) + (digits) | |
1396 | string_type __res; | |
1397 | string_type __value; | |
1398 | const string_type __symbol = __intl ? __mpt.curr_symbol() | |
1399 | : __mpf.curr_symbol(); | |
1400 | ||
1401 | // Deal with decimal point, decimal digits. | |
1402 | const int __frac = __intl ? __mpt.frac_digits() | |
1403 | : __mpf.frac_digits(); | |
1404 | if (__frac > 0) | |
1405 | { | |
1406 | const char_type __d = __intl ? __mpt.decimal_point() | |
1407 | : __mpf.decimal_point(); | |
1408 | if (__end - __beg >= __frac) | |
1409 | { | |
1410 | __value = string_type(__end - __frac, __end); | |
1411 | __value.insert(__value.begin(), __d); | |
1412 | __end -= __frac; | |
1413 | } | |
1414 | else | |
1415 | { | |
1416 | // Have to pad zeros in the decimal position. | |
1417 | __value = string_type(__beg, __end); | |
a761195b PC |
1418 | const int __paddec = __frac - (__end - __beg); |
1419 | const char_type __zero = __ctype.widen('0'); | |
1ab65677 BK |
1420 | __value.insert(__value.begin(), __paddec, __zero); |
1421 | __value.insert(__value.begin(), __d); | |
1422 | __beg = __end; | |
1423 | } | |
1424 | } | |
1425 | ||
1426 | // Add thousands separators to non-decimal digits, per | |
1427 | // grouping rules. | |
1428 | if (__beg != __end) | |
1429 | { | |
1430 | const string __grouping = __intl ? __mpt.grouping() | |
1431 | : __mpf.grouping(); | |
1432 | if (__grouping.size()) | |
1433 | { | |
1434 | const char_type __sep = __intl ? __mpt.thousands_sep() | |
1435 | : __mpf.thousands_sep(); | |
761faeec | 1436 | const char* __gbeg = __grouping.data(); |
1ab65677 | 1437 | const char* __gend = __gbeg + __grouping.size(); |
3039874b PC |
1438 | const int __n = (__end - __beg) * 2; |
1439 | _CharT* __ws2 = | |
2e2a38cd | 1440 | static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __n)); |
391cfc46 PC |
1441 | _CharT* __ws_end = std::__add_grouping(__ws2, __sep, __gbeg, |
1442 | __gend, __beg, __end); | |
86ade44c | 1443 | __value.insert(0, __ws2, __ws_end - __ws2); |
1ab65677 BK |
1444 | } |
1445 | else | |
1446 | __value.insert(0, string_type(__beg, __end)); | |
1447 | } | |
1448 | ||
1449 | // Calculate length of resulting string. | |
905df1fb | 1450 | const ios_base::fmtflags __f = __io.flags() & ios_base::adjustfield; |
1ab65677 BK |
1451 | size_type __len = __value.size() + __sign.size(); |
1452 | __len += (__io.flags() & ios_base::showbase) ? __symbol.size() : 0; | |
905df1fb | 1453 | const bool __testipad = __f == ios_base::internal && __len < __width; |
1ab65677 BK |
1454 | |
1455 | // Fit formatted digits into the required pattern. | |
1456 | for (int __i = 0; __i < 4; ++__i) | |
1457 | { | |
905df1fb | 1458 | const part __which = static_cast<part>(__p.field[__i]); |
1ab65677 BK |
1459 | switch (__which) |
1460 | { | |
1461 | case money_base::symbol: | |
1462 | if (__io.flags() & ios_base::showbase) | |
1463 | __res += __symbol; | |
1464 | break; | |
1465 | case money_base::sign: | |
1466 | // Sign might not exist, or be more than one | |
1467 | // charater long. In that case, add in the rest | |
1468 | // below. | |
1469 | if (__sign.size()) | |
1470 | __res += __sign[0]; | |
1471 | break; | |
1472 | case money_base::value: | |
1473 | __res += __value; | |
1474 | break; | |
1475 | case money_base::space: | |
1476 | // At least one space is required, but if internal | |
1477 | // formatting is required, an arbitrary number of | |
1478 | // fill spaces will be necessary. | |
1479 | if (__testipad) | |
1480 | __res += string_type(__width - __len, __fill); | |
1481 | else | |
577f4061 | 1482 | __res += __ctype.widen(__fill); |
1ab65677 BK |
1483 | break; |
1484 | case money_base::none: | |
1485 | if (__testipad) | |
1486 | __res += string_type(__width - __len, __fill); | |
1487 | break; | |
1488 | } | |
1489 | } | |
1490 | ||
1491 | // Special case of multi-part sign parts. | |
1492 | if (__sign.size() > 1) | |
1493 | __res += string_type(__sign.begin() + 1, __sign.end()); | |
1494 | ||
1495 | // Pad, if still necessary. | |
1496 | __len = __res.size(); | |
1497 | if (__width > __len) | |
1498 | { | |
1499 | if (__f == ios_base::left) | |
1500 | // After. | |
1501 | __res.append(__width - __len, __fill); | |
1502 | else | |
1503 | // Before. | |
1504 | __res.insert(0, string_type(__width - __len, __fill)); | |
1505 | __len = __width; | |
1506 | } | |
1507 | ||
1508 | // Write resulting, fully-formatted string to output iterator. | |
761faeec | 1509 | __s = std::__write(__s, __res.data(), __len); |
1ab65677 BK |
1510 | } |
1511 | __io.width(0); | |
1512 | return __s; | |
fb678854 BK |
1513 | } |
1514 | ||
1ab65677 BK |
1515 | |
1516 | // NB: Not especially useful. Without an ios_base object or some | |
1517 | // kind of locale reference, we are left clawing at the air where | |
1518 | // the side of the mountain used to be... | |
1519 | template<typename _CharT, typename _InIter> | |
1520 | time_base::dateorder | |
1521 | time_get<_CharT, _InIter>::do_date_order() const | |
1522 | { return time_base::no_order; } | |
1523 | ||
1524 | template<typename _CharT, typename _InIter> | |
1525 | void | |
1526 | time_get<_CharT, _InIter>:: | |
da5c0f6e BK |
1527 | _M_extract_via_format(iter_type& __beg, iter_type& __end, ios_base& __io, |
1528 | ios_base::iostate& __err, tm* __tm, | |
1529 | const _CharT* __format) const | |
1530 | { | |
905df1fb | 1531 | const locale __loc = __io.getloc(); |
e0f05105 | 1532 | const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); |
da5c0f6e | 1533 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); |
905df1fb | 1534 | const size_t __len = char_traits<_CharT>::length(__format); |
da5c0f6e BK |
1535 | |
1536 | for (size_t __i = 0; __beg != __end && __i < __len && !__err; ++__i) | |
1ab65677 | 1537 | { |
da5c0f6e BK |
1538 | char __c = __format[__i]; |
1539 | if (__c == '%') | |
1ab65677 | 1540 | { |
da5c0f6e BK |
1541 | // Verify valid formatting code, attempt to extract. |
1542 | __c = __format[++__i]; | |
da5c0f6e BK |
1543 | int __mem = 0; |
1544 | if (__c == 'E' || __c == 'O') | |
08b9183d | 1545 | __c = __format[++__i]; |
da5c0f6e BK |
1546 | switch (__c) |
1547 | { | |
1548 | const char* __cs; | |
1549 | _CharT __wcs[10]; | |
1550 | case 'a': | |
1551 | // Abbreviated weekday name [tm_wday] | |
1552 | const char_type* __days1[7]; | |
1553 | __tp._M_days_abbreviated(__days1); | |
1554 | _M_extract_name(__beg, __end, __tm->tm_wday, __days1, 7, | |
e0f05105 | 1555 | __ctype, __err); |
da5c0f6e BK |
1556 | break; |
1557 | case 'A': | |
1558 | // Weekday name [tm_wday]. | |
1559 | const char_type* __days2[7]; | |
1560 | __tp._M_days(__days2); | |
1561 | _M_extract_name(__beg, __end, __tm->tm_wday, __days2, 7, | |
e0f05105 | 1562 | __ctype, __err); |
da5c0f6e BK |
1563 | break; |
1564 | case 'h': | |
1565 | case 'b': | |
1566 | // Abbreviated month name [tm_mon] | |
1567 | const char_type* __months1[12]; | |
1568 | __tp._M_months_abbreviated(__months1); | |
1569 | _M_extract_name(__beg, __end, __tm->tm_mon, __months1, 12, | |
e0f05105 | 1570 | __ctype, __err); |
da5c0f6e BK |
1571 | break; |
1572 | case 'B': | |
1573 | // Month name [tm_mon]. | |
1574 | const char_type* __months2[12]; | |
1575 | __tp._M_months(__months2); | |
1576 | _M_extract_name(__beg, __end, __tm->tm_mon, __months2, 12, | |
e0f05105 | 1577 | __ctype, __err); |
da5c0f6e BK |
1578 | break; |
1579 | case 'c': | |
1580 | // Default time and date representation. | |
1581 | const char_type* __dt[2]; | |
1582 | __tp._M_date_time_formats(__dt); | |
1583 | _M_extract_via_format(__beg, __end, __io, __err, __tm, | |
1584 | __dt[0]); | |
1585 | break; | |
1586 | case 'd': | |
1587 | // Day [01, 31]. [tm_mday] | |
1588 | _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2, | |
1589 | __ctype, __err); | |
1590 | break; | |
f20d2b78 PC |
1591 | case 'e': |
1592 | // Day [1, 31], with single digits preceded by | |
1593 | // space. [tm_mday] | |
1594 | if (__ctype.is(ctype_base::space, *__beg)) | |
1595 | _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9, 1, | |
1596 | __ctype, __err); | |
cc27f5a2 | 1597 | else |
f20d2b78 PC |
1598 | _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31, 2, |
1599 | __ctype, __err); | |
f20d2b78 | 1600 | break; |
da5c0f6e BK |
1601 | case 'D': |
1602 | // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year] | |
1603 | __cs = "%m/%d/%y"; | |
1604 | __ctype.widen(__cs, __cs + 9, __wcs); | |
1605 | _M_extract_via_format(__beg, __end, __io, __err, __tm, | |
1606 | __wcs); | |
1607 | break; | |
1608 | case 'H': | |
1609 | // Hour [00, 23]. [tm_hour] | |
1610 | _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2, | |
1611 | __ctype, __err); | |
1612 | break; | |
1613 | case 'I': | |
1614 | // Hour [01, 12]. [tm_hour] | |
8f88da40 | 1615 | _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2, |
da5c0f6e BK |
1616 | __ctype, __err); |
1617 | break; | |
1618 | case 'm': | |
1619 | // Month [01, 12]. [tm_mon] | |
8f88da40 BK |
1620 | _M_extract_num(__beg, __end, __mem, 1, 12, 2, __ctype, |
1621 | __err); | |
da5c0f6e BK |
1622 | if (!__err) |
1623 | __tm->tm_mon = __mem - 1; | |
1624 | break; | |
1625 | case 'M': | |
1626 | // Minute [00, 59]. [tm_min] | |
1627 | _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2, | |
1628 | __ctype, __err); | |
1629 | break; | |
1630 | case 'n': | |
1631 | if (__ctype.narrow(*__beg, 0) == '\n') | |
1632 | ++__beg; | |
1633 | else | |
1634 | __err |= ios_base::failbit; | |
1635 | break; | |
1636 | case 'R': | |
1637 | // Equivalent to (%H:%M). | |
1638 | __cs = "%H:%M"; | |
1639 | __ctype.widen(__cs, __cs + 6, __wcs); | |
1640 | _M_extract_via_format(__beg, __end, __io, __err, __tm, | |
1641 | __wcs); | |
1642 | break; | |
1643 | case 'S': | |
1644 | // Seconds. | |
1645 | _M_extract_num(__beg, __end, __tm->tm_sec, 0, 59, 2, | |
1646 | __ctype, __err); | |
1647 | break; | |
1648 | case 't': | |
1649 | if (__ctype.narrow(*__beg, 0) == '\t') | |
1650 | ++__beg; | |
1651 | else | |
f20d2b78 | 1652 | __err |= ios_base::failbit; |
da5c0f6e BK |
1653 | break; |
1654 | case 'T': | |
1655 | // Equivalent to (%H:%M:%S). | |
1656 | __cs = "%H:%M:%S"; | |
1657 | __ctype.widen(__cs, __cs + 9, __wcs); | |
1658 | _M_extract_via_format(__beg, __end, __io, __err, __tm, | |
1659 | __wcs); | |
1660 | break; | |
1661 | case 'x': | |
1662 | // Locale's date. | |
1663 | const char_type* __dates[2]; | |
1664 | __tp._M_date_formats(__dates); | |
1665 | _M_extract_via_format(__beg, __end, __io, __err, __tm, | |
1666 | __dates[0]); | |
1667 | break; | |
1668 | case 'X': | |
1669 | // Locale's time. | |
1670 | const char_type* __times[2]; | |
1671 | __tp._M_time_formats(__times); | |
1672 | _M_extract_via_format(__beg, __end, __io, __err, __tm, | |
1673 | __times[0]); | |
1674 | break; | |
1675 | case 'y': | |
c21dbe85 | 1676 | case 'C': // C99 |
da5c0f6e BK |
1677 | // Two digit year. [tm_year] |
1678 | _M_extract_num(__beg, __end, __tm->tm_year, 0, 99, 2, | |
1679 | __ctype, __err); | |
1680 | break; | |
1681 | case 'Y': | |
1682 | // Year [1900). [tm_year] | |
1683 | _M_extract_num(__beg, __end, __mem, 0, | |
1684 | numeric_limits<int>::max(), 4, | |
1685 | __ctype, __err); | |
1686 | if (!__err) | |
1687 | __tm->tm_year = __mem - 1900; | |
1688 | break; | |
1689 | case 'Z': | |
1690 | // Timezone info. | |
1691 | if (__ctype.is(ctype_base::upper, *__beg)) | |
1692 | { | |
1693 | int __tmp; | |
1694 | _M_extract_name(__beg, __end, __tmp, | |
fea4065d | 1695 | __timepunct_cache<_CharT>::_S_timezones, |
e0f05105 | 1696 | 14, __ctype, __err); |
da5c0f6e BK |
1697 | |
1698 | // GMT requires special effort. | |
f20d2b78 PC |
1699 | if (__beg != __end && !__err && __tmp == 0 |
1700 | && (*__beg == __ctype.widen('-') | |
1701 | || *__beg == __ctype.widen('+'))) | |
da5c0f6e BK |
1702 | { |
1703 | _M_extract_num(__beg, __end, __tmp, 0, 23, 2, | |
1704 | __ctype, __err); | |
1705 | _M_extract_num(__beg, __end, __tmp, 0, 59, 2, | |
1706 | __ctype, __err); | |
1707 | } | |
da5c0f6e | 1708 | } |
da5c0f6e BK |
1709 | else |
1710 | __err |= ios_base::failbit; | |
905df1fb PC |
1711 | break; |
1712 | default: | |
1713 | // Not recognized. | |
1714 | __err |= ios_base::failbit; | |
da5c0f6e | 1715 | } |
905df1fb PC |
1716 | } |
1717 | else | |
1718 | { | |
1719 | // Verify format and input match, extract and discard. | |
1720 | if (__c == __ctype.narrow(*__beg, 0)) | |
1721 | ++__beg; | |
1722 | else | |
1723 | __err |= ios_base::failbit; | |
1724 | } | |
da5c0f6e BK |
1725 | } |
1726 | } | |
1727 | ||
1728 | template<typename _CharT, typename _InIter> | |
1729 | void | |
1730 | time_get<_CharT, _InIter>:: | |
1731 | _M_extract_num(iter_type& __beg, iter_type& __end, int& __member, | |
1732 | int __min, int __max, size_t __len, | |
1733 | const ctype<_CharT>& __ctype, | |
1734 | ios_base::iostate& __err) const | |
1735 | { | |
1736 | size_t __i = 0; | |
1737 | string __digits; | |
1738 | bool __testvalid = true; | |
cc27f5a2 PC |
1739 | for (; __beg != __end && __i < __len |
1740 | && __ctype.is(ctype_base::digit, *__beg); ++__beg, ++__i) | |
1741 | __digits += __ctype.narrow(*__beg, 0); | |
da5c0f6e BK |
1742 | if (__i == __len) |
1743 | { | |
905df1fb | 1744 | const int __value = std::atoi(__digits.c_str()); |
da5c0f6e BK |
1745 | if (__min <= __value && __value <= __max) |
1746 | __member = __value; | |
1ab65677 BK |
1747 | else |
1748 | __testvalid = false; | |
da5c0f6e BK |
1749 | } |
1750 | else | |
1751 | __testvalid = false; | |
1752 | if (!__testvalid) | |
1753 | __err |= ios_base::failbit; | |
725dc051 BK |
1754 | } |
1755 | ||
1ab65677 BK |
1756 | // Assumptions: |
1757 | // All elements in __names are unique. | |
1758 | template<typename _CharT, typename _InIter> | |
1759 | void | |
1760 | time_get<_CharT, _InIter>:: | |
1761 | _M_extract_name(iter_type& __beg, iter_type& __end, int& __member, | |
1762 | const _CharT** __names, size_t __indexlen, | |
e0f05105 | 1763 | const ctype<_CharT>& __ctype, |
1ab65677 | 1764 | ios_base::iostate& __err) const |
725dc051 | 1765 | { |
f13a69ec | 1766 | typedef char_traits<_CharT> __traits_type; |
2e2a38cd BK |
1767 | int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int) |
1768 | * __indexlen)); | |
1ab65677 BK |
1769 | size_t __nmatches = 0; |
1770 | size_t __pos = 0; | |
1771 | bool __testvalid = true; | |
1772 | const char_type* __name; | |
725dc051 | 1773 | |
e0f05105 BK |
1774 | // Look for initial matches. |
1775 | // NB: Some of the locale data is in the form of all lowercase | |
1776 | // names, and some is in the form of initially-capitalized | |
1777 | // names. Look for both. | |
cc27f5a2 PC |
1778 | if (__beg != __end) |
1779 | { | |
1780 | const char_type __c = *__beg; | |
1781 | for (size_t __i1 = 0; __i1 < __indexlen; ++__i1) | |
e0f05105 BK |
1782 | if (__c == __names[__i1][0] |
1783 | || __c == __ctype.toupper(__names[__i1][0])) | |
cc27f5a2 PC |
1784 | __matches[__nmatches++] = __i1; |
1785 | } | |
1ab65677 | 1786 | |
ce3039af | 1787 | while (__nmatches > 1) |
1ab65677 BK |
1788 | { |
1789 | // Find smallest matching string. | |
1790 | size_t __minlen = 10; | |
1791 | for (size_t __i2 = 0; __i2 < __nmatches; ++__i2) | |
5b577977 PC |
1792 | __minlen = std::min(__minlen, |
1793 | __traits_type::length(__names[__matches[__i2]])); | |
cc27f5a2 | 1794 | ++__beg; |
1ab65677 BK |
1795 | if (__pos < __minlen && __beg != __end) |
1796 | { | |
1797 | ++__pos; | |
1ab65677 BK |
1798 | for (size_t __i3 = 0; __i3 < __nmatches; ++__i3) |
1799 | { | |
1800 | __name = __names[__matches[__i3]]; | |
cc27f5a2 | 1801 | if (__name[__pos] != *__beg) |
1ab65677 BK |
1802 | __matches[__i3] = __matches[--__nmatches]; |
1803 | } | |
1804 | } | |
1805 | else | |
1806 | break; | |
1807 | } | |
725dc051 | 1808 | |
1ab65677 BK |
1809 | if (__nmatches == 1) |
1810 | { | |
e0f05105 BK |
1811 | // If there was only one match, the first compare is redundant. |
1812 | if (__pos == 0) | |
1813 | { | |
1814 | ++__pos; | |
1815 | ++__beg; | |
1816 | } | |
1817 | ||
1ab65677 BK |
1818 | // Make sure found name is completely extracted. |
1819 | __name = __names[__matches[0]]; | |
1820 | const size_t __len = __traits_type::length(__name); | |
1821 | while (__pos < __len && __beg != __end && __name[__pos] == *__beg) | |
1822 | ++__beg, ++__pos; | |
1823 | ||
1824 | if (__len == __pos) | |
1825 | __member = __matches[0]; | |
1826 | else | |
1827 | __testvalid = false; | |
1828 | } | |
1829 | else | |
1830 | __testvalid = false; | |
1831 | if (!__testvalid) | |
1832 | __err |= ios_base::failbit; | |
725dc051 BK |
1833 | } |
1834 | ||
1ab65677 BK |
1835 | template<typename _CharT, typename _InIter> |
1836 | _InIter | |
1837 | time_get<_CharT, _InIter>:: | |
1838 | do_get_time(iter_type __beg, iter_type __end, ios_base& __io, | |
1839 | ios_base::iostate& __err, tm* __tm) const | |
725dc051 | 1840 | { |
da5c0f6e BK |
1841 | _CharT __wcs[3]; |
1842 | const char* __cs = "%X"; | |
905df1fb | 1843 | const locale __loc = __io.getloc(); |
da5c0f6e BK |
1844 | ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc); |
1845 | __ctype.widen(__cs, __cs + 3, __wcs); | |
1846 | _M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs); | |
1ab65677 BK |
1847 | if (__beg == __end) |
1848 | __err |= ios_base::eofbit; | |
1849 | return __beg; | |
725dc051 BK |
1850 | } |
1851 | ||
1ab65677 BK |
1852 | template<typename _CharT, typename _InIter> |
1853 | _InIter | |
1854 | time_get<_CharT, _InIter>:: | |
1855 | do_get_date(iter_type __beg, iter_type __end, ios_base& __io, | |
da5c0f6e | 1856 | ios_base::iostate& __err, tm* __tm) const |
725dc051 | 1857 | { |
da5c0f6e BK |
1858 | _CharT __wcs[3]; |
1859 | const char* __cs = "%x"; | |
905df1fb | 1860 | const locale __loc = __io.getloc(); |
da5c0f6e BK |
1861 | ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc); |
1862 | __ctype.widen(__cs, __cs + 3, __wcs); | |
1863 | _M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs); | |
1ab65677 BK |
1864 | if (__beg == __end) |
1865 | __err |= ios_base::eofbit; | |
1866 | return __beg; | |
725dc051 BK |
1867 | } |
1868 | ||
1ab65677 BK |
1869 | template<typename _CharT, typename _InIter> |
1870 | _InIter | |
1871 | time_get<_CharT, _InIter>:: | |
1872 | do_get_weekday(iter_type __beg, iter_type __end, ios_base& __io, | |
1873 | ios_base::iostate& __err, tm* __tm) const | |
725dc051 | 1874 | { |
f13a69ec | 1875 | typedef char_traits<_CharT> __traits_type; |
905df1fb | 1876 | const locale __loc = __io.getloc(); |
e0f05105 BK |
1877 | const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); |
1878 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
1ab65677 BK |
1879 | const char_type* __days[7]; |
1880 | __tp._M_days_abbreviated(__days); | |
1881 | int __tmpwday; | |
e0f05105 | 1882 | _M_extract_name(__beg, __end, __tmpwday, __days, 7, __ctype, __err); |
1ab65677 BK |
1883 | |
1884 | // Check to see if non-abbreviated name exists, and extract. | |
1885 | // NB: Assumes both _M_days and _M_days_abbreviated organized in | |
1886 | // exact same order, first to last, such that the resulting | |
1887 | // __days array with the same index points to a day, and that | |
1888 | // day's abbreviated form. | |
1889 | // NB: Also assumes that an abbreviated name is a subset of the name. | |
1890 | if (!__err) | |
1891 | { | |
1892 | size_t __pos = __traits_type::length(__days[__tmpwday]); | |
1893 | __tp._M_days(__days); | |
1894 | const char_type* __name = __days[__tmpwday]; | |
1895 | if (__name[__pos] == *__beg) | |
1896 | { | |
1897 | // Extract the rest of it. | |
1898 | const size_t __len = __traits_type::length(__name); | |
1899 | while (__pos < __len && __beg != __end | |
1900 | && __name[__pos] == *__beg) | |
1901 | ++__beg, ++__pos; | |
1902 | if (__len != __pos) | |
1903 | __err |= ios_base::failbit; | |
1904 | } | |
1905 | if (!__err) | |
1906 | __tm->tm_wday = __tmpwday; | |
1907 | } | |
1908 | if (__beg == __end) | |
1909 | __err |= ios_base::eofbit; | |
1910 | return __beg; | |
1911 | } | |
725dc051 | 1912 | |
1ab65677 BK |
1913 | template<typename _CharT, typename _InIter> |
1914 | _InIter | |
1915 | time_get<_CharT, _InIter>:: | |
1916 | do_get_monthname(iter_type __beg, iter_type __end, | |
1917 | ios_base& __io, ios_base::iostate& __err, tm* __tm) const | |
725dc051 | 1918 | { |
f13a69ec | 1919 | typedef char_traits<_CharT> __traits_type; |
905df1fb | 1920 | const locale __loc = __io.getloc(); |
e0f05105 BK |
1921 | const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); |
1922 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
1ab65677 BK |
1923 | const char_type* __months[12]; |
1924 | __tp._M_months_abbreviated(__months); | |
1925 | int __tmpmon; | |
e0f05105 | 1926 | _M_extract_name(__beg, __end, __tmpmon, __months, 12, __ctype, __err); |
1ab65677 BK |
1927 | |
1928 | // Check to see if non-abbreviated name exists, and extract. | |
1929 | // NB: Assumes both _M_months and _M_months_abbreviated organized in | |
1930 | // exact same order, first to last, such that the resulting | |
1931 | // __months array with the same index points to a month, and that | |
1932 | // month's abbreviated form. | |
1933 | // NB: Also assumes that an abbreviated name is a subset of the name. | |
1934 | if (!__err) | |
1935 | { | |
1936 | size_t __pos = __traits_type::length(__months[__tmpmon]); | |
1937 | __tp._M_months(__months); | |
1938 | const char_type* __name = __months[__tmpmon]; | |
1939 | if (__name[__pos] == *__beg) | |
1940 | { | |
1941 | // Extract the rest of it. | |
1942 | const size_t __len = __traits_type::length(__name); | |
1943 | while (__pos < __len && __beg != __end | |
1944 | && __name[__pos] == *__beg) | |
1945 | ++__beg, ++__pos; | |
1946 | if (__len != __pos) | |
1947 | __err |= ios_base::failbit; | |
1948 | } | |
1949 | if (!__err) | |
1950 | __tm->tm_mon = __tmpmon; | |
1951 | } | |
1952 | ||
1953 | if (__beg == __end) | |
1954 | __err |= ios_base::eofbit; | |
1955 | return __beg; | |
725dc051 BK |
1956 | } |
1957 | ||
1ab65677 BK |
1958 | template<typename _CharT, typename _InIter> |
1959 | _InIter | |
1960 | time_get<_CharT, _InIter>:: | |
1961 | do_get_year(iter_type __beg, iter_type __end, ios_base& __io, | |
1962 | ios_base::iostate& __err, tm* __tm) const | |
725dc051 | 1963 | { |
905df1fb | 1964 | const locale __loc = __io.getloc(); |
1ab65677 BK |
1965 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); |
1966 | ||
1ab65677 BK |
1967 | size_t __i = 0; |
1968 | string __digits; | |
f1e7988a PC |
1969 | for (; __i < 4 && __beg != __end |
1970 | && __ctype.is(ctype_base::digit, *__beg); ++__beg, ++__i) | |
1971 | __digits += __ctype.narrow(*__beg, 0); | |
1ab65677 BK |
1972 | if (__i == 2 || __i == 4) |
1973 | { | |
4b9aaf63 | 1974 | long __l; |
8ae81136 BK |
1975 | std::__convert_to_v(__digits.c_str(), __l, __err, |
1976 | _S_get_c_locale()); | |
4b9aaf63 BK |
1977 | if (!(__err & ios_base::failbit) && __l <= INT_MAX) |
1978 | { | |
1979 | __l = __i == 2 ? __l : __l - 1900; | |
1980 | __tm->tm_year = static_cast<int>(__l); | |
1981 | } | |
1ab65677 | 1982 | } |
725dc051 | 1983 | else |
1ab65677 BK |
1984 | __err |= ios_base::failbit; |
1985 | if (__beg == __end) | |
1986 | __err |= ios_base::eofbit; | |
1987 | return __beg; | |
725dc051 BK |
1988 | } |
1989 | ||
fb678854 | 1990 | template<typename _CharT, typename _OutIter> |
725dc051 | 1991 | _OutIter |
1ab65677 | 1992 | time_put<_CharT, _OutIter>:: |
52a16d08 | 1993 | put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, |
1ab65677 | 1994 | const _CharT* __beg, const _CharT* __end) const |
e08138aa | 1995 | { |
905df1fb | 1996 | const locale __loc = __io.getloc(); |
e08138aa | 1997 | ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc); |
6bf0b59c | 1998 | for (; __beg != __end; ++__beg) |
f1e7988a PC |
1999 | if (__ctype.narrow(*__beg, 0) != '%') |
2000 | { | |
2001 | *__s = *__beg; | |
2002 | ++__s; | |
2003 | } | |
2004 | else if (++__beg != __end) | |
2005 | { | |
2006 | char __format; | |
2007 | char __mod = 0; | |
2008 | const char __c = __ctype.narrow(*__beg, 0); | |
2009 | if (__c != 'E' && __c != 'O') | |
2010 | __format = __c; | |
2011 | else if (++__beg != __end) | |
2012 | { | |
2013 | __mod = __c; | |
2014 | __format = __ctype.narrow(*__beg, 0); | |
2015 | } | |
2016 | else | |
2017 | break; | |
2018 | __s = this->do_put(__s, __io, __fill, __tm, | |
2019 | __format, __mod); | |
2020 | } | |
2021 | else | |
2022 | break; | |
e08138aa BK |
2023 | return __s; |
2024 | } | |
2025 | ||
2026 | template<typename _CharT, typename _OutIter> | |
1ab65677 BK |
2027 | _OutIter |
2028 | time_put<_CharT, _OutIter>:: | |
2029 | do_put(iter_type __s, ios_base& __io, char_type, const tm* __tm, | |
2030 | char __format, char __mod) const | |
e08138aa | 2031 | { |
905df1fb | 2032 | const locale __loc = __io.getloc(); |
da5c0f6e BK |
2033 | ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc); |
2034 | __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc); | |
2035 | ||
e08138aa BK |
2036 | // NB: This size is arbitrary. Should this be a data member, |
2037 | // initialized at construction? | |
2038 | const size_t __maxlen = 64; | |
2e2a38cd | 2039 | char_type* __res = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen)); |
e08138aa BK |
2040 | |
2041 | // NB: In IEE 1003.1-200x, and perhaps other locale models, it | |
2042 | // is possible that the format character will be longer than one | |
2043 | // character. Possibilities include 'E' or 'O' followed by a | |
c5504edb | 2044 | // format character: if __mod is not the default argument, assume |
e08138aa | 2045 | // it's a valid modifier. |
da5c0f6e BK |
2046 | char_type __fmt[4]; |
2047 | __fmt[0] = __ctype.widen('%'); | |
e08138aa BK |
2048 | if (!__mod) |
2049 | { | |
2050 | __fmt[1] = __format; | |
da5c0f6e | 2051 | __fmt[2] = char_type(); |
e08138aa BK |
2052 | } |
2053 | else | |
2054 | { | |
2055 | __fmt[1] = __mod; | |
2056 | __fmt[2] = __format; | |
da5c0f6e | 2057 | __fmt[3] = char_type(); |
e08138aa BK |
2058 | } |
2059 | ||
d3a193e3 | 2060 | __tp._M_put(__res, __maxlen, __fmt, __tm); |
e08138aa BK |
2061 | |
2062 | // Write resulting, fully-formatted string to output iterator. | |
391cfc46 | 2063 | return std::__write(__s, __res, char_traits<char_type>::length(__res)); |
e08138aa BK |
2064 | } |
2065 | ||
725dc051 | 2066 | |
ea0c0b6e BK |
2067 | // Generic version does nothing. |
2068 | template<typename _CharT> | |
2069 | int | |
d3a193e3 | 2070 | collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const |
ea0c0b6e BK |
2071 | { return 0; } |
2072 | ||
2073 | // Generic version does nothing. | |
2074 | template<typename _CharT> | |
2075 | size_t | |
d3a193e3 | 2076 | collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const |
ea0c0b6e BK |
2077 | { return 0; } |
2078 | ||
2079 | template<typename _CharT> | |
2080 | int | |
2081 | collate<_CharT>:: | |
1ab65677 | 2082 | do_compare(const _CharT* __lo1, const _CharT* __hi1, |
ea0c0b6e BK |
2083 | const _CharT* __lo2, const _CharT* __hi2) const |
2084 | { | |
5040d691 PR |
2085 | // strcoll assumes zero-terminated strings so we make a copy |
2086 | // and then put a zero at the end. | |
ea0c0b6e BK |
2087 | const string_type __one(__lo1, __hi1); |
2088 | const string_type __two(__lo2, __hi2); | |
5040d691 PR |
2089 | |
2090 | const _CharT* __p = __one.c_str(); | |
761faeec | 2091 | const _CharT* __pend = __one.data() + __one.length(); |
5040d691 | 2092 | const _CharT* __q = __two.c_str(); |
761faeec | 2093 | const _CharT* __qend = __two.data() + __two.length(); |
5040d691 PR |
2094 | |
2095 | // strcoll stops when it sees a nul character so we break | |
2096 | // the strings into zero-terminated substrings and pass those | |
2097 | // to strcoll. | |
2098 | for (;;) | |
2099 | { | |
905df1fb | 2100 | const int __res = _M_compare(__p, __q); |
5040d691 PR |
2101 | if (__res) |
2102 | return __res; | |
2103 | ||
2104 | __p += char_traits<_CharT>::length(__p); | |
2105 | __q += char_traits<_CharT>::length(__q); | |
2106 | if (__p == __pend && __q == __qend) | |
2107 | return 0; | |
2108 | else if (__p == __pend) | |
2109 | return -1; | |
2110 | else if (__q == __qend) | |
2111 | return 1; | |
2112 | ||
2113 | __p++; | |
2114 | __q++; | |
2115 | } | |
ea0c0b6e BK |
2116 | } |
2117 | ||
f1e7988a | 2118 | template<typename _CharT> |
b206658a | 2119 | typename collate<_CharT>::string_type |
ea0c0b6e BK |
2120 | collate<_CharT>:: |
2121 | do_transform(const _CharT* __lo, const _CharT* __hi) const | |
2122 | { | |
5040d691 PR |
2123 | // strxfrm assumes zero-terminated strings so we make a copy |
2124 | string_type __str(__lo, __hi); | |
2125 | ||
2126 | const _CharT* __p = __str.c_str(); | |
761faeec | 2127 | const _CharT* __pend = __str.data() + __str.length(); |
5040d691 | 2128 | |
32c16200 | 2129 | size_t __len = (__hi - __lo) * 2; |
5040d691 PR |
2130 | |
2131 | string_type __ret; | |
2132 | ||
2133 | // strxfrm stops when it sees a nul character so we break | |
2134 | // the string into zero-terminated substrings and pass those | |
2135 | // to strxfrm. | |
2136 | for (;;) | |
ea0c0b6e | 2137 | { |
5040d691 PR |
2138 | // First try a buffer perhaps big enough. |
2139 | _CharT* __c = | |
2140 | static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len)); | |
2141 | size_t __res = _M_transform(__c, __p, __len); | |
2142 | // If the buffer was not large enough, try again with the | |
2143 | // correct size. | |
2144 | if (__res >= __len) | |
2145 | { | |
2146 | __len = __res + 1; | |
2147 | __c = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) | |
2148 | * __len)); | |
2149 | __res = _M_transform(__c, __p, __res + 1); | |
2150 | } | |
2151 | ||
2152 | __ret.append(__c, __res); | |
2153 | __p += char_traits<_CharT>::length(__p); | |
2154 | if (__p == __pend) | |
2155 | return __ret; | |
2156 | ||
2157 | __p++; | |
2158 | __ret.push_back(_CharT()); | |
ea0c0b6e | 2159 | } |
ea0c0b6e BK |
2160 | } |
2161 | ||
f1e7988a | 2162 | template<typename _CharT> |
ea0c0b6e BK |
2163 | long |
2164 | collate<_CharT>:: | |
2165 | do_hash(const _CharT* __lo, const _CharT* __hi) const | |
2166 | { | |
2167 | unsigned long __val = 0; | |
2168 | for (; __lo < __hi; ++__lo) | |
2169 | __val = *__lo + ((__val << 7) | | |
4e2f8bcf | 2170 | (__val >> (numeric_limits<unsigned long>::digits - 7))); |
ea0c0b6e BK |
2171 | return static_cast<long>(__val); |
2172 | } | |
1ab65677 | 2173 | |
86ade44c BK |
2174 | // Construct correctly padded string, as per 22.2.2.2.2 |
2175 | // Assumes | |
2176 | // __newlen > __oldlen | |
2177 | // __news is allocated for __newlen size | |
b3340046 PC |
2178 | // Used by both num_put and ostream inserters: if __num, |
2179 | // internal-adjusted objects are padded according to the rules below | |
2180 | // concerning 0[xX] and +-, otherwise, exactly as right-adjusted | |
2181 | // ones are. | |
f13a69ec BK |
2182 | |
2183 | // NB: Of the two parameters, _CharT can be deduced from the | |
2184 | // function arguments. The other (_Traits) has to be explicitly specified. | |
f13a69ec BK |
2185 | template<typename _CharT, typename _Traits> |
2186 | void | |
2187 | __pad<_CharT, _Traits>::_S_pad(ios_base& __io, _CharT __fill, | |
2188 | _CharT* __news, const _CharT* __olds, | |
2189 | const streamsize __newlen, | |
2190 | const streamsize __oldlen, const bool __num) | |
2191 | { | |
e4f7d0a1 PC |
2192 | const size_t __plen = static_cast<size_t>(__newlen - __oldlen); |
2193 | const ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield; | |
86ade44c | 2194 | |
e4f7d0a1 | 2195 | // Padding last. |
86ade44c BK |
2196 | if (__adjust == ios_base::left) |
2197 | { | |
e4f7d0a1 PC |
2198 | _Traits::copy(__news, const_cast<_CharT*>(__olds), __oldlen); |
2199 | _Traits::assign(__news + __oldlen, __plen, __fill); | |
2200 | return; | |
86ade44c | 2201 | } |
e4f7d0a1 PC |
2202 | |
2203 | size_t __mod = 0; | |
2204 | if (__adjust == ios_base::internal && __num) | |
86ade44c BK |
2205 | { |
2206 | // Pad after the sign, if there is one. | |
2207 | // Pad after 0[xX], if there is one. | |
2208 | // Who came up with these rules, anyway? Jeeze. | |
7942afdc | 2209 | const locale& __loc = __io._M_getloc(); |
86ade44c | 2210 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); |
f13a69ec BK |
2211 | const _CharT __minus = __ctype.widen('-'); |
2212 | const _CharT __plus = __ctype.widen('+'); | |
5b577977 PC |
2213 | const bool __testsign = _Traits::eq(__olds[0], __minus) |
2214 | || _Traits::eq(__olds[0], __plus); | |
f13a69ec | 2215 | |
5b577977 PC |
2216 | const bool __testhex = _Traits::eq(__ctype.widen('0'), __olds[0]) |
2217 | && (_Traits::eq(__ctype.widen('x'), __olds[1]) | |
2218 | || _Traits::eq(__ctype.widen('X'), __olds[1])); | |
86ade44c BK |
2219 | if (__testhex) |
2220 | { | |
2221 | __news[0] = __olds[0]; | |
2222 | __news[1] = __olds[1]; | |
5b577977 | 2223 | __mod = 2; |
86ade44c | 2224 | __news += 2; |
86ade44c BK |
2225 | } |
2226 | else if (__testsign) | |
2227 | { | |
a3aff86a | 2228 | __news[0] = __olds[0]; |
5b577977 | 2229 | __mod = 1; |
86ade44c | 2230 | ++__news; |
86ade44c | 2231 | } |
5b577977 | 2232 | // else Padding first. |
86ade44c | 2233 | } |
e4f7d0a1 PC |
2234 | _Traits::assign(__news, __plen, __fill); |
2235 | _Traits::copy(__news + __plen, const_cast<_CharT*>(__olds + __mod), | |
2236 | __oldlen - __mod); | |
86ade44c BK |
2237 | } |
2238 | ||
1ab65677 BK |
2239 | template<typename _CharT> |
2240 | bool | |
2241 | __verify_grouping(const basic_string<_CharT>& __grouping, | |
f20d2b78 | 2242 | const basic_string<_CharT>& __grouping_tmp) |
1ab65677 | 2243 | { |
7942afdc BK |
2244 | size_t __i = 0; |
2245 | size_t __j = 0; | |
2246 | const size_t __len = __grouping.size(); | |
2247 | const size_t __n = __grouping_tmp.size(); | |
1ab65677 BK |
2248 | bool __test = true; |
2249 | ||
2250 | // Parsed number groupings have to match the | |
2251 | // numpunct::grouping string exactly, starting at the | |
2252 | // right-most point of the parsed sequence of elements ... | |
2253 | while (__test && __i < __n - 1) | |
eebf21ef PC |
2254 | for (__j = 0; __test && __j < __len && __i < __n - 1; ++__j, ++__i) |
2255 | __test = __grouping[__j] == __grouping_tmp[__n - __i - 1]; | |
1ab65677 BK |
2256 | // ... but the last parsed grouping can be <= numpunct |
2257 | // grouping. | |
2258 | __j == __len ? __j = 0 : __j; | |
2259 | __test &= __grouping[__j] >= __grouping_tmp[__n - __i - 1]; | |
2260 | return __test; | |
2261 | } | |
2262 | ||
1ab65677 BK |
2263 | template<typename _CharT> |
2264 | _CharT* | |
86ade44c | 2265 | __add_grouping(_CharT* __s, _CharT __sep, |
1ab65677 BK |
2266 | const char* __gbeg, const char* __gend, |
2267 | const _CharT* __first, const _CharT* __last) | |
bf058d22 PC |
2268 | { |
2269 | if (__last - __first > *__gbeg) | |
2270 | { | |
2271 | const bool __bump = __gbeg + 1 != __gend; | |
2272 | __s = std::__add_grouping(__s, __sep, __gbeg + __bump, | |
2273 | __gend, __first, __last - *__gbeg); | |
2274 | __first = __last - *__gbeg; | |
2275 | *__s++ = __sep; | |
2276 | } | |
2277 | do | |
2278 | *__s++ = *__first++; | |
2279 | while (__first != __last); | |
2280 | return __s; | |
2281 | } | |
a32e3c09 BK |
2282 | |
2283 | // Inhibit implicit instantiations for required instantiations, | |
2284 | // which are defined via explicit instantiations elsewhere. | |
2285 | // NB: This syntax is a GNU extension. | |
3d7c150e | 2286 | #if _GLIBCXX_EXTERN_TEMPLATE |
a32e3c09 BK |
2287 | extern template class moneypunct<char, false>; |
2288 | extern template class moneypunct<char, true>; | |
2289 | extern template class moneypunct_byname<char, false>; | |
2290 | extern template class moneypunct_byname<char, true>; | |
41b4d44b BK |
2291 | extern template class money_get<char>; |
2292 | extern template class money_put<char>; | |
a32e3c09 BK |
2293 | extern template class numpunct<char>; |
2294 | extern template class numpunct_byname<char>; | |
41b4d44b BK |
2295 | extern template class num_get<char>; |
2296 | extern template class num_put<char>; | |
a32e3c09 | 2297 | extern template class __timepunct<char>; |
41b4d44b BK |
2298 | extern template class time_put<char>; |
2299 | extern template class time_put_byname<char>; | |
2300 | extern template class time_get<char>; | |
2301 | extern template class time_get_byname<char>; | |
a32e3c09 BK |
2302 | extern template class messages<char>; |
2303 | extern template class messages_byname<char>; | |
a32e3c09 | 2304 | extern template class ctype_byname<char>; |
a32e3c09 | 2305 | extern template class codecvt_byname<char, char, mbstate_t>; |
a32e3c09 BK |
2306 | extern template class collate<char>; |
2307 | extern template class collate_byname<char>; | |
ea0c0b6e | 2308 | |
41b4d44b BK |
2309 | extern template |
2310 | const codecvt<char, char, mbstate_t>& | |
2311 | use_facet<codecvt<char, char, mbstate_t> >(const locale&); | |
2312 | ||
2313 | extern template | |
2314 | const collate<char>& | |
2315 | use_facet<collate<char> >(const locale&); | |
2316 | ||
2317 | extern template | |
2318 | const numpunct<char>& | |
2319 | use_facet<numpunct<char> >(const locale&); | |
2320 | ||
2321 | extern template | |
2322 | const num_put<char>& | |
2323 | use_facet<num_put<char> >(const locale&); | |
2324 | ||
2325 | extern template | |
2326 | const num_get<char>& | |
2327 | use_facet<num_get<char> >(const locale&); | |
2328 | ||
2329 | extern template | |
2330 | const moneypunct<char, true>& | |
2331 | use_facet<moneypunct<char, true> >(const locale&); | |
2332 | ||
2333 | extern template | |
2334 | const moneypunct<char, false>& | |
2335 | use_facet<moneypunct<char, false> >(const locale&); | |
2336 | ||
2337 | extern template | |
2338 | const money_put<char>& | |
2339 | use_facet<money_put<char> >(const locale&); | |
2340 | ||
2341 | extern template | |
2342 | const money_get<char>& | |
2343 | use_facet<money_get<char> >(const locale&); | |
2344 | ||
2345 | extern template | |
2346 | const __timepunct<char>& | |
2347 | use_facet<__timepunct<char> >(const locale&); | |
2348 | ||
2349 | extern template | |
2350 | const time_put<char>& | |
2351 | use_facet<time_put<char> >(const locale&); | |
2352 | ||
2353 | extern template | |
2354 | const time_get<char>& | |
2355 | use_facet<time_get<char> >(const locale&); | |
2356 | ||
2357 | extern template | |
2358 | const messages<char>& | |
2359 | use_facet<messages<char> >(const locale&); | |
2360 | ||
41b4d44b BK |
2361 | extern template |
2362 | bool | |
2363 | has_facet<ctype<char> >(const locale&); | |
2364 | ||
2365 | extern template | |
2366 | bool | |
2367 | has_facet<codecvt<char, char, mbstate_t> >(const locale&); | |
2368 | ||
2369 | extern template | |
2370 | bool | |
2371 | has_facet<collate<char> >(const locale&); | |
2372 | ||
2373 | extern template | |
2374 | bool | |
2375 | has_facet<numpunct<char> >(const locale&); | |
a32e3c09 | 2376 | |
41b4d44b BK |
2377 | extern template |
2378 | bool | |
2379 | has_facet<num_put<char> >(const locale&); | |
a32e3c09 | 2380 | |
41b4d44b BK |
2381 | extern template |
2382 | bool | |
2383 | has_facet<num_get<char> >(const locale&); | |
a32e3c09 | 2384 | |
41b4d44b BK |
2385 | extern template |
2386 | bool | |
2387 | has_facet<moneypunct<char> >(const locale&); | |
2388 | ||
2389 | extern template | |
2390 | bool | |
2391 | has_facet<money_put<char> >(const locale&); | |
2392 | ||
2393 | extern template | |
2394 | bool | |
2395 | has_facet<money_get<char> >(const locale&); | |
2396 | ||
2397 | extern template | |
2398 | bool | |
2399 | has_facet<__timepunct<char> >(const locale&); | |
2400 | ||
2401 | extern template | |
2402 | bool | |
2403 | has_facet<time_put<char> >(const locale&); | |
2404 | ||
2405 | extern template | |
2406 | bool | |
2407 | has_facet<time_get<char> >(const locale&); | |
2408 | ||
2409 | extern template | |
2410 | bool | |
2411 | has_facet<messages<char> >(const locale&); | |
2412 | ||
3d7c150e | 2413 | #ifdef _GLIBCXX_USE_WCHAR_T |
5112ae3a BK |
2414 | extern template class moneypunct<wchar_t, false>; |
2415 | extern template class moneypunct<wchar_t, true>; | |
2416 | extern template class moneypunct_byname<wchar_t, false>; | |
2417 | extern template class moneypunct_byname<wchar_t, true>; | |
2418 | extern template class money_get<wchar_t>; | |
2419 | extern template class money_put<wchar_t>; | |
2420 | extern template class numpunct<wchar_t>; | |
2421 | extern template class numpunct_byname<wchar_t>; | |
2422 | extern template class num_get<wchar_t>; | |
2423 | extern template class num_put<wchar_t>; | |
2424 | extern template class __timepunct<wchar_t>; | |
2425 | extern template class time_put<wchar_t>; | |
2426 | extern template class time_put_byname<wchar_t>; | |
2427 | extern template class time_get<wchar_t>; | |
2428 | extern template class time_get_byname<wchar_t>; | |
2429 | extern template class messages<wchar_t>; | |
2430 | extern template class messages_byname<wchar_t>; | |
2431 | extern template class ctype_byname<wchar_t>; | |
2432 | extern template class codecvt_byname<wchar_t, char, mbstate_t>; | |
2433 | extern template class collate<wchar_t>; | |
2434 | extern template class collate_byname<wchar_t>; | |
2435 | ||
2436 | extern template | |
2437 | const codecvt<wchar_t, char, mbstate_t>& | |
2438 | use_facet<codecvt<wchar_t, char, mbstate_t> >(locale const&); | |
2439 | ||
2440 | extern template | |
2441 | const collate<wchar_t>& | |
2442 | use_facet<collate<wchar_t> >(const locale&); | |
2443 | ||
2444 | extern template | |
2445 | const numpunct<wchar_t>& | |
2446 | use_facet<numpunct<wchar_t> >(const locale&); | |
2447 | ||
2448 | extern template | |
2449 | const num_put<wchar_t>& | |
2450 | use_facet<num_put<wchar_t> >(const locale&); | |
2451 | ||
2452 | extern template | |
2453 | const num_get<wchar_t>& | |
2454 | use_facet<num_get<wchar_t> >(const locale&); | |
2455 | ||
2456 | extern template | |
2457 | const moneypunct<wchar_t, true>& | |
2458 | use_facet<moneypunct<wchar_t, true> >(const locale&); | |
2459 | ||
2460 | extern template | |
2461 | const moneypunct<wchar_t, false>& | |
2462 | use_facet<moneypunct<wchar_t, false> >(const locale&); | |
2463 | ||
2464 | extern template | |
2465 | const money_put<wchar_t>& | |
2466 | use_facet<money_put<wchar_t> >(const locale&); | |
2467 | ||
2468 | extern template | |
2469 | const money_get<wchar_t>& | |
2470 | use_facet<money_get<wchar_t> >(const locale&); | |
2471 | ||
2472 | extern template | |
2473 | const __timepunct<wchar_t>& | |
2474 | use_facet<__timepunct<wchar_t> >(const locale&); | |
2475 | ||
2476 | extern template | |
2477 | const time_put<wchar_t>& | |
2478 | use_facet<time_put<wchar_t> >(const locale&); | |
2479 | ||
2480 | extern template | |
2481 | const time_get<wchar_t>& | |
2482 | use_facet<time_get<wchar_t> >(const locale&); | |
2483 | ||
2484 | extern template | |
2485 | const messages<wchar_t>& | |
2486 | use_facet<messages<wchar_t> >(const locale&); | |
2487 | ||
41b4d44b BK |
2488 | extern template |
2489 | bool | |
2490 | has_facet<ctype<wchar_t> >(const locale&); | |
2491 | ||
2492 | extern template | |
2493 | bool | |
2494 | has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&); | |
2495 | ||
2496 | extern template | |
2497 | bool | |
2498 | has_facet<collate<wchar_t> >(const locale&); | |
2499 | ||
2500 | extern template | |
2501 | bool | |
2502 | has_facet<numpunct<wchar_t> >(const locale&); | |
2503 | ||
2504 | extern template | |
2505 | bool | |
2506 | has_facet<num_put<wchar_t> >(const locale&); | |
2507 | ||
2508 | extern template | |
2509 | bool | |
2510 | has_facet<num_get<wchar_t> >(const locale&); | |
2511 | ||
2512 | extern template | |
2513 | bool | |
2514 | has_facet<moneypunct<wchar_t> >(const locale&); | |
2515 | ||
2516 | extern template | |
2517 | bool | |
2518 | has_facet<money_put<wchar_t> >(const locale&); | |
2519 | ||
2520 | extern template | |
2521 | bool | |
2522 | has_facet<money_get<wchar_t> >(const locale&); | |
2523 | ||
2524 | extern template | |
2525 | bool | |
2526 | has_facet<__timepunct<wchar_t> >(const locale&); | |
2527 | ||
2528 | extern template | |
2529 | bool | |
2530 | has_facet<time_put<wchar_t> >(const locale&); | |
2531 | ||
2532 | extern template | |
2533 | bool | |
2534 | has_facet<time_get<wchar_t> >(const locale&); | |
2535 | ||
2536 | extern template | |
2537 | bool | |
2538 | has_facet<messages<wchar_t> >(const locale&); | |
5112ae3a | 2539 | #endif |
1bc8b0ad | 2540 | #endif |
41b4d44b BK |
2541 | } // namespace std |
2542 | ||
2543 | #endif |