locale_facets_nonio.tcc 44 KB

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