]>
Commit | Line | Data |
---|---|---|
f749a55b PC |
1 | // Locale support -*- C++ -*- |
2 | ||
5624e564 | 3 | // Copyright (C) 2007-2015 Free Software Foundation, Inc. |
f749a55b PC |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
f749a55b PC |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
f749a55b | 19 | |
748086b7 JJ |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
f749a55b | 24 | |
f910786b | 25 | /** @file bits/locale_facets_nonio.tcc |
f749a55b | 26 | * This is an internal header file, included by other library headers. |
f910786b | 27 | * Do not attempt to use it directly. @headername{locale} |
f749a55b PC |
28 | */ |
29 | ||
30 | #ifndef _LOCALE_FACETS_NONIO_TCC | |
31 | #define _LOCALE_FACETS_NONIO_TCC 1 | |
32 | ||
84b31797 PC |
33 | #pragma GCC system_header |
34 | ||
12ffa228 BK |
35 | namespace std _GLIBCXX_VISIBILITY(default) |
36 | { | |
37 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
f749a55b PC |
38 | |
39 | template<typename _CharT, bool _Intl> | |
40 | struct __use_cache<__moneypunct_cache<_CharT, _Intl> > | |
41 | { | |
42 | const __moneypunct_cache<_CharT, _Intl>* | |
43 | operator() (const locale& __loc) const | |
44 | { | |
45 | const size_t __i = moneypunct<_CharT, _Intl>::id._M_id(); | |
46 | const locale::facet** __caches = __loc._M_impl->_M_caches; | |
47 | if (!__caches[__i]) | |
48 | { | |
8fc81078 | 49 | __moneypunct_cache<_CharT, _Intl>* __tmp = 0; |
bc2631e0 | 50 | __try |
f749a55b PC |
51 | { |
52 | __tmp = new __moneypunct_cache<_CharT, _Intl>; | |
53 | __tmp->_M_cache(__loc); | |
54 | } | |
bc2631e0 | 55 | __catch(...) |
f749a55b PC |
56 | { |
57 | delete __tmp; | |
58 | __throw_exception_again; | |
59 | } | |
60 | __loc._M_impl->_M_install_cache(__tmp, __i); | |
61 | } | |
62 | return static_cast< | |
63 | const __moneypunct_cache<_CharT, _Intl>*>(__caches[__i]); | |
64 | } | |
65 | }; | |
66 | ||
67 | template<typename _CharT, bool _Intl> | |
68 | void | |
69 | __moneypunct_cache<_CharT, _Intl>::_M_cache(const locale& __loc) | |
70 | { | |
f749a55b PC |
71 | const moneypunct<_CharT, _Intl>& __mp = |
72 | use_facet<moneypunct<_CharT, _Intl> >(__loc); | |
73 | ||
f749a55b PC |
74 | _M_decimal_point = __mp.decimal_point(); |
75 | _M_thousands_sep = __mp.thousands_sep(); | |
76 | _M_frac_digits = __mp.frac_digits(); | |
af90c8c9 PC |
77 | |
78 | char* __grouping = 0; | |
79 | _CharT* __curr_symbol = 0; | |
80 | _CharT* __positive_sign = 0; | |
81 | _CharT* __negative_sign = 0; | |
82 | __try | |
83 | { | |
d6f64424 JW |
84 | const string& __g = __mp.grouping(); |
85 | _M_grouping_size = __g.size(); | |
af90c8c9 | 86 | __grouping = new char[_M_grouping_size]; |
d6f64424 | 87 | __g.copy(__grouping, _M_grouping_size); |
af90c8c9 | 88 | _M_use_grouping = (_M_grouping_size |
d6f64424 JW |
89 | && static_cast<signed char>(__grouping[0]) > 0 |
90 | && (__grouping[0] | |
af90c8c9 PC |
91 | != __gnu_cxx::__numeric_traits<char>::__max)); |
92 | ||
d6f64424 JW |
93 | const basic_string<_CharT>& __cs = __mp.curr_symbol(); |
94 | _M_curr_symbol_size = __cs.size(); | |
af90c8c9 | 95 | __curr_symbol = new _CharT[_M_curr_symbol_size]; |
d6f64424 | 96 | __cs.copy(__curr_symbol, _M_curr_symbol_size); |
af90c8c9 | 97 | |
d6f64424 JW |
98 | const basic_string<_CharT>& __ps = __mp.positive_sign(); |
99 | _M_positive_sign_size = __ps.size(); | |
af90c8c9 | 100 | __positive_sign = new _CharT[_M_positive_sign_size]; |
d6f64424 | 101 | __ps.copy(__positive_sign, _M_positive_sign_size); |
af90c8c9 | 102 | |
d6f64424 JW |
103 | const basic_string<_CharT>& __ns = __mp.negative_sign(); |
104 | _M_negative_sign_size = __ns.size(); | |
af90c8c9 | 105 | __negative_sign = new _CharT[_M_negative_sign_size]; |
d6f64424 | 106 | __ns.copy(__negative_sign, _M_negative_sign_size); |
af90c8c9 PC |
107 | |
108 | _M_pos_format = __mp.pos_format(); | |
109 | _M_neg_format = __mp.neg_format(); | |
110 | ||
111 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc); | |
112 | __ct.widen(money_base::_S_atoms, | |
113 | money_base::_S_atoms + money_base::_S_end, _M_atoms); | |
d6f64424 JW |
114 | |
115 | _M_grouping = __grouping; | |
116 | _M_curr_symbol = __curr_symbol; | |
117 | _M_positive_sign = __positive_sign; | |
118 | _M_negative_sign = __negative_sign; | |
119 | _M_allocated = true; | |
af90c8c9 PC |
120 | } |
121 | __catch(...) | |
122 | { | |
123 | delete [] __grouping; | |
124 | delete [] __curr_symbol; | |
125 | delete [] __positive_sign; | |
126 | delete [] __negative_sign; | |
127 | __throw_exception_again; | |
128 | } | |
f749a55b PC |
129 | } |
130 | ||
34a2b755 | 131 | _GLIBCXX_BEGIN_NAMESPACE_LDBL_OR_CXX11 |
f749a55b PC |
132 | |
133 | template<typename _CharT, typename _InIter> | |
134 | template<bool _Intl> | |
135 | _InIter | |
136 | money_get<_CharT, _InIter>:: | |
137 | _M_extract(iter_type __beg, iter_type __end, ios_base& __io, | |
138 | ios_base::iostate& __err, string& __units) const | |
139 | { | |
140 | typedef char_traits<_CharT> __traits_type; | |
141 | typedef typename string_type::size_type size_type; | |
142 | typedef money_base::part part; | |
143 | typedef __moneypunct_cache<_CharT, _Intl> __cache_type; | |
144 | ||
145 | const locale& __loc = __io._M_getloc(); | |
146 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
147 | ||
148 | __use_cache<__cache_type> __uc; | |
149 | const __cache_type* __lc = __uc(__loc); | |
150 | const char_type* __lit = __lc->_M_atoms; | |
151 | ||
152 | // Deduced sign. | |
153 | bool __negative = false; | |
154 | // Sign size. | |
155 | size_type __sign_size = 0; | |
156 | // True if sign is mandatory. | |
157 | const bool __mandatory_sign = (__lc->_M_positive_sign_size | |
158 | && __lc->_M_negative_sign_size); | |
159 | // String of grouping info from thousands_sep plucked from __units. | |
160 | string __grouping_tmp; | |
161 | if (__lc->_M_use_grouping) | |
162 | __grouping_tmp.reserve(32); | |
163 | // Last position before the decimal point. | |
164 | int __last_pos = 0; | |
165 | // Separator positions, then, possibly, fractional digits. | |
166 | int __n = 0; | |
167 | // If input iterator is in a valid state. | |
168 | bool __testvalid = true; | |
169 | // Flag marking when a decimal point is found. | |
170 | bool __testdecfound = false; | |
171 | ||
172 | // The tentative returned string is stored here. | |
173 | string __res; | |
174 | __res.reserve(32); | |
175 | ||
176 | const char_type* __lit_zero = __lit + money_base::_S_zero; | |
177 | const money_base::pattern __p = __lc->_M_neg_format; | |
178 | for (int __i = 0; __i < 4 && __testvalid; ++__i) | |
179 | { | |
180 | const part __which = static_cast<part>(__p.field[__i]); | |
181 | switch (__which) | |
182 | { | |
183 | case money_base::symbol: | |
184 | // According to 22.2.6.1.2, p2, symbol is required | |
185 | // if (__io.flags() & ios_base::showbase), otherwise | |
186 | // is optional and consumed only if other characters | |
187 | // are needed to complete the format. | |
188 | if (__io.flags() & ios_base::showbase || __sign_size > 1 | |
189 | || __i == 0 | |
190 | || (__i == 1 && (__mandatory_sign | |
191 | || (static_cast<part>(__p.field[0]) | |
192 | == money_base::sign) | |
193 | || (static_cast<part>(__p.field[2]) | |
194 | == money_base::space))) | |
195 | || (__i == 2 && ((static_cast<part>(__p.field[3]) | |
196 | == money_base::value) | |
197 | || (__mandatory_sign | |
198 | && (static_cast<part>(__p.field[3]) | |
199 | == money_base::sign))))) | |
200 | { | |
201 | const size_type __len = __lc->_M_curr_symbol_size; | |
202 | size_type __j = 0; | |
203 | for (; __beg != __end && __j < __len | |
204 | && *__beg == __lc->_M_curr_symbol[__j]; | |
f970a17d | 205 | ++__beg, (void)++__j); |
f749a55b PC |
206 | if (__j != __len |
207 | && (__j || __io.flags() & ios_base::showbase)) | |
208 | __testvalid = false; | |
209 | } | |
210 | break; | |
211 | case money_base::sign: | |
212 | // Sign might not exist, or be more than one character long. | |
213 | if (__lc->_M_positive_sign_size && __beg != __end | |
214 | && *__beg == __lc->_M_positive_sign[0]) | |
215 | { | |
216 | __sign_size = __lc->_M_positive_sign_size; | |
217 | ++__beg; | |
218 | } | |
219 | else if (__lc->_M_negative_sign_size && __beg != __end | |
220 | && *__beg == __lc->_M_negative_sign[0]) | |
221 | { | |
222 | __negative = true; | |
223 | __sign_size = __lc->_M_negative_sign_size; | |
224 | ++__beg; | |
225 | } | |
226 | else if (__lc->_M_positive_sign_size | |
227 | && !__lc->_M_negative_sign_size) | |
228 | // "... if no sign is detected, the result is given the sign | |
229 | // that corresponds to the source of the empty string" | |
230 | __negative = true; | |
231 | else if (__mandatory_sign) | |
232 | __testvalid = false; | |
233 | break; | |
234 | case money_base::value: | |
235 | // Extract digits, remove and stash away the | |
236 | // grouping of found thousands separators. | |
237 | for (; __beg != __end; ++__beg) | |
238 | { | |
239 | const char_type __c = *__beg; | |
240 | const char_type* __q = __traits_type::find(__lit_zero, | |
241 | 10, __c); | |
242 | if (__q != 0) | |
243 | { | |
244 | __res += money_base::_S_atoms[__q - __lit]; | |
245 | ++__n; | |
246 | } | |
247 | else if (__c == __lc->_M_decimal_point | |
248 | && !__testdecfound) | |
249 | { | |
015daa3a PC |
250 | if (__lc->_M_frac_digits <= 0) |
251 | break; | |
252 | ||
f749a55b PC |
253 | __last_pos = __n; |
254 | __n = 0; | |
255 | __testdecfound = true; | |
256 | } | |
257 | else if (__lc->_M_use_grouping | |
258 | && __c == __lc->_M_thousands_sep | |
259 | && !__testdecfound) | |
260 | { | |
261 | if (__n) | |
262 | { | |
263 | // Mark position for later analysis. | |
264 | __grouping_tmp += static_cast<char>(__n); | |
265 | __n = 0; | |
266 | } | |
267 | else | |
268 | { | |
269 | __testvalid = false; | |
270 | break; | |
271 | } | |
272 | } | |
273 | else | |
274 | break; | |
275 | } | |
276 | if (__res.empty()) | |
277 | __testvalid = false; | |
278 | break; | |
279 | case money_base::space: | |
280 | // At least one space is required. | |
281 | if (__beg != __end && __ctype.is(ctype_base::space, *__beg)) | |
282 | ++__beg; | |
283 | else | |
284 | __testvalid = false; | |
285 | case money_base::none: | |
286 | // Only if not at the end of the pattern. | |
287 | if (__i != 3) | |
288 | for (; __beg != __end | |
289 | && __ctype.is(ctype_base::space, *__beg); ++__beg); | |
290 | break; | |
291 | } | |
292 | } | |
293 | ||
294 | // Need to get the rest of the sign characters, if they exist. | |
295 | if (__sign_size > 1 && __testvalid) | |
296 | { | |
297 | const char_type* __sign = __negative ? __lc->_M_negative_sign | |
298 | : __lc->_M_positive_sign; | |
299 | size_type __i = 1; | |
300 | for (; __beg != __end && __i < __sign_size | |
f970a17d | 301 | && *__beg == __sign[__i]; ++__beg, (void)++__i); |
f749a55b PC |
302 | |
303 | if (__i != __sign_size) | |
304 | __testvalid = false; | |
305 | } | |
306 | ||
307 | if (__testvalid) | |
308 | { | |
309 | // Strip leading zeros. | |
310 | if (__res.size() > 1) | |
311 | { | |
312 | const size_type __first = __res.find_first_not_of('0'); | |
313 | const bool __only_zeros = __first == string::npos; | |
314 | if (__first) | |
315 | __res.erase(0, __only_zeros ? __res.size() - 1 : __first); | |
316 | } | |
317 | ||
318 | // 22.2.6.1.2, p4 | |
319 | if (__negative && __res[0] != '0') | |
320 | __res.insert(__res.begin(), '-'); | |
321 | ||
322 | // Test for grouping fidelity. | |
323 | if (__grouping_tmp.size()) | |
324 | { | |
325 | // Add the ending grouping. | |
326 | __grouping_tmp += static_cast<char>(__testdecfound ? __last_pos | |
327 | : __n); | |
328 | if (!std::__verify_grouping(__lc->_M_grouping, | |
329 | __lc->_M_grouping_size, | |
330 | __grouping_tmp)) | |
331 | __err |= ios_base::failbit; | |
332 | } | |
333 | ||
334 | // Iff not enough digits were supplied after the decimal-point. | |
015daa3a | 335 | if (__testdecfound && __n != __lc->_M_frac_digits) |
f749a55b PC |
336 | __testvalid = false; |
337 | } | |
015daa3a | 338 | |
f749a55b PC |
339 | // Iff valid sequence is not recognized. |
340 | if (!__testvalid) | |
341 | __err |= ios_base::failbit; | |
342 | else | |
343 | __units.swap(__res); | |
344 | ||
345 | // Iff no more characters are available. | |
346 | if (__beg == __end) | |
347 | __err |= ios_base::eofbit; | |
348 | return __beg; | |
349 | } | |
350 | ||
34a2b755 JW |
351 | #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ |
352 | && _GLIBCXX_USE_CXX11_ABI == 0 | |
f749a55b PC |
353 | template<typename _CharT, typename _InIter> |
354 | _InIter | |
355 | money_get<_CharT, _InIter>:: | |
356 | __do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io, | |
357 | ios_base::iostate& __err, double& __units) const | |
358 | { | |
359 | string __str; | |
360 | __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str) | |
361 | : _M_extract<false>(__beg, __end, __io, __err, __str); | |
362 | std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale()); | |
363 | return __beg; | |
364 | } | |
365 | #endif | |
366 | ||
367 | template<typename _CharT, typename _InIter> | |
368 | _InIter | |
369 | money_get<_CharT, _InIter>:: | |
370 | do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io, | |
371 | ios_base::iostate& __err, long double& __units) const | |
372 | { | |
373 | string __str; | |
374 | __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str) | |
375 | : _M_extract<false>(__beg, __end, __io, __err, __str); | |
376 | std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale()); | |
377 | return __beg; | |
378 | } | |
379 | ||
380 | template<typename _CharT, typename _InIter> | |
381 | _InIter | |
382 | money_get<_CharT, _InIter>:: | |
383 | do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io, | |
384 | ios_base::iostate& __err, string_type& __digits) const | |
385 | { | |
386 | typedef typename string::size_type size_type; | |
387 | ||
388 | const locale& __loc = __io._M_getloc(); | |
389 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
390 | ||
391 | string __str; | |
392 | __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str) | |
393 | : _M_extract<false>(__beg, __end, __io, __err, __str); | |
394 | const size_type __len = __str.size(); | |
395 | if (__len) | |
396 | { | |
397 | __digits.resize(__len); | |
398 | __ctype.widen(__str.data(), __str.data() + __len, &__digits[0]); | |
399 | } | |
400 | return __beg; | |
401 | } | |
402 | ||
403 | template<typename _CharT, typename _OutIter> | |
404 | template<bool _Intl> | |
405 | _OutIter | |
406 | money_put<_CharT, _OutIter>:: | |
407 | _M_insert(iter_type __s, ios_base& __io, char_type __fill, | |
408 | const string_type& __digits) const | |
409 | { | |
410 | typedef typename string_type::size_type size_type; | |
411 | typedef money_base::part part; | |
412 | typedef __moneypunct_cache<_CharT, _Intl> __cache_type; | |
413 | ||
414 | const locale& __loc = __io._M_getloc(); | |
415 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
416 | ||
417 | __use_cache<__cache_type> __uc; | |
418 | const __cache_type* __lc = __uc(__loc); | |
419 | const char_type* __lit = __lc->_M_atoms; | |
420 | ||
421 | // Determine if negative or positive formats are to be used, and | |
422 | // discard leading negative_sign if it is present. | |
423 | const char_type* __beg = __digits.data(); | |
424 | ||
425 | money_base::pattern __p; | |
426 | const char_type* __sign; | |
427 | size_type __sign_size; | |
428 | if (!(*__beg == __lit[money_base::_S_minus])) | |
429 | { | |
430 | __p = __lc->_M_pos_format; | |
431 | __sign = __lc->_M_positive_sign; | |
432 | __sign_size = __lc->_M_positive_sign_size; | |
433 | } | |
434 | else | |
435 | { | |
436 | __p = __lc->_M_neg_format; | |
437 | __sign = __lc->_M_negative_sign; | |
438 | __sign_size = __lc->_M_negative_sign_size; | |
439 | if (__digits.size()) | |
440 | ++__beg; | |
441 | } | |
442 | ||
443 | // Look for valid numbers in the ctype facet within input digits. | |
444 | size_type __len = __ctype.scan_not(ctype_base::digit, __beg, | |
445 | __beg + __digits.size()) - __beg; | |
446 | if (__len) | |
447 | { | |
448 | // Assume valid input, and attempt to format. | |
449 | // Break down input numbers into base components, as follows: | |
450 | // final_value = grouped units + (decimal point) + (digits) | |
451 | string_type __value; | |
452 | __value.reserve(2 * __len); | |
453 | ||
454 | // Add thousands separators to non-decimal digits, per | |
455 | // grouping rules. | |
456 | long __paddec = __len - __lc->_M_frac_digits; | |
457 | if (__paddec > 0) | |
458 | { | |
459 | if (__lc->_M_frac_digits < 0) | |
460 | __paddec = __len; | |
461 | if (__lc->_M_grouping_size) | |
462 | { | |
463 | __value.assign(2 * __paddec, char_type()); | |
464 | _CharT* __vend = | |
465 | std::__add_grouping(&__value[0], __lc->_M_thousands_sep, | |
466 | __lc->_M_grouping, | |
467 | __lc->_M_grouping_size, | |
468 | __beg, __beg + __paddec); | |
469 | __value.erase(__vend - &__value[0]); | |
470 | } | |
471 | else | |
472 | __value.assign(__beg, __paddec); | |
473 | } | |
474 | ||
475 | // Deal with decimal point, decimal digits. | |
476 | if (__lc->_M_frac_digits > 0) | |
477 | { | |
478 | __value += __lc->_M_decimal_point; | |
479 | if (__paddec >= 0) | |
480 | __value.append(__beg + __paddec, __lc->_M_frac_digits); | |
481 | else | |
482 | { | |
483 | // Have to pad zeros in the decimal position. | |
484 | __value.append(-__paddec, __lit[money_base::_S_zero]); | |
485 | __value.append(__beg, __len); | |
486 | } | |
487 | } | |
488 | ||
489 | // Calculate length of resulting string. | |
490 | const ios_base::fmtflags __f = __io.flags() | |
491 | & ios_base::adjustfield; | |
492 | __len = __value.size() + __sign_size; | |
493 | __len += ((__io.flags() & ios_base::showbase) | |
494 | ? __lc->_M_curr_symbol_size : 0); | |
495 | ||
496 | string_type __res; | |
497 | __res.reserve(2 * __len); | |
498 | ||
499 | const size_type __width = static_cast<size_type>(__io.width()); | |
500 | const bool __testipad = (__f == ios_base::internal | |
501 | && __len < __width); | |
502 | // Fit formatted digits into the required pattern. | |
503 | for (int __i = 0; __i < 4; ++__i) | |
504 | { | |
505 | const part __which = static_cast<part>(__p.field[__i]); | |
506 | switch (__which) | |
507 | { | |
508 | case money_base::symbol: | |
509 | if (__io.flags() & ios_base::showbase) | |
510 | __res.append(__lc->_M_curr_symbol, | |
511 | __lc->_M_curr_symbol_size); | |
512 | break; | |
513 | case money_base::sign: | |
514 | // Sign might not exist, or be more than one | |
28dac70a | 515 | // character long. In that case, add in the rest |
f749a55b PC |
516 | // below. |
517 | if (__sign_size) | |
518 | __res += __sign[0]; | |
519 | break; | |
520 | case money_base::value: | |
521 | __res += __value; | |
522 | break; | |
523 | case money_base::space: | |
524 | // At least one space is required, but if internal | |
525 | // formatting is required, an arbitrary number of | |
526 | // fill spaces will be necessary. | |
527 | if (__testipad) | |
528 | __res.append(__width - __len, __fill); | |
529 | else | |
530 | __res += __fill; | |
531 | break; | |
532 | case money_base::none: | |
533 | if (__testipad) | |
534 | __res.append(__width - __len, __fill); | |
535 | break; | |
536 | } | |
537 | } | |
538 | ||
539 | // Special case of multi-part sign parts. | |
540 | if (__sign_size > 1) | |
541 | __res.append(__sign + 1, __sign_size - 1); | |
542 | ||
543 | // Pad, if still necessary. | |
544 | __len = __res.size(); | |
545 | if (__width > __len) | |
546 | { | |
547 | if (__f == ios_base::left) | |
548 | // After. | |
549 | __res.append(__width - __len, __fill); | |
550 | else | |
551 | // Before. | |
552 | __res.insert(0, __width - __len, __fill); | |
553 | __len = __width; | |
554 | } | |
555 | ||
556 | // Write resulting, fully-formatted string to output iterator. | |
557 | __s = std::__write(__s, __res.data(), __len); | |
558 | } | |
559 | __io.width(0); | |
560 | return __s; | |
561 | } | |
562 | ||
34a2b755 JW |
563 | #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ |
564 | && _GLIBCXX_USE_CXX11_ABI == 0 | |
f749a55b PC |
565 | template<typename _CharT, typename _OutIter> |
566 | _OutIter | |
567 | money_put<_CharT, _OutIter>:: | |
568 | __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, | |
569 | double __units) const | |
570 | { return this->do_put(__s, __intl, __io, __fill, (long double) __units); } | |
571 | #endif | |
572 | ||
573 | template<typename _CharT, typename _OutIter> | |
574 | _OutIter | |
575 | money_put<_CharT, _OutIter>:: | |
576 | do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, | |
577 | long double __units) const | |
578 | { | |
579 | const locale __loc = __io.getloc(); | |
580 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
581 | #ifdef _GLIBCXX_USE_C99 | |
582 | // First try a buffer perhaps big enough. | |
583 | int __cs_size = 64; | |
584 | char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); | |
585 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
586 | // 328. Bad sprintf format modifier in money_put<>::do_put() | |
587 | int __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size, | |
588 | "%.*Lf", 0, __units); | |
589 | // If the buffer was not large enough, try again with the correct size. | |
590 | if (__len >= __cs_size) | |
591 | { | |
592 | __cs_size = __len + 1; | |
593 | __cs = static_cast<char*>(__builtin_alloca(__cs_size)); | |
594 | __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size, | |
595 | "%.*Lf", 0, __units); | |
596 | } | |
597 | #else | |
598 | // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'. | |
599 | const int __cs_size = | |
600 | __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 3; | |
601 | char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); | |
602 | int __len = std::__convert_from_v(_S_get_c_locale(), __cs, 0, "%.*Lf", | |
603 | 0, __units); | |
604 | #endif | |
605 | string_type __digits(__len, char_type()); | |
606 | __ctype.widen(__cs, __cs + __len, &__digits[0]); | |
607 | return __intl ? _M_insert<true>(__s, __io, __fill, __digits) | |
608 | : _M_insert<false>(__s, __io, __fill, __digits); | |
609 | } | |
610 | ||
611 | template<typename _CharT, typename _OutIter> | |
612 | _OutIter | |
613 | money_put<_CharT, _OutIter>:: | |
614 | do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, | |
615 | const string_type& __digits) const | |
616 | { return __intl ? _M_insert<true>(__s, __io, __fill, __digits) | |
617 | : _M_insert<false>(__s, __io, __fill, __digits); } | |
618 | ||
34a2b755 | 619 | _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11 |
f749a55b PC |
620 | |
621 | // NB: Not especially useful. Without an ios_base object or some | |
622 | // kind of locale reference, we are left clawing at the air where | |
623 | // the side of the mountain used to be... | |
624 | template<typename _CharT, typename _InIter> | |
625 | time_base::dateorder | |
626 | time_get<_CharT, _InIter>::do_date_order() const | |
627 | { return time_base::no_order; } | |
628 | ||
629 | // Expand a strftime format string and parse it. E.g., do_get_date() may | |
630 | // pass %m/%d/%Y => extracted characters. | |
631 | template<typename _CharT, typename _InIter> | |
632 | _InIter | |
633 | time_get<_CharT, _InIter>:: | |
634 | _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io, | |
635 | ios_base::iostate& __err, tm* __tm, | |
636 | const _CharT* __format) const | |
637 | { | |
638 | const locale& __loc = __io._M_getloc(); | |
639 | const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); | |
640 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
641 | const size_t __len = char_traits<_CharT>::length(__format); | |
642 | ||
643 | ios_base::iostate __tmperr = ios_base::goodbit; | |
a4a7631d PC |
644 | size_t __i = 0; |
645 | for (; __beg != __end && __i < __len && !__tmperr; ++__i) | |
f749a55b PC |
646 | { |
647 | if (__ctype.narrow(__format[__i], 0) == '%') | |
648 | { | |
649 | // Verify valid formatting code, attempt to extract. | |
650 | char __c = __ctype.narrow(__format[++__i], 0); | |
651 | int __mem = 0; | |
652 | if (__c == 'E' || __c == 'O') | |
653 | __c = __ctype.narrow(__format[++__i], 0); | |
654 | switch (__c) | |
655 | { | |
656 | const char* __cs; | |
657 | _CharT __wcs[10]; | |
658 | case 'a': | |
659 | // Abbreviated weekday name [tm_wday] | |
660 | const char_type* __days1[7]; | |
661 | __tp._M_days_abbreviated(__days1); | |
662 | __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days1, | |
663 | 7, __io, __tmperr); | |
664 | break; | |
665 | case 'A': | |
666 | // Weekday name [tm_wday]. | |
667 | const char_type* __days2[7]; | |
668 | __tp._M_days(__days2); | |
669 | __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days2, | |
670 | 7, __io, __tmperr); | |
671 | break; | |
672 | case 'h': | |
673 | case 'b': | |
674 | // Abbreviated month name [tm_mon] | |
675 | const char_type* __months1[12]; | |
676 | __tp._M_months_abbreviated(__months1); | |
677 | __beg = _M_extract_name(__beg, __end, __tm->tm_mon, | |
678 | __months1, 12, __io, __tmperr); | |
679 | break; | |
680 | case 'B': | |
681 | // Month name [tm_mon]. | |
682 | const char_type* __months2[12]; | |
683 | __tp._M_months(__months2); | |
684 | __beg = _M_extract_name(__beg, __end, __tm->tm_mon, | |
685 | __months2, 12, __io, __tmperr); | |
686 | break; | |
687 | case 'c': | |
688 | // Default time and date representation. | |
689 | const char_type* __dt[2]; | |
690 | __tp._M_date_time_formats(__dt); | |
691 | __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, | |
692 | __tm, __dt[0]); | |
693 | break; | |
694 | case 'd': | |
695 | // Day [01, 31]. [tm_mday] | |
696 | __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2, | |
697 | __io, __tmperr); | |
698 | break; | |
699 | case 'e': | |
700 | // Day [1, 31], with single digits preceded by | |
701 | // space. [tm_mday] | |
702 | if (__ctype.is(ctype_base::space, *__beg)) | |
703 | __beg = _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9, | |
704 | 1, __io, __tmperr); | |
705 | else | |
706 | __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31, | |
707 | 2, __io, __tmperr); | |
708 | break; | |
709 | case 'D': | |
710 | // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year] | |
711 | __cs = "%m/%d/%y"; | |
712 | __ctype.widen(__cs, __cs + 9, __wcs); | |
713 | __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, | |
714 | __tm, __wcs); | |
715 | break; | |
716 | case 'H': | |
717 | // Hour [00, 23]. [tm_hour] | |
718 | __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2, | |
719 | __io, __tmperr); | |
720 | break; | |
721 | case 'I': | |
722 | // Hour [01, 12]. [tm_hour] | |
723 | __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2, | |
724 | __io, __tmperr); | |
725 | break; | |
726 | case 'm': | |
727 | // Month [01, 12]. [tm_mon] | |
728 | __beg = _M_extract_num(__beg, __end, __mem, 1, 12, 2, | |
729 | __io, __tmperr); | |
730 | if (!__tmperr) | |
731 | __tm->tm_mon = __mem - 1; | |
732 | break; | |
733 | case 'M': | |
734 | // Minute [00, 59]. [tm_min] | |
735 | __beg = _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2, | |
736 | __io, __tmperr); | |
737 | break; | |
738 | case 'n': | |
739 | if (__ctype.narrow(*__beg, 0) == '\n') | |
740 | ++__beg; | |
741 | else | |
742 | __tmperr |= ios_base::failbit; | |
743 | break; | |
744 | case 'R': | |
745 | // Equivalent to (%H:%M). | |
746 | __cs = "%H:%M"; | |
747 | __ctype.widen(__cs, __cs + 6, __wcs); | |
748 | __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, | |
749 | __tm, __wcs); | |
750 | break; | |
751 | case 'S': | |
752 | // Seconds. [tm_sec] | |
753 | // [00, 60] in C99 (one leap-second), [00, 61] in C89. | |
754 | #ifdef _GLIBCXX_USE_C99 | |
755 | __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 60, 2, | |
756 | #else | |
757 | __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 61, 2, | |
758 | #endif | |
759 | __io, __tmperr); | |
760 | break; | |
761 | case 't': | |
762 | if (__ctype.narrow(*__beg, 0) == '\t') | |
763 | ++__beg; | |
764 | else | |
765 | __tmperr |= ios_base::failbit; | |
766 | break; | |
767 | case 'T': | |
768 | // Equivalent to (%H:%M:%S). | |
769 | __cs = "%H:%M:%S"; | |
770 | __ctype.widen(__cs, __cs + 9, __wcs); | |
771 | __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, | |
772 | __tm, __wcs); | |
773 | break; | |
774 | case 'x': | |
775 | // Locale's date. | |
776 | const char_type* __dates[2]; | |
777 | __tp._M_date_formats(__dates); | |
778 | __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, | |
779 | __tm, __dates[0]); | |
780 | break; | |
781 | case 'X': | |
782 | // Locale's time. | |
783 | const char_type* __times[2]; | |
784 | __tp._M_time_formats(__times); | |
785 | __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, | |
786 | __tm, __times[0]); | |
787 | break; | |
788 | case 'y': | |
789 | case 'C': // C99 | |
2e8e6a99 | 790 | // Two digit year. |
f749a55b | 791 | case 'Y': |
2e8e6a99 PC |
792 | // Year [1900). |
793 | // NB: We parse either two digits, implicitly years since | |
794 | // 1900, or 4 digits, full year. In both cases we can | |
795 | // reconstruct [tm_year]. See also libstdc++/26701. | |
f749a55b PC |
796 | __beg = _M_extract_num(__beg, __end, __mem, 0, 9999, 4, |
797 | __io, __tmperr); | |
798 | if (!__tmperr) | |
2e8e6a99 | 799 | __tm->tm_year = __mem < 0 ? __mem + 100 : __mem - 1900; |
f749a55b PC |
800 | break; |
801 | case 'Z': | |
802 | // Timezone info. | |
803 | if (__ctype.is(ctype_base::upper, *__beg)) | |
804 | { | |
805 | int __tmp; | |
806 | __beg = _M_extract_name(__beg, __end, __tmp, | |
807 | __timepunct_cache<_CharT>::_S_timezones, | |
808 | 14, __io, __tmperr); | |
809 | ||
810 | // GMT requires special effort. | |
811 | if (__beg != __end && !__tmperr && __tmp == 0 | |
812 | && (*__beg == __ctype.widen('-') | |
813 | || *__beg == __ctype.widen('+'))) | |
814 | { | |
815 | __beg = _M_extract_num(__beg, __end, __tmp, 0, 23, 2, | |
816 | __io, __tmperr); | |
817 | __beg = _M_extract_num(__beg, __end, __tmp, 0, 59, 2, | |
818 | __io, __tmperr); | |
819 | } | |
820 | } | |
821 | else | |
822 | __tmperr |= ios_base::failbit; | |
823 | break; | |
824 | default: | |
825 | // Not recognized. | |
826 | __tmperr |= ios_base::failbit; | |
827 | } | |
828 | } | |
829 | else | |
830 | { | |
831 | // Verify format and input match, extract and discard. | |
832 | if (__format[__i] == *__beg) | |
833 | ++__beg; | |
834 | else | |
835 | __tmperr |= ios_base::failbit; | |
836 | } | |
837 | } | |
838 | ||
a4a7631d | 839 | if (__tmperr || __i != __len) |
f749a55b PC |
840 | __err |= ios_base::failbit; |
841 | ||
842 | return __beg; | |
843 | } | |
844 | ||
845 | template<typename _CharT, typename _InIter> | |
846 | _InIter | |
847 | time_get<_CharT, _InIter>:: | |
848 | _M_extract_num(iter_type __beg, iter_type __end, int& __member, | |
849 | int __min, int __max, size_t __len, | |
850 | ios_base& __io, ios_base::iostate& __err) const | |
851 | { | |
852 | const locale& __loc = __io._M_getloc(); | |
853 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
854 | ||
855 | // As-is works for __len = 1, 2, 4, the values actually used. | |
856 | int __mult = __len == 2 ? 10 : (__len == 4 ? 1000 : 1); | |
857 | ||
858 | ++__min; | |
859 | size_t __i = 0; | |
860 | int __value = 0; | |
f970a17d | 861 | for (; __beg != __end && __i < __len; ++__beg, (void)++__i) |
f749a55b PC |
862 | { |
863 | const char __c = __ctype.narrow(*__beg, '*'); | |
864 | if (__c >= '0' && __c <= '9') | |
865 | { | |
866 | __value = __value * 10 + (__c - '0'); | |
867 | const int __valuec = __value * __mult; | |
868 | if (__valuec > __max || __valuec + __mult < __min) | |
869 | break; | |
870 | __mult /= 10; | |
871 | } | |
872 | else | |
873 | break; | |
874 | } | |
875 | if (__i == __len) | |
876 | __member = __value; | |
2e8e6a99 PC |
877 | // Special encoding for do_get_year, 'y', and 'Y' above. |
878 | else if (__len == 4 && __i == 2) | |
879 | __member = __value - 100; | |
f749a55b PC |
880 | else |
881 | __err |= ios_base::failbit; | |
882 | ||
883 | return __beg; | |
884 | } | |
885 | ||
886 | // Assumptions: | |
887 | // All elements in __names are unique. | |
888 | template<typename _CharT, typename _InIter> | |
889 | _InIter | |
890 | time_get<_CharT, _InIter>:: | |
891 | _M_extract_name(iter_type __beg, iter_type __end, int& __member, | |
892 | const _CharT** __names, size_t __indexlen, | |
893 | ios_base& __io, ios_base::iostate& __err) const | |
894 | { | |
895 | typedef char_traits<_CharT> __traits_type; | |
896 | const locale& __loc = __io._M_getloc(); | |
897 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
898 | ||
899 | int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int) | |
900 | * __indexlen)); | |
901 | size_t __nmatches = 0; | |
902 | size_t __pos = 0; | |
903 | bool __testvalid = true; | |
904 | const char_type* __name; | |
905 | ||
906 | // Look for initial matches. | |
907 | // NB: Some of the locale data is in the form of all lowercase | |
908 | // names, and some is in the form of initially-capitalized | |
909 | // names. Look for both. | |
910 | if (__beg != __end) | |
911 | { | |
912 | const char_type __c = *__beg; | |
913 | for (size_t __i1 = 0; __i1 < __indexlen; ++__i1) | |
914 | if (__c == __names[__i1][0] | |
915 | || __c == __ctype.toupper(__names[__i1][0])) | |
916 | __matches[__nmatches++] = __i1; | |
917 | } | |
918 | ||
919 | while (__nmatches > 1) | |
920 | { | |
921 | // Find smallest matching string. | |
922 | size_t __minlen = __traits_type::length(__names[__matches[0]]); | |
923 | for (size_t __i2 = 1; __i2 < __nmatches; ++__i2) | |
924 | __minlen = std::min(__minlen, | |
925 | __traits_type::length(__names[__matches[__i2]])); | |
f970a17d JW |
926 | ++__beg; |
927 | ++__pos; | |
f749a55b PC |
928 | if (__pos < __minlen && __beg != __end) |
929 | for (size_t __i3 = 0; __i3 < __nmatches;) | |
930 | { | |
931 | __name = __names[__matches[__i3]]; | |
932 | if (!(__name[__pos] == *__beg)) | |
933 | __matches[__i3] = __matches[--__nmatches]; | |
934 | else | |
935 | ++__i3; | |
936 | } | |
937 | else | |
938 | break; | |
939 | } | |
940 | ||
941 | if (__nmatches == 1) | |
942 | { | |
943 | // Make sure found name is completely extracted. | |
f970a17d JW |
944 | ++__beg; |
945 | ++__pos; | |
f749a55b PC |
946 | __name = __names[__matches[0]]; |
947 | const size_t __len = __traits_type::length(__name); | |
948 | while (__pos < __len && __beg != __end && __name[__pos] == *__beg) | |
f970a17d | 949 | ++__beg, (void)++__pos; |
f749a55b PC |
950 | |
951 | if (__len == __pos) | |
952 | __member = __matches[0]; | |
953 | else | |
954 | __testvalid = false; | |
955 | } | |
956 | else | |
957 | __testvalid = false; | |
958 | if (!__testvalid) | |
959 | __err |= ios_base::failbit; | |
960 | ||
961 | return __beg; | |
962 | } | |
963 | ||
ac2bb437 PC |
964 | template<typename _CharT, typename _InIter> |
965 | _InIter | |
966 | time_get<_CharT, _InIter>:: | |
967 | _M_extract_wday_or_month(iter_type __beg, iter_type __end, int& __member, | |
968 | const _CharT** __names, size_t __indexlen, | |
969 | ios_base& __io, ios_base::iostate& __err) const | |
970 | { | |
971 | typedef char_traits<_CharT> __traits_type; | |
972 | const locale& __loc = __io._M_getloc(); | |
973 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
974 | ||
975 | int* __matches = static_cast<int*>(__builtin_alloca(2 * sizeof(int) | |
976 | * __indexlen)); | |
977 | size_t __nmatches = 0; | |
978 | size_t* __matches_lengths = 0; | |
979 | size_t __pos = 0; | |
980 | ||
981 | if (__beg != __end) | |
982 | { | |
983 | const char_type __c = *__beg; | |
984 | for (size_t __i = 0; __i < 2 * __indexlen; ++__i) | |
985 | if (__c == __names[__i][0] | |
986 | || __c == __ctype.toupper(__names[__i][0])) | |
987 | __matches[__nmatches++] = __i; | |
988 | } | |
989 | ||
990 | if (__nmatches) | |
991 | { | |
f970a17d JW |
992 | ++__beg; |
993 | ++__pos; | |
ac2bb437 PC |
994 | |
995 | __matches_lengths | |
996 | = static_cast<size_t*>(__builtin_alloca(sizeof(size_t) | |
997 | * __nmatches)); | |
998 | for (size_t __i = 0; __i < __nmatches; ++__i) | |
999 | __matches_lengths[__i] | |
1000 | = __traits_type::length(__names[__matches[__i]]); | |
1001 | } | |
1002 | ||
f970a17d | 1003 | for (; __beg != __end; ++__beg, (void)++__pos) |
ac2bb437 PC |
1004 | { |
1005 | size_t __nskipped = 0; | |
1006 | const char_type __c = *__beg; | |
1007 | for (size_t __i = 0; __i < __nmatches;) | |
1008 | { | |
1009 | const char_type* __name = __names[__matches[__i]]; | |
1010 | if (__pos >= __matches_lengths[__i]) | |
1011 | ++__nskipped, ++__i; | |
1012 | else if (!(__name[__pos] == __c)) | |
1013 | { | |
1014 | --__nmatches; | |
1015 | __matches[__i] = __matches[__nmatches]; | |
1016 | __matches_lengths[__i] = __matches_lengths[__nmatches]; | |
1017 | } | |
1018 | else | |
1019 | ++__i; | |
1020 | } | |
1021 | if (__nskipped == __nmatches) | |
1022 | break; | |
1023 | } | |
1024 | ||
1025 | if ((__nmatches == 1 && __matches_lengths[0] == __pos) | |
1026 | || (__nmatches == 2 && (__matches_lengths[0] == __pos | |
1027 | || __matches_lengths[1] == __pos))) | |
1028 | __member = (__matches[0] >= __indexlen | |
1029 | ? __matches[0] - __indexlen : __matches[0]); | |
1030 | else | |
1031 | __err |= ios_base::failbit; | |
1032 | ||
1033 | return __beg; | |
1034 | } | |
1035 | ||
f749a55b PC |
1036 | template<typename _CharT, typename _InIter> |
1037 | _InIter | |
1038 | time_get<_CharT, _InIter>:: | |
1039 | do_get_time(iter_type __beg, iter_type __end, ios_base& __io, | |
1040 | ios_base::iostate& __err, tm* __tm) const | |
1041 | { | |
1042 | const locale& __loc = __io._M_getloc(); | |
1043 | const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); | |
1044 | const char_type* __times[2]; | |
1045 | __tp._M_time_formats(__times); | |
1046 | __beg = _M_extract_via_format(__beg, __end, __io, __err, | |
1047 | __tm, __times[0]); | |
1048 | if (__beg == __end) | |
1049 | __err |= ios_base::eofbit; | |
1050 | return __beg; | |
1051 | } | |
1052 | ||
1053 | template<typename _CharT, typename _InIter> | |
1054 | _InIter | |
1055 | time_get<_CharT, _InIter>:: | |
1056 | do_get_date(iter_type __beg, iter_type __end, ios_base& __io, | |
1057 | ios_base::iostate& __err, tm* __tm) const | |
1058 | { | |
1059 | const locale& __loc = __io._M_getloc(); | |
1060 | const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); | |
1061 | const char_type* __dates[2]; | |
1062 | __tp._M_date_formats(__dates); | |
1063 | __beg = _M_extract_via_format(__beg, __end, __io, __err, | |
1064 | __tm, __dates[0]); | |
1065 | if (__beg == __end) | |
1066 | __err |= ios_base::eofbit; | |
1067 | return __beg; | |
1068 | } | |
1069 | ||
1070 | template<typename _CharT, typename _InIter> | |
1071 | _InIter | |
1072 | time_get<_CharT, _InIter>:: | |
1073 | do_get_weekday(iter_type __beg, iter_type __end, ios_base& __io, | |
1074 | ios_base::iostate& __err, tm* __tm) const | |
1075 | { | |
f749a55b PC |
1076 | const locale& __loc = __io._M_getloc(); |
1077 | const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); | |
1078 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
ac2bb437 | 1079 | const char_type* __days[14]; |
f749a55b | 1080 | __tp._M_days_abbreviated(__days); |
ac2bb437 | 1081 | __tp._M_days(__days + 7); |
f749a55b PC |
1082 | int __tmpwday; |
1083 | ios_base::iostate __tmperr = ios_base::goodbit; | |
ac2bb437 PC |
1084 | |
1085 | __beg = _M_extract_wday_or_month(__beg, __end, __tmpwday, __days, 7, | |
1086 | __io, __tmperr); | |
f749a55b PC |
1087 | if (!__tmperr) |
1088 | __tm->tm_wday = __tmpwday; | |
1089 | else | |
1090 | __err |= ios_base::failbit; | |
1091 | ||
1092 | if (__beg == __end) | |
1093 | __err |= ios_base::eofbit; | |
1094 | return __beg; | |
1095 | } | |
1096 | ||
1097 | template<typename _CharT, typename _InIter> | |
1098 | _InIter | |
1099 | time_get<_CharT, _InIter>:: | |
1100 | do_get_monthname(iter_type __beg, iter_type __end, | |
1101 | ios_base& __io, ios_base::iostate& __err, tm* __tm) const | |
1102 | { | |
f749a55b PC |
1103 | const locale& __loc = __io._M_getloc(); |
1104 | const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); | |
1105 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
ac2bb437 | 1106 | const char_type* __months[24]; |
f749a55b | 1107 | __tp._M_months_abbreviated(__months); |
ac2bb437 | 1108 | __tp._M_months(__months + 12); |
f749a55b PC |
1109 | int __tmpmon; |
1110 | ios_base::iostate __tmperr = ios_base::goodbit; | |
ac2bb437 PC |
1111 | |
1112 | __beg = _M_extract_wday_or_month(__beg, __end, __tmpmon, __months, 12, | |
1113 | __io, __tmperr); | |
f749a55b PC |
1114 | if (!__tmperr) |
1115 | __tm->tm_mon = __tmpmon; | |
1116 | else | |
1117 | __err |= ios_base::failbit; | |
1118 | ||
1119 | if (__beg == __end) | |
1120 | __err |= ios_base::eofbit; | |
1121 | return __beg; | |
1122 | } | |
1123 | ||
1124 | template<typename _CharT, typename _InIter> | |
1125 | _InIter | |
1126 | time_get<_CharT, _InIter>:: | |
1127 | do_get_year(iter_type __beg, iter_type __end, ios_base& __io, | |
1128 | ios_base::iostate& __err, tm* __tm) const | |
1129 | { | |
1130 | const locale& __loc = __io._M_getloc(); | |
1131 | const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); | |
2e8e6a99 PC |
1132 | int __tmpyear; |
1133 | ios_base::iostate __tmperr = ios_base::goodbit; | |
f749a55b | 1134 | |
2e8e6a99 PC |
1135 | __beg = _M_extract_num(__beg, __end, __tmpyear, 0, 9999, 4, |
1136 | __io, __tmperr); | |
1137 | if (!__tmperr) | |
1138 | __tm->tm_year = __tmpyear < 0 ? __tmpyear + 100 : __tmpyear - 1900; | |
f749a55b PC |
1139 | else |
1140 | __err |= ios_base::failbit; | |
1141 | ||
1142 | if (__beg == __end) | |
1143 | __err |= ios_base::eofbit; | |
1144 | return __beg; | |
1145 | } | |
1146 | ||
e869c090 RS |
1147 | #if __cplusplus >= 201103L |
1148 | template<typename _CharT, typename _InIter> | |
1149 | inline | |
1150 | _InIter | |
1151 | time_get<_CharT, _InIter>:: | |
1152 | get(iter_type __s, iter_type __end, ios_base& __io, | |
1153 | ios_base::iostate& __err, tm* __tm, const char_type* __fmt, | |
1154 | const char_type* __fmtend) const | |
1155 | { | |
1156 | const locale& __loc = __io._M_getloc(); | |
1157 | ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc); | |
1158 | __err = ios_base::goodbit; | |
1159 | while (__fmt != __fmtend && | |
1160 | __err == ios_base::goodbit) | |
1161 | { | |
1162 | if (__s == __end) | |
1163 | { | |
1164 | __err = ios_base::eofbit | ios_base::failbit; | |
1165 | break; | |
1166 | } | |
1167 | else if (__ctype.narrow(*__fmt, 0) == '%') | |
1168 | { | |
1169 | char __format; | |
1170 | char __mod = 0; | |
1171 | if (++__fmt == __fmtend) | |
1172 | { | |
1173 | __err = ios_base::failbit; | |
1174 | break; | |
1175 | } | |
1176 | const char __c = __ctype.narrow(*__fmt, 0); | |
1177 | if (__c != 'E' && __c != 'O') | |
1178 | __format = __c; | |
1179 | else if (++__fmt != __fmtend) | |
1180 | { | |
1181 | __mod = __c; | |
1182 | __format = __ctype.narrow(*__fmt, 0); | |
1183 | } | |
1184 | else | |
1185 | { | |
1186 | __err = ios_base::failbit; | |
1187 | break; | |
1188 | } | |
1189 | __s = this->do_get(__s, __end, __io, __err, __tm, __format, | |
1190 | __mod); | |
1191 | ++__fmt; | |
1192 | } | |
1193 | else if (__ctype.is(ctype_base::space, *__fmt)) | |
1194 | { | |
1195 | ++__fmt; | |
1196 | while (__fmt != __fmtend && | |
1197 | __ctype.is(ctype_base::space, *__fmt)) | |
1198 | ++__fmt; | |
1199 | ||
1200 | while (__s != __end && | |
1201 | __ctype.is(ctype_base::space, *__s)) | |
1202 | ++__s; | |
1203 | } | |
1204 | // TODO real case-insensitive comparison | |
1205 | else if (__ctype.tolower(*__s) == __ctype.tolower(*__fmt) || | |
1206 | __ctype.toupper(*__s) == __ctype.toupper(*__fmt)) | |
1207 | { | |
1208 | ++__s; | |
1209 | ++__fmt; | |
1210 | } | |
1211 | else | |
1212 | { | |
1213 | __err = ios_base::failbit; | |
1214 | break; | |
1215 | } | |
1216 | } | |
1217 | return __s; | |
1218 | } | |
1219 | ||
1220 | template<typename _CharT, typename _InIter> | |
1221 | inline | |
1222 | _InIter | |
1223 | time_get<_CharT, _InIter>:: | |
1224 | do_get(iter_type __beg, iter_type __end, ios_base& __io, | |
1225 | ios_base::iostate& __err, tm* __tm, | |
1226 | char __format, char __mod) const | |
1227 | { | |
1228 | const locale& __loc = __io._M_getloc(); | |
1229 | ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc); | |
1230 | __err = ios_base::goodbit; | |
1231 | ||
1232 | char_type __fmt[4]; | |
1233 | __fmt[0] = __ctype.widen('%'); | |
1234 | if (!__mod) | |
1235 | { | |
1236 | __fmt[1] = __format; | |
1237 | __fmt[2] = char_type(); | |
1238 | } | |
1239 | else | |
1240 | { | |
1241 | __fmt[1] = __mod; | |
1242 | __fmt[2] = __format; | |
1243 | __fmt[3] = char_type(); | |
1244 | } | |
1245 | ||
1246 | __beg = _M_extract_via_format(__beg, __end, __io, __err, __tm, __fmt); | |
1247 | if (__beg == __end) | |
1248 | __err |= ios_base::eofbit; | |
1249 | return __beg; | |
1250 | } | |
1251 | ||
1252 | #endif // __cplusplus >= 201103L | |
1253 | ||
f749a55b PC |
1254 | template<typename _CharT, typename _OutIter> |
1255 | _OutIter | |
1256 | time_put<_CharT, _OutIter>:: | |
1257 | put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, | |
1258 | const _CharT* __beg, const _CharT* __end) const | |
1259 | { | |
1260 | const locale& __loc = __io._M_getloc(); | |
1261 | ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc); | |
1262 | for (; __beg != __end; ++__beg) | |
1263 | if (__ctype.narrow(*__beg, 0) != '%') | |
1264 | { | |
1265 | *__s = *__beg; | |
1266 | ++__s; | |
1267 | } | |
1268 | else if (++__beg != __end) | |
1269 | { | |
1270 | char __format; | |
1271 | char __mod = 0; | |
1272 | const char __c = __ctype.narrow(*__beg, 0); | |
1273 | if (__c != 'E' && __c != 'O') | |
1274 | __format = __c; | |
1275 | else if (++__beg != __end) | |
1276 | { | |
1277 | __mod = __c; | |
1278 | __format = __ctype.narrow(*__beg, 0); | |
1279 | } | |
1280 | else | |
1281 | break; | |
1282 | __s = this->do_put(__s, __io, __fill, __tm, __format, __mod); | |
1283 | } | |
1284 | else | |
1285 | break; | |
1286 | return __s; | |
1287 | } | |
1288 | ||
1289 | template<typename _CharT, typename _OutIter> | |
1290 | _OutIter | |
1291 | time_put<_CharT, _OutIter>:: | |
1292 | do_put(iter_type __s, ios_base& __io, char_type, const tm* __tm, | |
1293 | char __format, char __mod) const | |
1294 | { | |
1295 | const locale& __loc = __io._M_getloc(); | |
1296 | ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc); | |
1297 | __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc); | |
1298 | ||
1299 | // NB: This size is arbitrary. Should this be a data member, | |
1300 | // initialized at construction? | |
1301 | const size_t __maxlen = 128; | |
3095eb8e | 1302 | char_type __res[__maxlen]; |
f749a55b PC |
1303 | |
1304 | // NB: In IEE 1003.1-200x, and perhaps other locale models, it | |
1305 | // is possible that the format character will be longer than one | |
1306 | // character. Possibilities include 'E' or 'O' followed by a | |
1307 | // format character: if __mod is not the default argument, assume | |
1308 | // it's a valid modifier. | |
1309 | char_type __fmt[4]; | |
1310 | __fmt[0] = __ctype.widen('%'); | |
1311 | if (!__mod) | |
1312 | { | |
1313 | __fmt[1] = __format; | |
1314 | __fmt[2] = char_type(); | |
1315 | } | |
1316 | else | |
1317 | { | |
1318 | __fmt[1] = __mod; | |
1319 | __fmt[2] = __format; | |
1320 | __fmt[3] = char_type(); | |
1321 | } | |
1322 | ||
1323 | __tp._M_put(__res, __maxlen, __fmt, __tm); | |
1324 | ||
1325 | // Write resulting, fully-formatted string to output iterator. | |
1326 | return std::__write(__s, __res, char_traits<char_type>::length(__res)); | |
1327 | } | |
1328 | ||
84b31797 | 1329 | |
f749a55b PC |
1330 | // Inhibit implicit instantiations for required instantiations, |
1331 | // which are defined via explicit instantiations elsewhere. | |
f749a55b PC |
1332 | #if _GLIBCXX_EXTERN_TEMPLATE |
1333 | extern template class moneypunct<char, false>; | |
1334 | extern template class moneypunct<char, true>; | |
1335 | extern template class moneypunct_byname<char, false>; | |
1336 | extern template class moneypunct_byname<char, true>; | |
34a2b755 JW |
1337 | extern template class _GLIBCXX_NAMESPACE_LDBL_OR_CXX11 money_get<char>; |
1338 | extern template class _GLIBCXX_NAMESPACE_LDBL_OR_CXX11 money_put<char>; | |
f749a55b PC |
1339 | extern template class __timepunct<char>; |
1340 | extern template class time_put<char>; | |
1341 | extern template class time_put_byname<char>; | |
1342 | extern template class time_get<char>; | |
1343 | extern template class time_get_byname<char>; | |
1344 | extern template class messages<char>; | |
1345 | extern template class messages_byname<char>; | |
1346 | ||
1347 | extern template | |
1348 | const moneypunct<char, true>& | |
1349 | use_facet<moneypunct<char, true> >(const locale&); | |
1350 | ||
1351 | extern template | |
1352 | const moneypunct<char, false>& | |
1353 | use_facet<moneypunct<char, false> >(const locale&); | |
1354 | ||
1355 | extern template | |
1356 | const money_put<char>& | |
1357 | use_facet<money_put<char> >(const locale&); | |
1358 | ||
1359 | extern template | |
1360 | const money_get<char>& | |
1361 | use_facet<money_get<char> >(const locale&); | |
1362 | ||
1363 | extern template | |
1364 | const __timepunct<char>& | |
1365 | use_facet<__timepunct<char> >(const locale&); | |
1366 | ||
1367 | extern template | |
1368 | const time_put<char>& | |
1369 | use_facet<time_put<char> >(const locale&); | |
1370 | ||
1371 | extern template | |
1372 | const time_get<char>& | |
1373 | use_facet<time_get<char> >(const locale&); | |
1374 | ||
1375 | extern template | |
1376 | const messages<char>& | |
1377 | use_facet<messages<char> >(const locale&); | |
1378 | ||
1379 | extern template | |
1380 | bool | |
1381 | has_facet<moneypunct<char> >(const locale&); | |
1382 | ||
1383 | extern template | |
1384 | bool | |
1385 | has_facet<money_put<char> >(const locale&); | |
1386 | ||
1387 | extern template | |
1388 | bool | |
1389 | has_facet<money_get<char> >(const locale&); | |
1390 | ||
1391 | extern template | |
1392 | bool | |
1393 | has_facet<__timepunct<char> >(const locale&); | |
1394 | ||
1395 | extern template | |
1396 | bool | |
1397 | has_facet<time_put<char> >(const locale&); | |
1398 | ||
1399 | extern template | |
1400 | bool | |
1401 | has_facet<time_get<char> >(const locale&); | |
1402 | ||
1403 | extern template | |
1404 | bool | |
1405 | has_facet<messages<char> >(const locale&); | |
1406 | ||
1407 | #ifdef _GLIBCXX_USE_WCHAR_T | |
1408 | extern template class moneypunct<wchar_t, false>; | |
1409 | extern template class moneypunct<wchar_t, true>; | |
1410 | extern template class moneypunct_byname<wchar_t, false>; | |
1411 | extern template class moneypunct_byname<wchar_t, true>; | |
34a2b755 JW |
1412 | extern template class _GLIBCXX_NAMESPACE_LDBL_OR_CXX11 money_get<wchar_t>; |
1413 | extern template class _GLIBCXX_NAMESPACE_LDBL_OR_CXX11 money_put<wchar_t>; | |
f749a55b PC |
1414 | extern template class __timepunct<wchar_t>; |
1415 | extern template class time_put<wchar_t>; | |
1416 | extern template class time_put_byname<wchar_t>; | |
1417 | extern template class time_get<wchar_t>; | |
1418 | extern template class time_get_byname<wchar_t>; | |
1419 | extern template class messages<wchar_t>; | |
1420 | extern template class messages_byname<wchar_t>; | |
1421 | ||
1422 | extern template | |
1423 | const moneypunct<wchar_t, true>& | |
1424 | use_facet<moneypunct<wchar_t, true> >(const locale&); | |
1425 | ||
1426 | extern template | |
1427 | const moneypunct<wchar_t, false>& | |
1428 | use_facet<moneypunct<wchar_t, false> >(const locale&); | |
1429 | ||
1430 | extern template | |
1431 | const money_put<wchar_t>& | |
1432 | use_facet<money_put<wchar_t> >(const locale&); | |
1433 | ||
1434 | extern template | |
1435 | const money_get<wchar_t>& | |
1436 | use_facet<money_get<wchar_t> >(const locale&); | |
1437 | ||
1438 | extern template | |
1439 | const __timepunct<wchar_t>& | |
1440 | use_facet<__timepunct<wchar_t> >(const locale&); | |
1441 | ||
1442 | extern template | |
1443 | const time_put<wchar_t>& | |
1444 | use_facet<time_put<wchar_t> >(const locale&); | |
1445 | ||
1446 | extern template | |
1447 | const time_get<wchar_t>& | |
1448 | use_facet<time_get<wchar_t> >(const locale&); | |
1449 | ||
1450 | extern template | |
1451 | const messages<wchar_t>& | |
1452 | use_facet<messages<wchar_t> >(const locale&); | |
1453 | ||
1454 | extern template | |
1455 | bool | |
1456 | has_facet<moneypunct<wchar_t> >(const locale&); | |
1457 | ||
1458 | extern template | |
1459 | bool | |
1460 | has_facet<money_put<wchar_t> >(const locale&); | |
1461 | ||
1462 | extern template | |
1463 | bool | |
1464 | has_facet<money_get<wchar_t> >(const locale&); | |
1465 | ||
1466 | extern template | |
1467 | bool | |
1468 | has_facet<__timepunct<wchar_t> >(const locale&); | |
1469 | ||
1470 | extern template | |
1471 | bool | |
1472 | has_facet<time_put<wchar_t> >(const locale&); | |
1473 | ||
1474 | extern template | |
1475 | bool | |
1476 | has_facet<time_get<wchar_t> >(const locale&); | |
1477 | ||
1478 | extern template | |
1479 | bool | |
1480 | has_facet<messages<wchar_t> >(const locale&); | |
1481 | #endif | |
1482 | #endif | |
1483 | ||
12ffa228 | 1484 | _GLIBCXX_END_NAMESPACE_VERSION |
ed4f96af | 1485 | } // namespace std |
f749a55b PC |
1486 | |
1487 | #endif |