Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/c++/15/bits/locale_facets_nonio.h
1 // Locale support -*- C++ -*- 2 3 // Copyright (C) 2007-2025 Free Software Foundation, Inc. 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 8 // Free Software Foundation; either version 3, or (at your option) 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 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. 19 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/>. 24 25 /** @file bits/locale_facets_nonio.h 26 * This is an internal header file, included by other library headers. 27 * Do not attempt to use it directly. @headername{locale} 28 */ 29 30 // 31 // ISO C++ 14882: 22.1 Locales 32 // 33 34 #ifndef _LOCALE_FACETS_NONIO_H 35 #define _LOCALE_FACETS_NONIO_H 1 36 37 #ifdef _GLIBCXX_SYSHDR 38 #pragma GCC system_header 39 #endif 40 41 #include <ctime> // For struct tm 42 43 namespace std _GLIBCXX_VISIBILITY(default) 44 { 45 _GLIBCXX_BEGIN_NAMESPACE_VERSION 46 47 /** 48 * @brief Time format ordering data. 49 * @ingroup locales 50 * 51 * This class provides an enum representing different orderings of 52 * time: day, month, and year. 53 */ 54 class time_base 55 { 56 public: 57 enum dateorder { no_order, dmy, mdy, ymd, ydm }; 58 }; 59 60 template<typename _CharT> 61 struct __timepunct_cache : public locale::facet 62 { 63 // List of all known timezones, with GMT first. 64 static const _CharT* _S_timezones[14]; 65 66 const _CharT* _M_date_format; 67 const _CharT* _M_date_era_format; 68 const _CharT* _M_time_format; 69 const _CharT* _M_time_era_format; 70 const _CharT* _M_date_time_format; 71 const _CharT* _M_date_time_era_format; 72 const _CharT* _M_am; 73 const _CharT* _M_pm; 74 const _CharT* _M_am_pm_format; 75 76 // Day names, starting with "C"'s Sunday. 77 const _CharT* _M_day1; 78 const _CharT* _M_day2; 79 const _CharT* _M_day3; 80 const _CharT* _M_day4; 81 const _CharT* _M_day5; 82 const _CharT* _M_day6; 83 const _CharT* _M_day7; 84 85 // Abbreviated day names, starting with "C"'s Sun. 86 const _CharT* _M_aday1; 87 const _CharT* _M_aday2; 88 const _CharT* _M_aday3; 89 const _CharT* _M_aday4; 90 const _CharT* _M_aday5; 91 const _CharT* _M_aday6; 92 const _CharT* _M_aday7; 93 94 // Month names, starting with "C"'s January. 95 const _CharT* _M_month01; 96 const _CharT* _M_month02; 97 const _CharT* _M_month03; 98 const _CharT* _M_month04; 99 const _CharT* _M_month05; 100 const _CharT* _M_month06; 101 const _CharT* _M_month07; 102 const _CharT* _M_month08; 103 const _CharT* _M_month09; 104 const _CharT* _M_month10; 105 const _CharT* _M_month11; 106 const _CharT* _M_month12; 107 108 // Abbreviated month names, starting with "C"'s Jan. 109 const _CharT* _M_amonth01; 110 const _CharT* _M_amonth02; 111 const _CharT* _M_amonth03; 112 const _CharT* _M_amonth04; 113 const _CharT* _M_amonth05; 114 const _CharT* _M_amonth06; 115 const _CharT* _M_amonth07; 116 const _CharT* _M_amonth08; 117 const _CharT* _M_amonth09; 118 const _CharT* _M_amonth10; 119 const _CharT* _M_amonth11; 120 const _CharT* _M_amonth12; 121 122 bool _M_allocated; 123 124 __timepunct_cache(size_t __refs = 0) : facet(__refs), 125 _M_date_format(0), _M_date_era_format(0), _M_time_format(0), 126 _M_time_era_format(0), _M_date_time_format(0), 127 _M_date_time_era_format(0), _M_am(0), _M_pm(0), 128 _M_am_pm_format(0), _M_day1(0), _M_day2(0), _M_day3(0), 129 _M_day4(0), _M_day5(0), _M_day6(0), _M_day7(0), 130 _M_aday1(0), _M_aday2(0), _M_aday3(0), _M_aday4(0), 131 _M_aday5(0), _M_aday6(0), _M_aday7(0), _M_month01(0), 132 _M_month02(0), _M_month03(0), _M_month04(0), _M_month05(0), 133 _M_month06(0), _M_month07(0), _M_month08(0), _M_month09(0), 134 _M_month10(0), _M_month11(0), _M_month12(0), _M_amonth01(0), 135 _M_amonth02(0), _M_amonth03(0), _M_amonth04(0), 136 _M_amonth05(0), _M_amonth06(0), _M_amonth07(0), 137 _M_amonth08(0), _M_amonth09(0), _M_amonth10(0), 138 _M_amonth11(0), _M_amonth12(0), _M_allocated(false) 139 { } 140 141 ~__timepunct_cache(); 142 143 private: 144 __timepunct_cache& 145 operator=(const __timepunct_cache&); 146 147 explicit 148 __timepunct_cache(const __timepunct_cache&); 149 }; 150 151 template<typename _CharT> 152 __timepunct_cache<_CharT>::~__timepunct_cache() 153 { 154 if (_M_allocated) 155 { 156 // Unused. 157 } 158 } 159 160 // Specializations. 161 template<> 162 const char* 163 __timepunct_cache<char>::_S_timezones[14]; 164 165 #ifdef _GLIBCXX_USE_WCHAR_T 166 template<> 167 const wchar_t* 168 __timepunct_cache<wchar_t>::_S_timezones[14]; 169 #endif 170 171 // Generic. 172 template<typename _CharT> 173 const _CharT* __timepunct_cache<_CharT>::_S_timezones[14]; 174 175 template<typename _CharT> 176 class __timepunct : public locale::facet 177 { 178 public: 179 // Types: 180 typedef _CharT __char_type; 181 typedef __timepunct_cache<_CharT> __cache_type; 182 183 protected: 184 __cache_type* _M_data; 185 __c_locale _M_c_locale_timepunct; 186 const char* _M_name_timepunct; 187 188 public: 189 /// Numpunct facet id. 190 static locale::id id; 191 192 explicit 193 __timepunct(size_t __refs = 0); 194 195 explicit 196 __timepunct(__cache_type* __cache, size_t __refs = 0); 197 198 /** 199 * @brief Internal constructor. Not for general use. 200 * 201 * This is a constructor for use by the library itself to set up new 202 * locales. 203 * 204 * @param __cloc The C locale. 205 * @param __s The name of a locale. 206 * @param refs Passed to the base facet class. 207 */ 208 explicit 209 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0); 210 211 // FIXME: for error checking purposes _M_put should return the return 212 // value of strftime/wcsftime. 213 void 214 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format, 215 const tm* __tm) const throw (); 216 217 void 218 _M_date_formats(const _CharT** __date) const 219 { 220 // Always have default first. 221 __date[0] = _M_data->_M_date_format; 222 __date[1] = _M_data->_M_date_era_format; 223 } 224 225 void 226 _M_time_formats(const _CharT** __time) const 227 { 228 // Always have default first. 229 __time[0] = _M_data->_M_time_format; 230 __time[1] = _M_data->_M_time_era_format; 231 } 232 233 void 234 _M_date_time_formats(const _CharT** __dt) const 235 { 236 // Always have default first. 237 __dt[0] = _M_data->_M_date_time_format; 238 __dt[1] = _M_data->_M_date_time_era_format; 239 } 240 241 #if !_GLIBCXX_INLINE_VERSION 242 void 243 _M_am_pm_format(const _CharT*) const 244 { /* Kept for ABI compatibility, see PR65927 */ } 245 #endif 246 247 void 248 _M_am_pm_format(const _CharT** __ampm_format) const 249 { 250 __ampm_format[0] = _M_data->_M_am_pm_format; 251 } 252 253 void 254 _M_am_pm(const _CharT** __ampm) const 255 { 256 __ampm[0] = _M_data->_M_am; 257 __ampm[1] = _M_data->_M_pm; 258 } 259 260 void 261 _M_days(const _CharT** __days) const 262 { 263 __days[0] = _M_data->_M_day1; 264 __days[1] = _M_data->_M_day2; 265 __days[2] = _M_data->_M_day3; 266 __days[3] = _M_data->_M_day4; 267 __days[4] = _M_data->_M_day5; 268 __days[5] = _M_data->_M_day6; 269 __days[6] = _M_data->_M_day7; 270 } 271 272 void 273 _M_days_abbreviated(const _CharT** __days) const 274 { 275 __days[0] = _M_data->_M_aday1; 276 __days[1] = _M_data->_M_aday2; 277 __days[2] = _M_data->_M_aday3; 278 __days[3] = _M_data->_M_aday4; 279 __days[4] = _M_data->_M_aday5; 280 __days[5] = _M_data->_M_aday6; 281 __days[6] = _M_data->_M_aday7; 282 } 283 284 void 285 _M_months(const _CharT** __months) const 286 { 287 __months[0] = _M_data->_M_month01; 288 __months[1] = _M_data->_M_month02; 289 __months[2] = _M_data->_M_month03; 290 __months[3] = _M_data->_M_month04; 291 __months[4] = _M_data->_M_month05; 292 __months[5] = _M_data->_M_month06; 293 __months[6] = _M_data->_M_month07; 294 __months[7] = _M_data->_M_month08; 295 __months[8] = _M_data->_M_month09; 296 __months[9] = _M_data->_M_month10; 297 __months[10] = _M_data->_M_month11; 298 __months[11] = _M_data->_M_month12; 299 } 300 301 void 302 _M_months_abbreviated(const _CharT** __months) const 303 { 304 __months[0] = _M_data->_M_amonth01; 305 __months[1] = _M_data->_M_amonth02; 306 __months[2] = _M_data->_M_amonth03; 307 __months[3] = _M_data->_M_amonth04; 308 __months[4] = _M_data->_M_amonth05; 309 __months[5] = _M_data->_M_amonth06; 310 __months[6] = _M_data->_M_amonth07; 311 __months[7] = _M_data->_M_amonth08; 312 __months[8] = _M_data->_M_amonth09; 313 __months[9] = _M_data->_M_amonth10; 314 __months[10] = _M_data->_M_amonth11; 315 __months[11] = _M_data->_M_amonth12; 316 } 317 318 protected: 319 virtual 320 ~__timepunct(); 321 322 // For use at construction time only. 323 void 324 _M_initialize_timepunct(__c_locale __cloc = 0); 325 }; 326 327 template<typename _CharT> 328 locale::id __timepunct<_CharT>::id; 329 330 // Specializations. 331 template<> 332 void 333 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc); 334 335 template<> 336 void 337 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const throw (); 338 339 #ifdef _GLIBCXX_USE_WCHAR_T 340 template<> 341 void 342 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc); 343 344 template<> 345 void 346 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*, 347 const tm*) const throw (); 348 #endif 349 350 _GLIBCXX_END_NAMESPACE_VERSION 351 } // namespace 352 353 // Include host and configuration specific timepunct functions. 354 #include <bits/time_members.h> 355 356 namespace std _GLIBCXX_VISIBILITY(default) 357 { 358 _GLIBCXX_BEGIN_NAMESPACE_VERSION 359 360 struct __time_get_state 361 { 362 // Finalize state. 363 void 364 _M_finalize_state(tm* __tm); 365 366 unsigned int _M_have_I : 1; 367 unsigned int _M_have_wday : 1; 368 unsigned int _M_have_yday : 1; 369 unsigned int _M_have_mon : 1; 370 unsigned int _M_have_mday : 1; 371 unsigned int _M_have_uweek : 1; 372 unsigned int _M_have_wweek : 1; 373 unsigned int _M_have_century : 1; 374 unsigned int _M_is_pm : 1; 375 unsigned int _M_want_century : 1; 376 unsigned int _M_want_xday : 1; 377 unsigned int _M_pad1 : 5; 378 unsigned int _M_week_no : 6; 379 unsigned int _M_pad2 : 10; 380 int _M_century; 381 int _M_pad3; 382 }; 383 384 _GLIBCXX_BEGIN_NAMESPACE_CXX11 385 386 /** 387 * @brief Primary class template time_get. 388 * @ingroup locales 389 * 390 * This facet encapsulates the code to parse and return a date or 391 * time from a string. It is used by the istream numeric 392 * extraction operators. 393 * 394 * The time_get template uses protected virtual functions to provide the 395 * actual results. The public accessors forward the call to the virtual 396 * functions. These virtual functions are hooks for developers to 397 * implement the behavior they require from the time_get facet. 398 */ 399 template<typename _CharT, typename _InIter> 400 class time_get : public locale::facet, public time_base 401 { 402 public: 403 // Types: 404 ///@{ 405 /// Public typedefs 406 typedef _CharT char_type; 407 typedef _InIter iter_type; 408 ///@} 409 410 /// Numpunct facet id. 411 static locale::id id; 412 413 /** 414 * @brief Constructor performs initialization. 415 * 416 * This is the constructor provided by the standard. 417 * 418 * @param __refs Passed to the base facet class. 419 */ 420 explicit 421 time_get(size_t __refs = 0) 422 : facet (__refs) { } 423 424 /** 425 * @brief Return preferred order of month, day, and year. 426 * 427 * This function returns an enum from time_base::dateorder giving the 428 * preferred ordering if the format @a x given to time_put::put() only 429 * uses month, day, and year. If the format @a x for the associated 430 * locale uses other fields, this function returns 431 * time_base::dateorder::noorder. 432 * 433 * NOTE: The library always returns noorder at the moment. 434 * 435 * @return A member of time_base::dateorder. 436 */ 437 dateorder 438 date_order() const 439 { return this->do_date_order(); } 440 441 /** 442 * @brief Parse input time string. 443 * 444 * This function parses a time according to the format @a X and puts the 445 * results into a user-supplied struct tm. The result is returned by 446 * calling time_get::do_get_time(). 447 * 448 * If there is a valid time string according to format @a X, @a tm will 449 * be filled in accordingly and the returned iterator will point to the 450 * first character beyond the time string. If an error occurs before 451 * the end, err |= ios_base::failbit. If parsing reads all the 452 * characters, err |= ios_base::eofbit. 453 * 454 * @param __beg Start of string to parse. 455 * @param __end End of string to parse. 456 * @param __io Source of the locale. 457 * @param __err Error flags to set. 458 * @param __tm Pointer to struct tm to fill in. 459 * @return Iterator to first char beyond time string. 460 */ 461 iter_type 462 get_time(iter_type __beg, iter_type __end, ios_base& __io, 463 ios_base::iostate& __err, tm* __tm) const 464 { return this->do_get_time(__beg, __end, __io, __err, __tm); } 465 466 /** 467 * @brief Parse input date string. 468 * 469 * This function parses a date according to the format @a x and puts the 470 * results into a user-supplied struct tm. The result is returned by 471 * calling time_get::do_get_date(). 472 * 473 * If there is a valid date string according to format @a x, @a tm will 474 * be filled in accordingly and the returned iterator will point to the 475 * first character beyond the date string. If an error occurs before 476 * the end, err |= ios_base::failbit. If parsing reads all the 477 * characters, err |= ios_base::eofbit. 478 * 479 * @param __beg Start of string to parse. 480 * @param __end End of string to parse. 481 * @param __io Source of the locale. 482 * @param __err Error flags to set. 483 * @param __tm Pointer to struct tm to fill in. 484 * @return Iterator to first char beyond date string. 485 */ 486 iter_type 487 get_date(iter_type __beg, iter_type __end, ios_base& __io, 488 ios_base::iostate& __err, tm* __tm) const 489 { return this->do_get_date(__beg, __end, __io, __err, __tm); } 490 491 /** 492 * @brief Parse input weekday string. 493 * 494 * This function parses a weekday name and puts the results into a 495 * user-supplied struct tm. The result is returned by calling 496 * time_get::do_get_weekday(). 497 * 498 * Parsing starts by parsing an abbreviated weekday name. If a valid 499 * abbreviation is followed by a character that would lead to the full 500 * weekday name, parsing continues until the full name is found or an 501 * error occurs. Otherwise parsing finishes at the end of the 502 * abbreviated name. 503 * 504 * If an error occurs before the end, err |= ios_base::failbit. If 505 * parsing reads all the characters, err |= ios_base::eofbit. 506 * 507 * @param __beg Start of string to parse. 508 * @param __end End of string to parse. 509 * @param __io Source of the locale. 510 * @param __err Error flags to set. 511 * @param __tm Pointer to struct tm to fill in. 512 * @return Iterator to first char beyond weekday name. 513 */ 514 iter_type 515 get_weekday(iter_type __beg, iter_type __end, ios_base& __io, 516 ios_base::iostate& __err, tm* __tm) const 517 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); } 518 519 /** 520 * @brief Parse input month string. 521 * 522 * This function parses a month name and puts the results into a 523 * user-supplied struct tm. The result is returned by calling 524 * time_get::do_get_monthname(). 525 * 526 * Parsing starts by parsing an abbreviated month name. If a valid 527 * abbreviation is followed by a character that would lead to the full 528 * month name, parsing continues until the full name is found or an 529 * error occurs. Otherwise parsing finishes at the end of the 530 * abbreviated name. 531 * 532 * If an error occurs before the end, err |= ios_base::failbit. If 533 * parsing reads all the characters, err |= 534 * ios_base::eofbit. 535 * 536 * @param __beg Start of string to parse. 537 * @param __end End of string to parse. 538 * @param __io Source of the locale. 539 * @param __err Error flags to set. 540 * @param __tm Pointer to struct tm to fill in. 541 * @return Iterator to first char beyond month name. 542 */ 543 iter_type 544 get_monthname(iter_type __beg, iter_type __end, ios_base& __io, 545 ios_base::iostate& __err, tm* __tm) const 546 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); } 547 548 /** 549 * @brief Parse input year string. 550 * 551 * This function reads up to 4 characters to parse a year string and 552 * puts the results into a user-supplied struct tm. The result is 553 * returned by calling time_get::do_get_year(). 554 * 555 * 4 consecutive digits are interpreted as a full year. If there are 556 * exactly 2 consecutive digits, the library interprets this as the 557 * number of years since 1900. 558 * 559 * If an error occurs before the end, err |= ios_base::failbit. If 560 * parsing reads all the characters, err |= ios_base::eofbit. 561 * 562 * @param __beg Start of string to parse. 563 * @param __end End of string to parse. 564 * @param __io Source of the locale. 565 * @param __err Error flags to set. 566 * @param __tm Pointer to struct tm to fill in. 567 * @return Iterator to first char beyond year. 568 */ 569 iter_type 570 get_year(iter_type __beg, iter_type __end, ios_base& __io, 571 ios_base::iostate& __err, tm* __tm) const 572 { return this->do_get_year(__beg, __end, __io, __err, __tm); } 573 574 #if __cplusplus >= 201103L 575 /** 576 * @brief Parse input string according to format. 577 * 578 * This function calls time_get::do_get with the provided 579 * parameters. @see do_get() and get(). 580 * 581 * @param __s Start of string to parse. 582 * @param __end End of string to parse. 583 * @param __io Source of the locale. 584 * @param __err Error flags to set. 585 * @param __tm Pointer to struct tm to fill in. 586 * @param __format Format specifier. 587 * @param __modifier Format modifier. 588 * @return Iterator to first char not parsed. 589 */ 590 inline 591 iter_type get(iter_type __s, iter_type __end, ios_base& __io, 592 ios_base::iostate& __err, tm* __tm, char __format, 593 char __modifier = 0) const 594 { 595 return this->do_get(__s, __end, __io, __err, __tm, __format, 596 __modifier); 597 } 598 599 /** 600 * @brief Parse input string according to format. 601 * 602 * This function parses the input string according to a 603 * provided format string. It does the inverse of 604 * time_put::put. The format string follows the format 605 * specified for strftime(3)/strptime(3). The actual parsing 606 * is done by time_get::do_get. 607 * 608 * @param __s Start of string to parse. 609 * @param __end End of string to parse. 610 * @param __io Source of the locale. 611 * @param __err Error flags to set. 612 * @param __tm Pointer to struct tm to fill in. 613 * @param __fmt Start of the format string. 614 * @param __fmtend End of the format string. 615 * @return Iterator to first char not parsed. 616 */ 617 iter_type get(iter_type __s, iter_type __end, ios_base& __io, 618 ios_base::iostate& __err, tm* __tm, const char_type* __fmt, 619 const char_type* __fmtend) const; 620 #endif // __cplusplus >= 201103L 621 622 protected: 623 /// Destructor. 624 virtual 625 ~time_get() { } 626 627 /** 628 * @brief Return preferred order of month, day, and year. 629 * 630 * This function returns an enum from time_base::dateorder giving the 631 * preferred ordering if the format @a x given to time_put::put() only 632 * uses month, day, and year. This function is a hook for derived 633 * classes to change the value returned. 634 * 635 * @return A member of time_base::dateorder. 636 */ 637 virtual dateorder 638 do_date_order() const; 639 640 /** 641 * @brief Parse input time string. 642 * 643 * This function parses a time according to the format @a x and puts the 644 * results into a user-supplied struct tm. This function is a hook for 645 * derived classes to change the value returned. @see get_time() for 646 * details. 647 * 648 * @param __beg Start of string to parse. 649 * @param __end End of string to parse. 650 * @param __io Source of the locale. 651 * @param __err Error flags to set. 652 * @param __tm Pointer to struct tm to fill in. 653 * @return Iterator to first char beyond time string. 654 */ 655 virtual iter_type 656 do_get_time(iter_type __beg, iter_type __end, ios_base& __io, 657 ios_base::iostate& __err, tm* __tm) const; 658 659 /** 660 * @brief Parse input date string. 661 * 662 * This function parses a date according to the format @a X and puts the 663 * results into a user-supplied struct tm. This function is a hook for 664 * derived classes to change the value returned. @see get_date() for 665 * details. 666 * 667 * @param __beg Start of string to parse. 668 * @param __end End of string to parse. 669 * @param __io Source of the locale. 670 * @param __err Error flags to set. 671 * @param __tm Pointer to struct tm to fill in. 672 * @return Iterator to first char beyond date string. 673 */ 674 virtual iter_type 675 do_get_date(iter_type __beg, iter_type __end, ios_base& __io, 676 ios_base::iostate& __err, tm* __tm) const; 677 678 /** 679 * @brief Parse input weekday string. 680 * 681 * This function parses a weekday name and puts the results into a 682 * user-supplied struct tm. This function is a hook for derived 683 * classes to change the value returned. @see get_weekday() for 684 * details. 685 * 686 * @param __beg Start of string to parse. 687 * @param __end End of string to parse. 688 * @param __io Source of the locale. 689 * @param __err Error flags to set. 690 * @param __tm Pointer to struct tm to fill in. 691 * @return Iterator to first char beyond weekday name. 692 */ 693 virtual iter_type 694 do_get_weekday(iter_type __beg, iter_type __end, ios_base&, 695 ios_base::iostate& __err, tm* __tm) const; 696 697 /** 698 * @brief Parse input month string. 699 * 700 * This function parses a month name and puts the results into a 701 * user-supplied struct tm. This function is a hook for derived 702 * classes to change the value returned. @see get_monthname() for 703 * details. 704 * 705 * @param __beg Start of string to parse. 706 * @param __end End of string to parse. 707 * @param __io Source of the locale. 708 * @param __err Error flags to set. 709 * @param __tm Pointer to struct tm to fill in. 710 * @return Iterator to first char beyond month name. 711 */ 712 virtual iter_type 713 do_get_monthname(iter_type __beg, iter_type __end, ios_base&, 714 ios_base::iostate& __err, tm* __tm) const; 715 716 /** 717 * @brief Parse input year string. 718 * 719 * This function reads up to 4 characters to parse a year string and 720 * puts the results into a user-supplied struct tm. This function is a 721 * hook for derived classes to change the value returned. @see 722 * get_year() for details. 723 * 724 * @param __beg Start of string to parse. 725 * @param __end End of string to parse. 726 * @param __io Source of the locale. 727 * @param __err Error flags to set. 728 * @param __tm Pointer to struct tm to fill in. 729 * @return Iterator to first char beyond year. 730 */ 731 virtual iter_type 732 do_get_year(iter_type __beg, iter_type __end, ios_base& __io, 733 ios_base::iostate& __err, tm* __tm) const; 734 735 #if __cplusplus >= 201103L 736 /** 737 * @brief Parse input string according to format. 738 * 739 * This function parses the string according to the provided 740 * format and optional modifier. This function is a hook for 741 * derived classes to change the value returned. @see get() 742 * for more details. 743 * 744 * @param __s Start of string to parse. 745 * @param __end End of string to parse. 746 * @param __f Source of the locale. 747 * @param __err Error flags to set. 748 * @param __tm Pointer to struct tm to fill in. 749 * @param __format Format specifier. 750 * @param __modifier Format modifier. 751 * @return Iterator to first char not parsed. 752 */ 753 #if _GLIBCXX_USE_CXX11_ABI 754 virtual 755 #endif 756 iter_type 757 do_get(iter_type __s, iter_type __end, ios_base& __f, 758 ios_base::iostate& __err, tm* __tm, 759 char __format, char __modifier) const; 760 #endif // __cplusplus >= 201103L 761 762 // Extract numeric component of length __len. 763 iter_type 764 _M_extract_num(iter_type __beg, iter_type __end, int& __member, 765 int __min, int __max, size_t __len, 766 ios_base& __io, ios_base::iostate& __err) const; 767 768 // Extract any unique array of string literals in a const _CharT* array. 769 iter_type 770 _M_extract_name(iter_type __beg, iter_type __end, int& __member, 771 const _CharT** __names, size_t __indexlen, 772 ios_base& __io, ios_base::iostate& __err) const; 773 774 // Extract day or month name in a const _CharT* array. 775 iter_type 776 _M_extract_wday_or_month(iter_type __beg, iter_type __end, int& __member, 777 const _CharT** __names, size_t __indexlen, 778 ios_base& __io, ios_base::iostate& __err) const; 779 780 // Extract on a component-by-component basis, via __format argument. 781 iter_type 782 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io, 783 ios_base::iostate& __err, tm* __tm, 784 const _CharT* __format) const; 785 786 // Extract on a component-by-component basis, via __format argument, with 787 // state. 788 iter_type 789 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io, 790 ios_base::iostate& __err, tm* __tm, 791 const _CharT* __format, 792 __time_get_state &__state) const; 793 }; 794 795 template<typename _CharT, typename _InIter> 796 locale::id time_get<_CharT, _InIter>::id; 797 798 /// class time_get_byname [22.2.5.2]. 799 template<typename _CharT, typename _InIter> 800 class time_get_byname : public time_get<_CharT, _InIter> 801 { 802 public: 803 // Types: 804 typedef _CharT char_type; 805 typedef _InIter iter_type; 806 807 explicit 808 time_get_byname(const char*, size_t __refs = 0) 809 : time_get<_CharT, _InIter>(__refs) { } 810 811 #if __cplusplus >= 201103L 812 explicit 813 time_get_byname(const string& __s, size_t __refs = 0) 814 : time_get_byname(__s.c_str(), __refs) { } 815 #endif 816 817 protected: 818 virtual 819 ~time_get_byname() { } 820 }; 821 822 _GLIBCXX_END_NAMESPACE_CXX11 823 824 /** 825 * @brief Primary class template time_put. 826 * @ingroup locales 827 * 828 * This facet encapsulates the code to format and output dates and times 829 * according to formats used by strftime(). 830 * 831 * The time_put template uses protected virtual functions to provide the 832 * actual results. The public accessors forward the call to the virtual 833 * functions. These virtual functions are hooks for developers to 834 * implement the behavior they require from the time_put facet. 835 */ 836 template<typename _CharT, typename _OutIter> 837 class time_put : public locale::facet 838 { 839 public: 840 // Types: 841 ///@{ 842 /// Public typedefs 843 typedef _CharT char_type; 844 typedef _OutIter iter_type; 845 ///@} 846 847 /// Numpunct facet id. 848 static locale::id id; 849 850 /** 851 * @brief Constructor performs initialization. 852 * 853 * This is the constructor provided by the standard. 854 * 855 * @param __refs Passed to the base facet class. 856 */ 857 explicit 858 time_put(size_t __refs = 0) 859 : facet(__refs) { } 860 861 /** 862 * @brief Format and output a time or date. 863 * 864 * This function formats the data in struct tm according to the 865 * provided format string. The format string is interpreted as by 866 * strftime(). 867 * 868 * @param __s The stream to write to. 869 * @param __io Source of locale. 870 * @param __fill char_type to use for padding. 871 * @param __tm Struct tm with date and time info to format. 872 * @param __beg Start of format string. 873 * @param __end End of format string. 874 * @return Iterator after writing. 875 */ 876 iter_type 877 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 878 const _CharT* __beg, const _CharT* __end) const; 879 880 /** 881 * @brief Format and output a time or date. 882 * 883 * This function formats the data in struct tm according to the 884 * provided format char and optional modifier. The format and modifier 885 * are interpreted as by strftime(). It does so by returning 886 * time_put::do_put(). 887 * 888 * @param __s The stream to write to. 889 * @param __io Source of locale. 890 * @param __fill char_type to use for padding. 891 * @param __tm Struct tm with date and time info to format. 892 * @param __format Format char. 893 * @param __mod Optional modifier char. 894 * @return Iterator after writing. 895 */ 896 iter_type 897 put(iter_type __s, ios_base& __io, char_type __fill, 898 const tm* __tm, char __format, char __mod = 0) const 899 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); } 900 901 protected: 902 /// Destructor. 903 virtual 904 ~time_put() 905 { } 906 907 /** 908 * @brief Format and output a time or date. 909 * 910 * This function formats the data in struct tm according to the 911 * provided format char and optional modifier. This function is a hook 912 * for derived classes to change the value returned. @see put() for 913 * more details. 914 * 915 * @param __s The stream to write to. 916 * @param __io Source of locale. 917 * @param __fill char_type to use for padding. 918 * @param __tm Struct tm with date and time info to format. 919 * @param __format Format char. 920 * @param __mod Optional modifier char. 921 * @return Iterator after writing. 922 */ 923 virtual iter_type 924 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 925 char __format, char __mod) const; 926 }; 927 928 template<typename _CharT, typename _OutIter> 929 locale::id time_put<_CharT, _OutIter>::id; 930 931 /// class time_put_byname [22.2.5.4]. 932 template<typename _CharT, typename _OutIter> 933 class time_put_byname : public time_put<_CharT, _OutIter> 934 { 935 public: 936 // Types: 937 typedef _CharT char_type; 938 typedef _OutIter iter_type; 939 940 explicit 941 time_put_byname(const char*, size_t __refs = 0) 942 : time_put<_CharT, _OutIter>(__refs) 943 { } 944 945 #if __cplusplus >= 201103L 946 explicit 947 time_put_byname(const string& __s, size_t __refs = 0) 948 : time_put_byname(__s.c_str(), __refs) { } 949 #endif 950 951 protected: 952 virtual 953 ~time_put_byname() { } 954 }; 955 956 957 /** 958 * @brief Money format ordering data. 959 * @ingroup locales 960 * 961 * This class contains an ordered array of 4 fields to represent the 962 * pattern for formatting a money amount. Each field may contain one entry 963 * from the part enum. symbol, sign, and value must be present and the 964 * remaining field must contain either none or space. @see 965 * moneypunct::pos_format() and moneypunct::neg_format() for details of how 966 * these fields are interpreted. 967 */ 968 class money_base 969 { 970 public: 971 enum part { none, space, symbol, sign, value }; 972 struct pattern { char field[4]; }; 973 974 static const pattern _S_default_pattern; 975 976 enum 977 { 978 _S_minus, 979 _S_zero, 980 _S_end = 11 981 }; 982 983 // String literal of acceptable (narrow) input/output, for 984 // money_get/money_put. "-0123456789" 985 static const char* _S_atoms; 986 987 // Construct and return valid pattern consisting of some combination of: 988 // space none symbol sign value 989 _GLIBCXX_CONST static pattern 990 _S_construct_pattern(char __precedes, char __space, char __posn) throw (); 991 }; 992 993 template<typename _CharT, bool _Intl> 994 struct __moneypunct_cache : public locale::facet 995 { 996 const char* _M_grouping; 997 size_t _M_grouping_size; 998 bool _M_use_grouping; 999 _CharT _M_decimal_point; 1000 _CharT _M_thousands_sep; 1001 const _CharT* _M_curr_symbol; 1002 size_t _M_curr_symbol_size; 1003 const _CharT* _M_positive_sign; 1004 size_t _M_positive_sign_size; 1005 const _CharT* _M_negative_sign; 1006 size_t _M_negative_sign_size; 1007 int _M_frac_digits; 1008 money_base::pattern _M_pos_format; 1009 money_base::pattern _M_neg_format; 1010 1011 // A list of valid numeric literals for input and output: in the standard 1012 // "C" locale, this is "-0123456789". This array contains the chars after 1013 // having been passed through the current locale's ctype<_CharT>.widen(). 1014 _CharT _M_atoms[money_base::_S_end]; 1015 1016 bool _M_allocated; 1017 1018 __moneypunct_cache(size_t __refs = 0) : facet(__refs), 1019 _M_grouping(0), _M_grouping_size(0), _M_use_grouping(false), 1020 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()), 1021 _M_curr_symbol(0), _M_curr_symbol_size(0), 1022 _M_positive_sign(0), _M_positive_sign_size(0), 1023 _M_negative_sign(0), _M_negative_sign_size(0), 1024 _M_frac_digits(0), 1025 _M_pos_format(money_base::pattern()), 1026 _M_neg_format(money_base::pattern()), _M_allocated(false) 1027 { } 1028 1029 ~__moneypunct_cache(); 1030 1031 void 1032 _M_cache(const locale& __loc); 1033 1034 private: 1035 __moneypunct_cache& 1036 operator=(const __moneypunct_cache&); 1037 1038 explicit 1039 __moneypunct_cache(const __moneypunct_cache&); 1040 }; 1041 1042 template<typename _CharT, bool _Intl> 1043 __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache() 1044 { 1045 if (_M_allocated) 1046 { 1047 delete [] _M_grouping; 1048 delete [] _M_curr_symbol; 1049 delete [] _M_positive_sign; 1050 delete [] _M_negative_sign; 1051 } 1052 } 1053 1054 _GLIBCXX_BEGIN_NAMESPACE_CXX11 1055 1056 /** 1057 * @brief Primary class template moneypunct. 1058 * @ingroup locales 1059 * 1060 * This facet encapsulates the punctuation, grouping and other formatting 1061 * features of money amount string representations. 1062 */ 1063 template<typename _CharT, bool _Intl> 1064 class moneypunct : public locale::facet, public money_base 1065 { 1066 public: 1067 // Types: 1068 ///@{ 1069 /// Public typedefs 1070 typedef _CharT char_type; 1071 typedef basic_string<_CharT> string_type; 1072 ///@} 1073 typedef __moneypunct_cache<_CharT, _Intl> __cache_type; 1074 1075 private: 1076 __cache_type* _M_data; 1077 1078 public: 1079 /// This value is provided by the standard, but no reason for its 1080 /// existence. 1081 static const bool intl = _Intl; 1082 /// Numpunct facet id. 1083 static locale::id id; 1084 1085 /** 1086 * @brief Constructor performs initialization. 1087 * 1088 * This is the constructor provided by the standard. 1089 * 1090 * @param __refs Passed to the base facet class. 1091 */ 1092 explicit 1093 moneypunct(size_t __refs = 0) 1094 : facet(__refs), _M_data(0) 1095 { _M_initialize_moneypunct(); } 1096 1097 /** 1098 * @brief Constructor performs initialization. 1099 * 1100 * This is an internal constructor. 1101 * 1102 * @param __cache Cache for optimization. 1103 * @param __refs Passed to the base facet class. 1104 */ 1105 explicit 1106 moneypunct(__cache_type* __cache, size_t __refs = 0) 1107 : facet(__refs), _M_data(__cache) 1108 { _M_initialize_moneypunct(); } 1109 1110 /** 1111 * @brief Internal constructor. Not for general use. 1112 * 1113 * This is a constructor for use by the library itself to set up new 1114 * locales. 1115 * 1116 * @param __cloc The C locale. 1117 * @param __s The name of a locale. 1118 * @param __refs Passed to the base facet class. 1119 */ 1120 explicit 1121 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0) 1122 : facet(__refs), _M_data(0) 1123 { _M_initialize_moneypunct(__cloc, __s); } 1124 1125 /** 1126 * @brief Return decimal point character. 1127 * 1128 * This function returns a char_type to use as a decimal point. It 1129 * does so by returning returning 1130 * moneypunct<char_type>::do_decimal_point(). 1131 * 1132 * @return @a char_type representing a decimal point. 1133 */ 1134 char_type 1135 decimal_point() const 1136 { return this->do_decimal_point(); } 1137 1138 /** 1139 * @brief Return thousands separator character. 1140 * 1141 * This function returns a char_type to use as a thousands 1142 * separator. It does so by returning returning 1143 * moneypunct<char_type>::do_thousands_sep(). 1144 * 1145 * @return char_type representing a thousands separator. 1146 */ 1147 char_type 1148 thousands_sep() const 1149 { return this->do_thousands_sep(); } 1150 1151 /** 1152 * @brief Return grouping specification. 1153 * 1154 * This function returns a string representing groupings for the 1155 * integer part of an amount. Groupings indicate where thousands 1156 * separators should be inserted. 1157 * 1158 * Each char in the return string is interpret as an integer rather 1159 * than a character. These numbers represent the number of digits in a 1160 * group. The first char in the string represents the number of digits 1161 * in the least significant group. If a char is negative, it indicates 1162 * an unlimited number of digits for the group. If more chars from the 1163 * string are required to group a number, the last char is used 1164 * repeatedly. 1165 * 1166 * For example, if the grouping() returns <code>\003\002</code> 1167 * and is applied to the number 123456789, this corresponds to 1168 * 12,34,56,789. Note that if the string was <code>32</code>, this would 1169 * put more than 50 digits into the least significant group if 1170 * the character set is ASCII. 1171 * 1172 * The string is returned by calling 1173 * moneypunct<char_type>::do_grouping(). 1174 * 1175 * @return string representing grouping specification. 1176 */ 1177 string 1178 grouping() const 1179 { return this->do_grouping(); } 1180 1181 /** 1182 * @brief Return currency symbol string. 1183 * 1184 * This function returns a string_type to use as a currency symbol. It 1185 * does so by returning returning 1186 * moneypunct<char_type>::do_curr_symbol(). 1187 * 1188 * @return @a string_type representing a currency symbol. 1189 */ 1190 string_type 1191 curr_symbol() const 1192 { return this->do_curr_symbol(); } 1193 1194 /** 1195 * @brief Return positive sign string. 1196 * 1197 * This function returns a string_type to use as a sign for positive 1198 * amounts. It does so by returning returning 1199 * moneypunct<char_type>::do_positive_sign(). 1200 * 1201 * If the return value contains more than one character, the first 1202 * character appears in the position indicated by pos_format() and the 1203 * remainder appear at the end of the formatted string. 1204 * 1205 * @return @a string_type representing a positive sign. 1206 */ 1207 string_type 1208 positive_sign() const 1209 { return this->do_positive_sign(); } 1210 1211 /** 1212 * @brief Return negative sign string. 1213 * 1214 * This function returns a string_type to use as a sign for negative 1215 * amounts. It does so by returning returning 1216 * moneypunct<char_type>::do_negative_sign(). 1217 * 1218 * If the return value contains more than one character, the first 1219 * character appears in the position indicated by neg_format() and the 1220 * remainder appear at the end of the formatted string. 1221 * 1222 * @return @a string_type representing a negative sign. 1223 */ 1224 string_type 1225 negative_sign() const 1226 { return this->do_negative_sign(); } 1227 1228 /** 1229 * @brief Return number of digits in fraction. 1230 * 1231 * This function returns the exact number of digits that make up the 1232 * fractional part of a money amount. It does so by returning 1233 * returning moneypunct<char_type>::do_frac_digits(). 1234 * 1235 * The fractional part of a money amount is optional. But if it is 1236 * present, there must be frac_digits() digits. 1237 * 1238 * @return Number of digits in amount fraction. 1239 */ 1240 int 1241 frac_digits() const 1242 { return this->do_frac_digits(); } 1243 1244 ///@{ 1245 /** 1246 * @brief Return pattern for money values. 1247 * 1248 * This function returns a pattern describing the formatting of a 1249 * positive or negative valued money amount. It does so by returning 1250 * returning moneypunct<char_type>::do_pos_format() or 1251 * moneypunct<char_type>::do_neg_format(). 1252 * 1253 * The pattern has 4 fields describing the ordering of symbol, sign, 1254 * value, and none or space. There must be one of each in the pattern. 1255 * The none and space enums may not appear in the first field and space 1256 * may not appear in the final field. 1257 * 1258 * The parts of a money string must appear in the order indicated by 1259 * the fields of the pattern. The symbol field indicates that the 1260 * value of curr_symbol() may be present. The sign field indicates 1261 * that the value of positive_sign() or negative_sign() must be 1262 * present. The value field indicates that the absolute value of the 1263 * money amount is present. none indicates 0 or more whitespace 1264 * characters, except at the end, where it permits no whitespace. 1265 * space indicates that 1 or more whitespace characters must be 1266 * present. 1267 * 1268 * For example, for the US locale and pos_format() pattern 1269 * {symbol,sign,value,none}, curr_symbol() == '$' 1270 * positive_sign() == '+', and value 10.01, and 1271 * options set to force the symbol, the corresponding string is 1272 * <code>$+10.01</code>. 1273 * 1274 * @return Pattern for money values. 1275 */ 1276 pattern 1277 pos_format() const 1278 { return this->do_pos_format(); } 1279 1280 pattern 1281 neg_format() const 1282 { return this->do_neg_format(); } 1283 ///@} 1284 1285 protected: 1286 /// Destructor. 1287 virtual 1288 ~moneypunct(); 1289 1290 /** 1291 * @brief Return decimal point character. 1292 * 1293 * Returns a char_type to use as a decimal point. This function is a 1294 * hook for derived classes to change the value returned. 1295 * 1296 * @return @a char_type representing a decimal point. 1297 */ 1298 virtual char_type 1299 do_decimal_point() const 1300 { return _M_data->_M_decimal_point; } 1301 1302 /** 1303 * @brief Return thousands separator character. 1304 * 1305 * Returns a char_type to use as a thousands separator. This function 1306 * is a hook for derived classes to change the value returned. 1307 * 1308 * @return @a char_type representing a thousands separator. 1309 */ 1310 virtual char_type 1311 do_thousands_sep() const 1312 { return _M_data->_M_thousands_sep; } 1313 1314 /** 1315 * @brief Return grouping specification. 1316 * 1317 * Returns a string representing groupings for the integer part of a 1318 * number. This function is a hook for derived classes to change the 1319 * value returned. @see grouping() for details. 1320 * 1321 * @return String representing grouping specification. 1322 */ 1323 virtual string 1324 do_grouping() const 1325 { return _M_data->_M_grouping; } 1326 1327 /** 1328 * @brief Return currency symbol string. 1329 * 1330 * This function returns a string_type to use as a currency symbol. 1331 * This function is a hook for derived classes to change the value 1332 * returned. @see curr_symbol() for details. 1333 * 1334 * @return @a string_type representing a currency symbol. 1335 */ 1336 virtual string_type 1337 do_curr_symbol() const 1338 { return _M_data->_M_curr_symbol; } 1339 1340 /** 1341 * @brief Return positive sign string. 1342 * 1343 * This function returns a string_type to use as a sign for positive 1344 * amounts. This function is a hook for derived classes to change the 1345 * value returned. @see positive_sign() for details. 1346 * 1347 * @return @a string_type representing a positive sign. 1348 */ 1349 virtual string_type 1350 do_positive_sign() const 1351 { return _M_data->_M_positive_sign; } 1352 1353 /** 1354 * @brief Return negative sign string. 1355 * 1356 * This function returns a string_type to use as a sign for negative 1357 * amounts. This function is a hook for derived classes to change the 1358 * value returned. @see negative_sign() for details. 1359 * 1360 * @return @a string_type representing a negative sign. 1361 */ 1362 virtual string_type 1363 do_negative_sign() const 1364 { return _M_data->_M_negative_sign; } 1365 1366 /** 1367 * @brief Return number of digits in fraction. 1368 * 1369 * This function returns the exact number of digits that make up the 1370 * fractional part of a money amount. This function is a hook for 1371 * derived classes to change the value returned. @see frac_digits() 1372 * for details. 1373 * 1374 * @return Number of digits in amount fraction. 1375 */ 1376 virtual int 1377 do_frac_digits() const 1378 { return _M_data->_M_frac_digits; } 1379 1380 /** 1381 * @brief Return pattern for money values. 1382 * 1383 * This function returns a pattern describing the formatting of a 1384 * positive valued money amount. This function is a hook for derived 1385 * classes to change the value returned. @see pos_format() for 1386 * details. 1387 * 1388 * @return Pattern for money values. 1389 */ 1390 virtual pattern 1391 do_pos_format() const 1392 { return _M_data->_M_pos_format; } 1393 1394 /** 1395 * @brief Return pattern for money values. 1396 * 1397 * This function returns a pattern describing the formatting of a 1398 * negative valued money amount. This function is a hook for derived 1399 * classes to change the value returned. @see neg_format() for 1400 * details. 1401 * 1402 * @return Pattern for money values. 1403 */ 1404 virtual pattern 1405 do_neg_format() const 1406 { return _M_data->_M_neg_format; } 1407 1408 // For use at construction time only. 1409 void 1410 _M_initialize_moneypunct(__c_locale __cloc = 0, 1411 const char* __name = 0); 1412 }; 1413 1414 template<typename _CharT, bool _Intl> 1415 locale::id moneypunct<_CharT, _Intl>::id; 1416 1417 template<typename _CharT, bool _Intl> 1418 const bool moneypunct<_CharT, _Intl>::intl; 1419 1420 template<> 1421 moneypunct<char, true>::~moneypunct(); 1422 1423 template<> 1424 moneypunct<char, false>::~moneypunct(); 1425 1426 template<> 1427 void 1428 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*); 1429 1430 template<> 1431 void 1432 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*); 1433 1434 #ifdef _GLIBCXX_USE_WCHAR_T 1435 template<> 1436 moneypunct<wchar_t, true>::~moneypunct(); 1437 1438 template<> 1439 moneypunct<wchar_t, false>::~moneypunct(); 1440 1441 template<> 1442 void 1443 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale, 1444 const char*); 1445 1446 template<> 1447 void 1448 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale, 1449 const char*); 1450 #endif 1451 1452 /// class moneypunct_byname [22.2.6.4]. 1453 template<typename _CharT, bool _Intl> 1454 class moneypunct_byname : public moneypunct<_CharT, _Intl> 1455 { 1456 public: 1457 typedef _CharT char_type; 1458 typedef basic_string<_CharT> string_type; 1459 1460 static const bool intl = _Intl; 1461 1462 explicit 1463 moneypunct_byname(const char* __s, size_t __refs = 0) 1464 : moneypunct<_CharT, _Intl>(__refs) 1465 { 1466 if (__builtin_strcmp(__s, "C") != 0 1467 && __builtin_strcmp(__s, "POSIX") != 0) 1468 { 1469 __c_locale __tmp; 1470 this->_S_create_c_locale(__tmp, __s); 1471 this->_M_initialize_moneypunct(__tmp); 1472 this->_S_destroy_c_locale(__tmp); 1473 } 1474 } 1475 1476 #if __cplusplus >= 201103L 1477 explicit 1478 moneypunct_byname(const string& __s, size_t __refs = 0) 1479 : moneypunct_byname(__s.c_str(), __refs) { } 1480 #endif 1481 1482 protected: 1483 virtual 1484 ~moneypunct_byname() { } 1485 }; 1486 1487 template<typename _CharT, bool _Intl> 1488 const bool moneypunct_byname<_CharT, _Intl>::intl; 1489 1490 _GLIBCXX_END_NAMESPACE_CXX11 1491 1492 _GLIBCXX_BEGIN_NAMESPACE_LDBL_OR_CXX11 1493 1494 /** 1495 * @brief Primary class template money_get. 1496 * @ingroup locales 1497 * 1498 * This facet encapsulates the code to parse and return a monetary 1499 * amount from a string. 1500 * 1501 * The money_get template uses protected virtual functions to 1502 * provide the actual results. The public accessors forward the 1503 * call to the virtual functions. These virtual functions are 1504 * hooks for developers to implement the behavior they require from 1505 * the money_get facet. 1506 */ 1507 template<typename _CharT, typename _InIter> 1508 class money_get : public locale::facet 1509 { 1510 public: 1511 // Types: 1512 ///@{ 1513 /// Public typedefs 1514 typedef _CharT char_type; 1515 typedef _InIter iter_type; 1516 typedef basic_string<_CharT> string_type; 1517 ///@} 1518 1519 /// Numpunct facet id. 1520 static locale::id id; 1521 1522 /** 1523 * @brief Constructor performs initialization. 1524 * 1525 * This is the constructor provided by the standard. 1526 * 1527 * @param __refs Passed to the base facet class. 1528 */ 1529 explicit 1530 money_get(size_t __refs = 0) : facet(__refs) { } 1531 1532 /** 1533 * @brief Read and parse a monetary value. 1534 * 1535 * This function reads characters from @a __s, interprets them as a 1536 * monetary value according to moneypunct and ctype facets retrieved 1537 * from io.getloc(), and returns the result in @a units as an integral 1538 * value moneypunct::frac_digits() * the actual amount. For example, 1539 * the string $10.01 in a US locale would store 1001 in @a units. 1540 * 1541 * Any characters not part of a valid money amount are not consumed. 1542 * 1543 * If a money value cannot be parsed from the input stream, sets 1544 * err=(err|io.failbit). If the stream is consumed before finishing 1545 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is 1546 * unchanged if parsing fails. 1547 * 1548 * This function works by returning the result of do_get(). 1549 * 1550 * @param __s Start of characters to parse. 1551 * @param __end End of characters to parse. 1552 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 1553 * @param __io Source of facets and io state. 1554 * @param __err Error field to set if parsing fails. 1555 * @param __units Place to store result of parsing. 1556 * @return Iterator referencing first character beyond valid money 1557 * amount. 1558 */ 1559 iter_type 1560 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 1561 ios_base::iostate& __err, long double& __units) const 1562 { return this->do_get(__s, __end, __intl, __io, __err, __units); } 1563 1564 /** 1565 * @brief Read and parse a monetary value. 1566 * 1567 * This function reads characters from @a __s, interprets them as 1568 * a monetary value according to moneypunct and ctype facets 1569 * retrieved from io.getloc(), and returns the result in @a 1570 * digits. For example, the string $10.01 in a US locale would 1571 * store <code>1001</code> in @a digits. 1572 * 1573 * Any characters not part of a valid money amount are not consumed. 1574 * 1575 * If a money value cannot be parsed from the input stream, sets 1576 * err=(err|io.failbit). If the stream is consumed before finishing 1577 * parsing, sets err=(err|io.failbit|io.eofbit). 1578 * 1579 * This function works by returning the result of do_get(). 1580 * 1581 * @param __s Start of characters to parse. 1582 * @param __end End of characters to parse. 1583 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 1584 * @param __io Source of facets and io state. 1585 * @param __err Error field to set if parsing fails. 1586 * @param __digits Place to store result of parsing. 1587 * @return Iterator referencing first character beyond valid money 1588 * amount. 1589 */ 1590 iter_type 1591 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 1592 ios_base::iostate& __err, string_type& __digits) const 1593 { return this->do_get(__s, __end, __intl, __io, __err, __digits); } 1594 1595 protected: 1596 /// Destructor. 1597 virtual 1598 ~money_get() { } 1599 1600 /** 1601 * @brief Read and parse a monetary value. 1602 * 1603 * This function reads and parses characters representing a monetary 1604 * value. This function is a hook for derived classes to change the 1605 * value returned. @see get() for details. 1606 */ 1607 // XXX GLIBCXX_ABI Deprecated 1608 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ 1609 && (_GLIBCXX_USE_CXX11_ABI == 0 || defined __LONG_DOUBLE_IEEE128__) 1610 virtual iter_type 1611 __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 1612 ios_base::iostate& __err, double& __units) const; 1613 #else 1614 virtual iter_type 1615 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 1616 ios_base::iostate& __err, long double& __units) const; 1617 #endif 1618 1619 /** 1620 * @brief Read and parse a monetary value. 1621 * 1622 * This function reads and parses characters representing a monetary 1623 * value. This function is a hook for derived classes to change the 1624 * value returned. @see get() for details. 1625 */ 1626 virtual iter_type 1627 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 1628 ios_base::iostate& __err, string_type& __digits) const; 1629 1630 // XXX GLIBCXX_ABI Deprecated 1631 #if defined _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT \ 1632 && defined __LONG_DOUBLE_IEEE128__ 1633 virtual iter_type 1634 __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 1635 ios_base::iostate& __err, __ibm128& __units) const; 1636 #endif 1637 1638 // XXX GLIBCXX_ABI Deprecated 1639 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ 1640 && (_GLIBCXX_USE_CXX11_ABI == 0 || defined __LONG_DOUBLE_IEEE128__) 1641 virtual iter_type 1642 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 1643 ios_base::iostate& __err, long double& __units) const; 1644 #endif 1645 1646 template<bool _Intl> 1647 iter_type 1648 _M_extract(iter_type __s, iter_type __end, ios_base& __io, 1649 ios_base::iostate& __err, string& __digits) const; 1650 }; 1651 1652 template<typename _CharT, typename _InIter> 1653 locale::id money_get<_CharT, _InIter>::id; 1654 1655 /** 1656 * @brief Primary class template money_put. 1657 * @ingroup locales 1658 * 1659 * This facet encapsulates the code to format and output a monetary 1660 * amount. 1661 * 1662 * The money_put template uses protected virtual functions to 1663 * provide the actual results. The public accessors forward the 1664 * call to the virtual functions. These virtual functions are 1665 * hooks for developers to implement the behavior they require from 1666 * the money_put facet. 1667 */ 1668 template<typename _CharT, typename _OutIter> 1669 class money_put : public locale::facet 1670 { 1671 public: 1672 ///@{ 1673 /// Public typedefs 1674 typedef _CharT char_type; 1675 typedef _OutIter iter_type; 1676 typedef basic_string<_CharT> string_type; 1677 ///@} 1678 1679 /// Numpunct facet id. 1680 static locale::id id; 1681 1682 /** 1683 * @brief Constructor performs initialization. 1684 * 1685 * This is the constructor provided by the standard. 1686 * 1687 * @param __refs Passed to the base facet class. 1688 */ 1689 explicit 1690 money_put(size_t __refs = 0) : facet(__refs) { } 1691 1692 /** 1693 * @brief Format and output a monetary value. 1694 * 1695 * This function formats @a units as a monetary value according to 1696 * moneypunct and ctype facets retrieved from io.getloc(), and writes 1697 * the resulting characters to @a __s. For example, the value 1001 in a 1698 * US locale would write <code>$10.01</code> to @a __s. 1699 * 1700 * This function works by returning the result of do_put(). 1701 * 1702 * @param __s The stream to write to. 1703 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 1704 * @param __io Source of facets and io state. 1705 * @param __fill char_type to use for padding. 1706 * @param __units Place to store result of parsing. 1707 * @return Iterator after writing. 1708 */ 1709 iter_type 1710 put(iter_type __s, bool __intl, ios_base& __io, 1711 char_type __fill, long double __units) const 1712 { return this->do_put(__s, __intl, __io, __fill, __units); } 1713 1714 /** 1715 * @brief Format and output a monetary value. 1716 * 1717 * This function formats @a digits as a monetary value 1718 * according to moneypunct and ctype facets retrieved from 1719 * io.getloc(), and writes the resulting characters to @a __s. 1720 * For example, the string <code>1001</code> in a US locale 1721 * would write <code>$10.01</code> to @a __s. 1722 * 1723 * This function works by returning the result of do_put(). 1724 * 1725 * @param __s The stream to write to. 1726 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 1727 * @param __io Source of facets and io state. 1728 * @param __fill char_type to use for padding. 1729 * @param __digits Place to store result of parsing. 1730 * @return Iterator after writing. 1731 */ 1732 iter_type 1733 put(iter_type __s, bool __intl, ios_base& __io, 1734 char_type __fill, const string_type& __digits) const 1735 { return this->do_put(__s, __intl, __io, __fill, __digits); } 1736 1737 protected: 1738 /// Destructor. 1739 virtual 1740 ~money_put() { } 1741 1742 /** 1743 * @brief Format and output a monetary value. 1744 * 1745 * This function formats @a units as a monetary value according to 1746 * moneypunct and ctype facets retrieved from io.getloc(), and writes 1747 * the resulting characters to @a __s. For example, the value 1001 in a 1748 * US locale would write <code>$10.01</code> to @a __s. 1749 * 1750 * This function is a hook for derived classes to change the value 1751 * returned. @see put(). 1752 * 1753 * @param __s The stream to write to. 1754 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 1755 * @param __io Source of facets and io state. 1756 * @param __fill char_type to use for padding. 1757 * @param __units Place to store result of parsing. 1758 * @return Iterator after writing. 1759 */ 1760 // XXX GLIBCXX_ABI Deprecated 1761 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ 1762 && (_GLIBCXX_USE_CXX11_ABI == 0 || defined __LONG_DOUBLE_IEEE128__) 1763 virtual iter_type 1764 __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 1765 double __units) const; 1766 #else 1767 virtual iter_type 1768 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 1769 long double __units) const; 1770 #endif 1771 1772 /** 1773 * @brief Format and output a monetary value. 1774 * 1775 * This function formats @a digits as a monetary value 1776 * according to moneypunct and ctype facets retrieved from 1777 * io.getloc(), and writes the resulting characters to @a __s. 1778 * For example, the string <code>1001</code> in a US locale 1779 * would write <code>$10.01</code> to @a __s. 1780 * 1781 * This function is a hook for derived classes to change the value 1782 * returned. @see put(). 1783 * 1784 * @param __s The stream to write to. 1785 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 1786 * @param __io Source of facets and io state. 1787 * @param __fill char_type to use for padding. 1788 * @param __digits Place to store result of parsing. 1789 * @return Iterator after writing. 1790 */ 1791 virtual iter_type 1792 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 1793 const string_type& __digits) const; 1794 1795 // XXX GLIBCXX_ABI Deprecated 1796 #if defined _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT \ 1797 && defined __LONG_DOUBLE_IEEE128__ 1798 virtual iter_type 1799 __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 1800 __ibm128 __units) const; 1801 #endif 1802 1803 // XXX GLIBCXX_ABI Deprecated 1804 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ 1805 && (_GLIBCXX_USE_CXX11_ABI == 0 || defined __LONG_DOUBLE_IEEE128__) 1806 virtual iter_type 1807 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 1808 long double __units) const; 1809 #endif 1810 1811 template<bool _Intl> 1812 iter_type 1813 _M_insert(iter_type __s, ios_base& __io, char_type __fill, 1814 const string_type& __digits) const; 1815 }; 1816 1817 template<typename _CharT, typename _OutIter> 1818 locale::id money_put<_CharT, _OutIter>::id; 1819 1820 _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11 1821 1822 /** 1823 * @brief Messages facet base class providing catalog typedef. 1824 * @ingroup locales 1825 */ 1826 struct messages_base 1827 { 1828 typedef int catalog; 1829 }; 1830 1831 _GLIBCXX_BEGIN_NAMESPACE_CXX11 1832 1833 /** 1834 * @brief Primary class template messages. 1835 * @ingroup locales 1836 * 1837 * This facet encapsulates the code to retrieve messages from 1838 * message catalogs. The only thing defined by the standard for this facet 1839 * is the interface. All underlying functionality is 1840 * implementation-defined. 1841 * 1842 * This library currently implements 3 versions of the message facet. The 1843 * first version (gnu) is a wrapper around gettext, provided by libintl. 1844 * The second version (ieee) is a wrapper around catgets. The final 1845 * version (default) does no actual translation. These implementations are 1846 * only provided for char and wchar_t instantiations. 1847 * 1848 * The messages template uses protected virtual functions to 1849 * provide the actual results. The public accessors forward the 1850 * call to the virtual functions. These virtual functions are 1851 * hooks for developers to implement the behavior they require from 1852 * the messages facet. 1853 */ 1854 template<typename _CharT> 1855 class messages : public locale::facet, public messages_base 1856 { 1857 public: 1858 // Types: 1859 ///@{ 1860 /// Public typedefs 1861 typedef _CharT char_type; 1862 typedef basic_string<_CharT> string_type; 1863 ///@} 1864 1865 protected: 1866 // Underlying "C" library locale information saved from 1867 // initialization, needed by messages_byname as well. 1868 __c_locale _M_c_locale_messages; 1869 const char* _M_name_messages; 1870 1871 public: 1872 /// Numpunct facet id. 1873 static locale::id id; 1874 1875 /** 1876 * @brief Constructor performs initialization. 1877 * 1878 * This is the constructor provided by the standard. 1879 * 1880 * @param __refs Passed to the base facet class. 1881 */ 1882 explicit 1883 messages(size_t __refs = 0); 1884 1885 // Non-standard. 1886 /** 1887 * @brief Internal constructor. Not for general use. 1888 * 1889 * This is a constructor for use by the library itself to set up new 1890 * locales. 1891 * 1892 * @param __cloc The C locale. 1893 * @param __s The name of a locale. 1894 * @param __refs Refcount to pass to the base class. 1895 */ 1896 explicit 1897 messages(__c_locale __cloc, const char* __s, size_t __refs = 0); 1898 1899 /* 1900 * @brief Open a message catalog. 1901 * 1902 * This function opens and returns a handle to a message catalog by 1903 * returning do_open(__s, __loc). 1904 * 1905 * @param __s The catalog to open. 1906 * @param __loc Locale to use for character set conversions. 1907 * @return Handle to the catalog or value < 0 if open fails. 1908 */ 1909 catalog 1910 open(const basic_string<char>& __s, const locale& __loc) const 1911 { return this->do_open(__s, __loc); } 1912 1913 // Non-standard and unorthodox, yet effective. 1914 /* 1915 * @brief Open a message catalog. 1916 * 1917 * This non-standard function opens and returns a handle to a message 1918 * catalog by returning do_open(s, loc). The third argument provides a 1919 * message catalog root directory for gnu gettext and is ignored 1920 * otherwise. 1921 * 1922 * @param __s The catalog to open. 1923 * @param __loc Locale to use for character set conversions. 1924 * @param __dir Message catalog root directory. 1925 * @return Handle to the catalog or value < 0 if open fails. 1926 */ 1927 catalog 1928 open(const basic_string<char>&, const locale&, const char*) const; 1929 1930 /* 1931 * @brief Look up a string in a message catalog. 1932 * 1933 * This function retrieves and returns a message from a catalog by 1934 * returning do_get(c, set, msgid, s). 1935 * 1936 * For gnu, @a __set and @a msgid are ignored. Returns gettext(s). 1937 * For default, returns s. For ieee, returns catgets(c,set,msgid,s). 1938 * 1939 * @param __c The catalog to access. 1940 * @param __set Implementation-defined. 1941 * @param __msgid Implementation-defined. 1942 * @param __s Default return value if retrieval fails. 1943 * @return Retrieved message or @a __s if get fails. 1944 */ 1945 string_type 1946 get(catalog __c, int __set, int __msgid, const string_type& __s) const 1947 { return this->do_get(__c, __set, __msgid, __s); } 1948 1949 /* 1950 * @brief Close a message catalog. 1951 * 1952 * Closes catalog @a c by calling do_close(c). 1953 * 1954 * @param __c The catalog to close. 1955 */ 1956 void 1957 close(catalog __c) const 1958 { return this->do_close(__c); } 1959 1960 protected: 1961 /// Destructor. 1962 virtual 1963 ~messages(); 1964 1965 /* 1966 * @brief Open a message catalog. 1967 * 1968 * This function opens and returns a handle to a message catalog in an 1969 * implementation-defined manner. This function is a hook for derived 1970 * classes to change the value returned. 1971 * 1972 * @param __s The catalog to open. 1973 * @param __loc Locale to use for character set conversions. 1974 * @return Handle to the opened catalog, value < 0 if open failed. 1975 */ 1976 virtual catalog 1977 do_open(const basic_string<char>&, const locale&) const; 1978 1979 /* 1980 * @brief Look up a string in a message catalog. 1981 * 1982 * This function retrieves and returns a message from a catalog in an 1983 * implementation-defined manner. This function is a hook for derived 1984 * classes to change the value returned. 1985 * 1986 * For gnu, @a __set and @a __msgid are ignored. Returns gettext(s). 1987 * For default, returns s. For ieee, returns catgets(c,set,msgid,s). 1988 * 1989 * @param __c The catalog to access. 1990 * @param __set Implementation-defined. 1991 * @param __msgid Implementation-defined. 1992 * @param __s Default return value if retrieval fails. 1993 * @return Retrieved message or @a __s if get fails. 1994 */ 1995 virtual string_type 1996 do_get(catalog, int, int, const string_type& __dfault) const; 1997 1998 /* 1999 * @brief Close a message catalog. 2000 * 2001 * @param __c The catalog to close. 2002 */ 2003 virtual void 2004 do_close(catalog) const; 2005 2006 // Returns a locale and codeset-converted string, given a char* message. 2007 char* 2008 _M_convert_to_char(const string_type& __msg) const 2009 { 2010 // XXX 2011 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str())); 2012 } 2013 2014 // Returns a locale and codeset-converted string, given a char* message. 2015 string_type 2016 _M_convert_from_char(char*) const 2017 { 2018 // XXX 2019 return string_type(); 2020 } 2021 }; 2022 2023 template<typename _CharT> 2024 locale::id messages<_CharT>::id; 2025 2026 /// Specializations for required instantiations. 2027 template<> 2028 string 2029 messages<char>::do_get(catalog, int, int, const string&) const; 2030 2031 #ifdef _GLIBCXX_USE_WCHAR_T 2032 template<> 2033 wstring 2034 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const; 2035 #endif 2036 2037 /// class messages_byname [22.2.7.2]. 2038 template<typename _CharT> 2039 class messages_byname : public messages<_CharT> 2040 { 2041 public: 2042 typedef _CharT char_type; 2043 typedef basic_string<_CharT> string_type; 2044 2045 explicit 2046 messages_byname(const char* __s, size_t __refs = 0); 2047 2048 #if __cplusplus >= 201103L 2049 explicit 2050 messages_byname(const string& __s, size_t __refs = 0) 2051 : messages_byname(__s.c_str(), __refs) { } 2052 #endif 2053 2054 protected: 2055 virtual 2056 ~messages_byname() 2057 { } 2058 }; 2059 2060 _GLIBCXX_END_NAMESPACE_CXX11 2061 2062 _GLIBCXX_END_NAMESPACE_VERSION 2063 } // namespace 2064 2065 // Include host and configuration specific messages functions. 2066 #include <bits/messages_members.h> 2067 2068 // 22.2.1.5 Template class codecvt 2069 #include <bits/codecvt.h> 2070 2071 #include <bits/locale_facets_nonio.tcc> 2072 2073 #endif