libstdc++
|
00001 // Locale support -*- C++ -*- 00002 00003 // Copyright (C) 2007-2018 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file bits/locale_facets_nonio.h 00026 * This is an internal header file, included by other library headers. 00027 * Do not attempt to use it directly. @headername{locale} 00028 */ 00029 00030 // 00031 // ISO C++ 14882: 22.1 Locales 00032 // 00033 00034 #ifndef _LOCALE_FACETS_NONIO_H 00035 #define _LOCALE_FACETS_NONIO_H 1 00036 00037 #pragma GCC system_header 00038 00039 #include <ctime> // For struct tm 00040 00041 namespace std _GLIBCXX_VISIBILITY(default) 00042 { 00043 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00044 00045 /** 00046 * @brief Time format ordering data. 00047 * @ingroup locales 00048 * 00049 * This class provides an enum representing different orderings of 00050 * time: day, month, and year. 00051 */ 00052 class time_base 00053 { 00054 public: 00055 enum dateorder { no_order, dmy, mdy, ymd, ydm }; 00056 }; 00057 00058 template<typename _CharT> 00059 struct __timepunct_cache : public locale::facet 00060 { 00061 // List of all known timezones, with GMT first. 00062 static const _CharT* _S_timezones[14]; 00063 00064 const _CharT* _M_date_format; 00065 const _CharT* _M_date_era_format; 00066 const _CharT* _M_time_format; 00067 const _CharT* _M_time_era_format; 00068 const _CharT* _M_date_time_format; 00069 const _CharT* _M_date_time_era_format; 00070 const _CharT* _M_am; 00071 const _CharT* _M_pm; 00072 const _CharT* _M_am_pm_format; 00073 00074 // Day names, starting with "C"'s Sunday. 00075 const _CharT* _M_day1; 00076 const _CharT* _M_day2; 00077 const _CharT* _M_day3; 00078 const _CharT* _M_day4; 00079 const _CharT* _M_day5; 00080 const _CharT* _M_day6; 00081 const _CharT* _M_day7; 00082 00083 // Abbreviated day names, starting with "C"'s Sun. 00084 const _CharT* _M_aday1; 00085 const _CharT* _M_aday2; 00086 const _CharT* _M_aday3; 00087 const _CharT* _M_aday4; 00088 const _CharT* _M_aday5; 00089 const _CharT* _M_aday6; 00090 const _CharT* _M_aday7; 00091 00092 // Month names, starting with "C"'s January. 00093 const _CharT* _M_month01; 00094 const _CharT* _M_month02; 00095 const _CharT* _M_month03; 00096 const _CharT* _M_month04; 00097 const _CharT* _M_month05; 00098 const _CharT* _M_month06; 00099 const _CharT* _M_month07; 00100 const _CharT* _M_month08; 00101 const _CharT* _M_month09; 00102 const _CharT* _M_month10; 00103 const _CharT* _M_month11; 00104 const _CharT* _M_month12; 00105 00106 // Abbreviated month names, starting with "C"'s Jan. 00107 const _CharT* _M_amonth01; 00108 const _CharT* _M_amonth02; 00109 const _CharT* _M_amonth03; 00110 const _CharT* _M_amonth04; 00111 const _CharT* _M_amonth05; 00112 const _CharT* _M_amonth06; 00113 const _CharT* _M_amonth07; 00114 const _CharT* _M_amonth08; 00115 const _CharT* _M_amonth09; 00116 const _CharT* _M_amonth10; 00117 const _CharT* _M_amonth11; 00118 const _CharT* _M_amonth12; 00119 00120 bool _M_allocated; 00121 00122 __timepunct_cache(size_t __refs = 0) : facet(__refs), 00123 _M_date_format(0), _M_date_era_format(0), _M_time_format(0), 00124 _M_time_era_format(0), _M_date_time_format(0), 00125 _M_date_time_era_format(0), _M_am(0), _M_pm(0), 00126 _M_am_pm_format(0), _M_day1(0), _M_day2(0), _M_day3(0), 00127 _M_day4(0), _M_day5(0), _M_day6(0), _M_day7(0), 00128 _M_aday1(0), _M_aday2(0), _M_aday3(0), _M_aday4(0), 00129 _M_aday5(0), _M_aday6(0), _M_aday7(0), _M_month01(0), 00130 _M_month02(0), _M_month03(0), _M_month04(0), _M_month05(0), 00131 _M_month06(0), _M_month07(0), _M_month08(0), _M_month09(0), 00132 _M_month10(0), _M_month11(0), _M_month12(0), _M_amonth01(0), 00133 _M_amonth02(0), _M_amonth03(0), _M_amonth04(0), 00134 _M_amonth05(0), _M_amonth06(0), _M_amonth07(0), 00135 _M_amonth08(0), _M_amonth09(0), _M_amonth10(0), 00136 _M_amonth11(0), _M_amonth12(0), _M_allocated(false) 00137 { } 00138 00139 ~__timepunct_cache(); 00140 00141 private: 00142 __timepunct_cache& 00143 operator=(const __timepunct_cache&); 00144 00145 explicit 00146 __timepunct_cache(const __timepunct_cache&); 00147 }; 00148 00149 template<typename _CharT> 00150 __timepunct_cache<_CharT>::~__timepunct_cache() 00151 { 00152 if (_M_allocated) 00153 { 00154 // Unused. 00155 } 00156 } 00157 00158 // Specializations. 00159 template<> 00160 const char* 00161 __timepunct_cache<char>::_S_timezones[14]; 00162 00163 #ifdef _GLIBCXX_USE_WCHAR_T 00164 template<> 00165 const wchar_t* 00166 __timepunct_cache<wchar_t>::_S_timezones[14]; 00167 #endif 00168 00169 // Generic. 00170 template<typename _CharT> 00171 const _CharT* __timepunct_cache<_CharT>::_S_timezones[14]; 00172 00173 template<typename _CharT> 00174 class __timepunct : public locale::facet 00175 { 00176 public: 00177 // Types: 00178 typedef _CharT __char_type; 00179 typedef __timepunct_cache<_CharT> __cache_type; 00180 00181 protected: 00182 __cache_type* _M_data; 00183 __c_locale _M_c_locale_timepunct; 00184 const char* _M_name_timepunct; 00185 00186 public: 00187 /// Numpunct facet id. 00188 static locale::id id; 00189 00190 explicit 00191 __timepunct(size_t __refs = 0); 00192 00193 explicit 00194 __timepunct(__cache_type* __cache, size_t __refs = 0); 00195 00196 /** 00197 * @brief Internal constructor. Not for general use. 00198 * 00199 * This is a constructor for use by the library itself to set up new 00200 * locales. 00201 * 00202 * @param __cloc The C locale. 00203 * @param __s The name of a locale. 00204 * @param refs Passed to the base facet class. 00205 */ 00206 explicit 00207 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0); 00208 00209 // FIXME: for error checking purposes _M_put should return the return 00210 // value of strftime/wcsftime. 00211 void 00212 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format, 00213 const tm* __tm) const throw (); 00214 00215 void 00216 _M_date_formats(const _CharT** __date) const 00217 { 00218 // Always have default first. 00219 __date[0] = _M_data->_M_date_format; 00220 __date[1] = _M_data->_M_date_era_format; 00221 } 00222 00223 void 00224 _M_time_formats(const _CharT** __time) const 00225 { 00226 // Always have default first. 00227 __time[0] = _M_data->_M_time_format; 00228 __time[1] = _M_data->_M_time_era_format; 00229 } 00230 00231 void 00232 _M_date_time_formats(const _CharT** __dt) const 00233 { 00234 // Always have default first. 00235 __dt[0] = _M_data->_M_date_time_format; 00236 __dt[1] = _M_data->_M_date_time_era_format; 00237 } 00238 00239 #if !_GLIBCXX_INLINE_VERSION 00240 void 00241 _M_am_pm_format(const _CharT*) const 00242 { /* Kept for ABI compatibility, see PR65927 */ } 00243 #endif 00244 00245 void 00246 _M_am_pm(const _CharT** __ampm) const 00247 { 00248 __ampm[0] = _M_data->_M_am; 00249 __ampm[1] = _M_data->_M_pm; 00250 } 00251 00252 void 00253 _M_days(const _CharT** __days) const 00254 { 00255 __days[0] = _M_data->_M_day1; 00256 __days[1] = _M_data->_M_day2; 00257 __days[2] = _M_data->_M_day3; 00258 __days[3] = _M_data->_M_day4; 00259 __days[4] = _M_data->_M_day5; 00260 __days[5] = _M_data->_M_day6; 00261 __days[6] = _M_data->_M_day7; 00262 } 00263 00264 void 00265 _M_days_abbreviated(const _CharT** __days) const 00266 { 00267 __days[0] = _M_data->_M_aday1; 00268 __days[1] = _M_data->_M_aday2; 00269 __days[2] = _M_data->_M_aday3; 00270 __days[3] = _M_data->_M_aday4; 00271 __days[4] = _M_data->_M_aday5; 00272 __days[5] = _M_data->_M_aday6; 00273 __days[6] = _M_data->_M_aday7; 00274 } 00275 00276 void 00277 _M_months(const _CharT** __months) const 00278 { 00279 __months[0] = _M_data->_M_month01; 00280 __months[1] = _M_data->_M_month02; 00281 __months[2] = _M_data->_M_month03; 00282 __months[3] = _M_data->_M_month04; 00283 __months[4] = _M_data->_M_month05; 00284 __months[5] = _M_data->_M_month06; 00285 __months[6] = _M_data->_M_month07; 00286 __months[7] = _M_data->_M_month08; 00287 __months[8] = _M_data->_M_month09; 00288 __months[9] = _M_data->_M_month10; 00289 __months[10] = _M_data->_M_month11; 00290 __months[11] = _M_data->_M_month12; 00291 } 00292 00293 void 00294 _M_months_abbreviated(const _CharT** __months) const 00295 { 00296 __months[0] = _M_data->_M_amonth01; 00297 __months[1] = _M_data->_M_amonth02; 00298 __months[2] = _M_data->_M_amonth03; 00299 __months[3] = _M_data->_M_amonth04; 00300 __months[4] = _M_data->_M_amonth05; 00301 __months[5] = _M_data->_M_amonth06; 00302 __months[6] = _M_data->_M_amonth07; 00303 __months[7] = _M_data->_M_amonth08; 00304 __months[8] = _M_data->_M_amonth09; 00305 __months[9] = _M_data->_M_amonth10; 00306 __months[10] = _M_data->_M_amonth11; 00307 __months[11] = _M_data->_M_amonth12; 00308 } 00309 00310 protected: 00311 virtual 00312 ~__timepunct(); 00313 00314 // For use at construction time only. 00315 void 00316 _M_initialize_timepunct(__c_locale __cloc = 0); 00317 }; 00318 00319 template<typename _CharT> 00320 locale::id __timepunct<_CharT>::id; 00321 00322 // Specializations. 00323 template<> 00324 void 00325 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc); 00326 00327 template<> 00328 void 00329 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const throw (); 00330 00331 #ifdef _GLIBCXX_USE_WCHAR_T 00332 template<> 00333 void 00334 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc); 00335 00336 template<> 00337 void 00338 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*, 00339 const tm*) const throw (); 00340 #endif 00341 00342 _GLIBCXX_END_NAMESPACE_VERSION 00343 } // namespace 00344 00345 // Include host and configuration specific timepunct functions. 00346 #include <bits/time_members.h> 00347 00348 namespace std _GLIBCXX_VISIBILITY(default) 00349 { 00350 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00351 00352 _GLIBCXX_BEGIN_NAMESPACE_CXX11 00353 00354 /** 00355 * @brief Primary class template time_get. 00356 * @ingroup locales 00357 * 00358 * This facet encapsulates the code to parse and return a date or 00359 * time from a string. It is used by the istream numeric 00360 * extraction operators. 00361 * 00362 * The time_get template uses protected virtual functions to provide the 00363 * actual results. The public accessors forward the call to the virtual 00364 * functions. These virtual functions are hooks for developers to 00365 * implement the behavior they require from the time_get facet. 00366 */ 00367 template<typename _CharT, typename _InIter> 00368 class time_get : public locale::facet, public time_base 00369 { 00370 public: 00371 // Types: 00372 //@{ 00373 /// Public typedefs 00374 typedef _CharT char_type; 00375 typedef _InIter iter_type; 00376 //@} 00377 00378 /// Numpunct facet id. 00379 static locale::id id; 00380 00381 /** 00382 * @brief Constructor performs initialization. 00383 * 00384 * This is the constructor provided by the standard. 00385 * 00386 * @param __refs Passed to the base facet class. 00387 */ 00388 explicit 00389 time_get(size_t __refs = 0) 00390 : facet (__refs) { } 00391 00392 /** 00393 * @brief Return preferred order of month, day, and year. 00394 * 00395 * This function returns an enum from time_base::dateorder giving the 00396 * preferred ordering if the format @a x given to time_put::put() only 00397 * uses month, day, and year. If the format @a x for the associated 00398 * locale uses other fields, this function returns 00399 * time_base::dateorder::noorder. 00400 * 00401 * NOTE: The library always returns noorder at the moment. 00402 * 00403 * @return A member of time_base::dateorder. 00404 */ 00405 dateorder 00406 date_order() const 00407 { return this->do_date_order(); } 00408 00409 /** 00410 * @brief Parse input time string. 00411 * 00412 * This function parses a time according to the format @a X and puts the 00413 * results into a user-supplied struct tm. The result is returned by 00414 * calling time_get::do_get_time(). 00415 * 00416 * If there is a valid time string according to format @a X, @a tm will 00417 * be filled in accordingly and the returned iterator will point to the 00418 * first character beyond the time string. If an error occurs before 00419 * the end, err |= ios_base::failbit. If parsing reads all the 00420 * characters, err |= ios_base::eofbit. 00421 * 00422 * @param __beg Start of string to parse. 00423 * @param __end End of string to parse. 00424 * @param __io Source of the locale. 00425 * @param __err Error flags to set. 00426 * @param __tm Pointer to struct tm to fill in. 00427 * @return Iterator to first char beyond time string. 00428 */ 00429 iter_type 00430 get_time(iter_type __beg, iter_type __end, ios_base& __io, 00431 ios_base::iostate& __err, tm* __tm) const 00432 { return this->do_get_time(__beg, __end, __io, __err, __tm); } 00433 00434 /** 00435 * @brief Parse input date string. 00436 * 00437 * This function parses a date according to the format @a x and puts the 00438 * results into a user-supplied struct tm. The result is returned by 00439 * calling time_get::do_get_date(). 00440 * 00441 * If there is a valid date string according to format @a x, @a tm will 00442 * be filled in accordingly and the returned iterator will point to the 00443 * first character beyond the date string. If an error occurs before 00444 * the end, err |= ios_base::failbit. If parsing reads all the 00445 * characters, err |= ios_base::eofbit. 00446 * 00447 * @param __beg Start of string to parse. 00448 * @param __end End of string to parse. 00449 * @param __io Source of the locale. 00450 * @param __err Error flags to set. 00451 * @param __tm Pointer to struct tm to fill in. 00452 * @return Iterator to first char beyond date string. 00453 */ 00454 iter_type 00455 get_date(iter_type __beg, iter_type __end, ios_base& __io, 00456 ios_base::iostate& __err, tm* __tm) const 00457 { return this->do_get_date(__beg, __end, __io, __err, __tm); } 00458 00459 /** 00460 * @brief Parse input weekday string. 00461 * 00462 * This function parses a weekday name and puts the results into a 00463 * user-supplied struct tm. The result is returned by calling 00464 * time_get::do_get_weekday(). 00465 * 00466 * Parsing starts by parsing an abbreviated weekday name. If a valid 00467 * abbreviation is followed by a character that would lead to the full 00468 * weekday name, parsing continues until the full name is found or an 00469 * error occurs. Otherwise parsing finishes at the end of the 00470 * abbreviated name. 00471 * 00472 * If an error occurs before the end, err |= ios_base::failbit. If 00473 * parsing reads all the characters, err |= ios_base::eofbit. 00474 * 00475 * @param __beg Start of string to parse. 00476 * @param __end End of string to parse. 00477 * @param __io Source of the locale. 00478 * @param __err Error flags to set. 00479 * @param __tm Pointer to struct tm to fill in. 00480 * @return Iterator to first char beyond weekday name. 00481 */ 00482 iter_type 00483 get_weekday(iter_type __beg, iter_type __end, ios_base& __io, 00484 ios_base::iostate& __err, tm* __tm) const 00485 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); } 00486 00487 /** 00488 * @brief Parse input month string. 00489 * 00490 * This function parses a month name and puts the results into a 00491 * user-supplied struct tm. The result is returned by calling 00492 * time_get::do_get_monthname(). 00493 * 00494 * Parsing starts by parsing an abbreviated month name. If a valid 00495 * abbreviation is followed by a character that would lead to the full 00496 * month name, parsing continues until the full name is found or an 00497 * error occurs. Otherwise parsing finishes at the end of the 00498 * abbreviated name. 00499 * 00500 * If an error occurs before the end, err |= ios_base::failbit. If 00501 * parsing reads all the characters, err |= 00502 * ios_base::eofbit. 00503 * 00504 * @param __beg Start of string to parse. 00505 * @param __end End of string to parse. 00506 * @param __io Source of the locale. 00507 * @param __err Error flags to set. 00508 * @param __tm Pointer to struct tm to fill in. 00509 * @return Iterator to first char beyond month name. 00510 */ 00511 iter_type 00512 get_monthname(iter_type __beg, iter_type __end, ios_base& __io, 00513 ios_base::iostate& __err, tm* __tm) const 00514 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); } 00515 00516 /** 00517 * @brief Parse input year string. 00518 * 00519 * This function reads up to 4 characters to parse a year string and 00520 * puts the results into a user-supplied struct tm. The result is 00521 * returned by calling time_get::do_get_year(). 00522 * 00523 * 4 consecutive digits are interpreted as a full year. If there are 00524 * exactly 2 consecutive digits, the library interprets this as the 00525 * number of years since 1900. 00526 * 00527 * If an error occurs before the end, err |= ios_base::failbit. If 00528 * parsing reads all the characters, err |= ios_base::eofbit. 00529 * 00530 * @param __beg Start of string to parse. 00531 * @param __end End of string to parse. 00532 * @param __io Source of the locale. 00533 * @param __err Error flags to set. 00534 * @param __tm Pointer to struct tm to fill in. 00535 * @return Iterator to first char beyond year. 00536 */ 00537 iter_type 00538 get_year(iter_type __beg, iter_type __end, ios_base& __io, 00539 ios_base::iostate& __err, tm* __tm) const 00540 { return this->do_get_year(__beg, __end, __io, __err, __tm); } 00541 00542 #if __cplusplus >= 201103L 00543 /** 00544 * @brief Parse input string according to format. 00545 * 00546 * This function calls time_get::do_get with the provided 00547 * parameters. @see do_get() and get(). 00548 * 00549 * @param __s Start of string to parse. 00550 * @param __end End of string to parse. 00551 * @param __io Source of the locale. 00552 * @param __err Error flags to set. 00553 * @param __tm Pointer to struct tm to fill in. 00554 * @param __format Format specifier. 00555 * @param __modifier Format modifier. 00556 * @return Iterator to first char not parsed. 00557 */ 00558 inline 00559 iter_type get(iter_type __s, iter_type __end, ios_base& __io, 00560 ios_base::iostate& __err, tm* __tm, char __format, 00561 char __modifier = 0) const 00562 { 00563 return this->do_get(__s, __end, __io, __err, __tm, __format, 00564 __modifier); 00565 } 00566 00567 /** 00568 * @brief Parse input string according to format. 00569 * 00570 * This function parses the input string according to a 00571 * provided format string. It does the inverse of 00572 * time_put::put. The format string follows the format 00573 * specified for strftime(3)/strptime(3). The actual parsing 00574 * is done by time_get::do_get. 00575 * 00576 * @param __s Start of string to parse. 00577 * @param __end End of string to parse. 00578 * @param __io Source of the locale. 00579 * @param __err Error flags to set. 00580 * @param __tm Pointer to struct tm to fill in. 00581 * @param __fmt Start of the format string. 00582 * @param __fmtend End of the format string. 00583 * @return Iterator to first char not parsed. 00584 */ 00585 iter_type get(iter_type __s, iter_type __end, ios_base& __io, 00586 ios_base::iostate& __err, tm* __tm, const char_type* __fmt, 00587 const char_type* __fmtend) const; 00588 #endif // __cplusplus >= 201103L 00589 00590 protected: 00591 /// Destructor. 00592 virtual 00593 ~time_get() { } 00594 00595 /** 00596 * @brief Return preferred order of month, day, and year. 00597 * 00598 * This function returns an enum from time_base::dateorder giving the 00599 * preferred ordering if the format @a x given to time_put::put() only 00600 * uses month, day, and year. This function is a hook for derived 00601 * classes to change the value returned. 00602 * 00603 * @return A member of time_base::dateorder. 00604 */ 00605 virtual dateorder 00606 do_date_order() const; 00607 00608 /** 00609 * @brief Parse input time string. 00610 * 00611 * This function parses a time according to the format @a x and puts the 00612 * results into a user-supplied struct tm. This function is a hook for 00613 * derived classes to change the value returned. @see get_time() for 00614 * details. 00615 * 00616 * @param __beg Start of string to parse. 00617 * @param __end End of string to parse. 00618 * @param __io Source of the locale. 00619 * @param __err Error flags to set. 00620 * @param __tm Pointer to struct tm to fill in. 00621 * @return Iterator to first char beyond time string. 00622 */ 00623 virtual iter_type 00624 do_get_time(iter_type __beg, iter_type __end, ios_base& __io, 00625 ios_base::iostate& __err, tm* __tm) const; 00626 00627 /** 00628 * @brief Parse input date string. 00629 * 00630 * This function parses a date according to the format @a X and puts the 00631 * results into a user-supplied struct tm. This function is a hook for 00632 * derived classes to change the value returned. @see get_date() for 00633 * details. 00634 * 00635 * @param __beg Start of string to parse. 00636 * @param __end End of string to parse. 00637 * @param __io Source of the locale. 00638 * @param __err Error flags to set. 00639 * @param __tm Pointer to struct tm to fill in. 00640 * @return Iterator to first char beyond date string. 00641 */ 00642 virtual iter_type 00643 do_get_date(iter_type __beg, iter_type __end, ios_base& __io, 00644 ios_base::iostate& __err, tm* __tm) const; 00645 00646 /** 00647 * @brief Parse input weekday string. 00648 * 00649 * This function parses a weekday name and puts the results into a 00650 * user-supplied struct tm. This function is a hook for derived 00651 * classes to change the value returned. @see get_weekday() for 00652 * details. 00653 * 00654 * @param __beg Start of string to parse. 00655 * @param __end End of string to parse. 00656 * @param __io Source of the locale. 00657 * @param __err Error flags to set. 00658 * @param __tm Pointer to struct tm to fill in. 00659 * @return Iterator to first char beyond weekday name. 00660 */ 00661 virtual iter_type 00662 do_get_weekday(iter_type __beg, iter_type __end, ios_base&, 00663 ios_base::iostate& __err, tm* __tm) const; 00664 00665 /** 00666 * @brief Parse input month string. 00667 * 00668 * This function parses a month name and puts the results into a 00669 * user-supplied struct tm. This function is a hook for derived 00670 * classes to change the value returned. @see get_monthname() for 00671 * details. 00672 * 00673 * @param __beg Start of string to parse. 00674 * @param __end End of string to parse. 00675 * @param __io Source of the locale. 00676 * @param __err Error flags to set. 00677 * @param __tm Pointer to struct tm to fill in. 00678 * @return Iterator to first char beyond month name. 00679 */ 00680 virtual iter_type 00681 do_get_monthname(iter_type __beg, iter_type __end, ios_base&, 00682 ios_base::iostate& __err, tm* __tm) const; 00683 00684 /** 00685 * @brief Parse input year string. 00686 * 00687 * This function reads up to 4 characters to parse a year string and 00688 * puts the results into a user-supplied struct tm. This function is a 00689 * hook for derived classes to change the value returned. @see 00690 * get_year() for details. 00691 * 00692 * @param __beg Start of string to parse. 00693 * @param __end End of string to parse. 00694 * @param __io Source of the locale. 00695 * @param __err Error flags to set. 00696 * @param __tm Pointer to struct tm to fill in. 00697 * @return Iterator to first char beyond year. 00698 */ 00699 virtual iter_type 00700 do_get_year(iter_type __beg, iter_type __end, ios_base& __io, 00701 ios_base::iostate& __err, tm* __tm) const; 00702 00703 #if __cplusplus >= 201103L 00704 /** 00705 * @brief Parse input string according to format. 00706 * 00707 * This function parses the string according to the provided 00708 * format and optional modifier. This function is a hook for 00709 * derived classes to change the value returned. @see get() 00710 * for more details. 00711 * 00712 * @param __s Start of string to parse. 00713 * @param __end End of string to parse. 00714 * @param __f Source of the locale. 00715 * @param __err Error flags to set. 00716 * @param __tm Pointer to struct tm to fill in. 00717 * @param __format Format specifier. 00718 * @param __modifier Format modifier. 00719 * @return Iterator to first char not parsed. 00720 */ 00721 #if _GLIBCXX_USE_CXX11_ABI 00722 virtual 00723 #endif 00724 iter_type 00725 do_get(iter_type __s, iter_type __end, ios_base& __f, 00726 ios_base::iostate& __err, tm* __tm, 00727 char __format, char __modifier) const; 00728 #endif // __cplusplus >= 201103L 00729 00730 // Extract numeric component of length __len. 00731 iter_type 00732 _M_extract_num(iter_type __beg, iter_type __end, int& __member, 00733 int __min, int __max, size_t __len, 00734 ios_base& __io, ios_base::iostate& __err) const; 00735 00736 // Extract any unique array of string literals in a const _CharT* array. 00737 iter_type 00738 _M_extract_name(iter_type __beg, iter_type __end, int& __member, 00739 const _CharT** __names, size_t __indexlen, 00740 ios_base& __io, ios_base::iostate& __err) const; 00741 00742 // Extract day or month name in a const _CharT* array. 00743 iter_type 00744 _M_extract_wday_or_month(iter_type __beg, iter_type __end, int& __member, 00745 const _CharT** __names, size_t __indexlen, 00746 ios_base& __io, ios_base::iostate& __err) const; 00747 00748 // Extract on a component-by-component basis, via __format argument. 00749 iter_type 00750 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io, 00751 ios_base::iostate& __err, tm* __tm, 00752 const _CharT* __format) const; 00753 }; 00754 00755 template<typename _CharT, typename _InIter> 00756 locale::id time_get<_CharT, _InIter>::id; 00757 00758 /// class time_get_byname [22.2.5.2]. 00759 template<typename _CharT, typename _InIter> 00760 class time_get_byname : public time_get<_CharT, _InIter> 00761 { 00762 public: 00763 // Types: 00764 typedef _CharT char_type; 00765 typedef _InIter iter_type; 00766 00767 explicit 00768 time_get_byname(const char*, size_t __refs = 0) 00769 : time_get<_CharT, _InIter>(__refs) { } 00770 00771 #if __cplusplus >= 201103L 00772 explicit 00773 time_get_byname(const string& __s, size_t __refs = 0) 00774 : time_get_byname(__s.c_str(), __refs) { } 00775 #endif 00776 00777 protected: 00778 virtual 00779 ~time_get_byname() { } 00780 }; 00781 00782 _GLIBCXX_END_NAMESPACE_CXX11 00783 00784 /** 00785 * @brief Primary class template time_put. 00786 * @ingroup locales 00787 * 00788 * This facet encapsulates the code to format and output dates and times 00789 * according to formats used by strftime(). 00790 * 00791 * The time_put template uses protected virtual functions to provide the 00792 * actual results. The public accessors forward the call to the virtual 00793 * functions. These virtual functions are hooks for developers to 00794 * implement the behavior they require from the time_put facet. 00795 */ 00796 template<typename _CharT, typename _OutIter> 00797 class time_put : public locale::facet 00798 { 00799 public: 00800 // Types: 00801 //@{ 00802 /// Public typedefs 00803 typedef _CharT char_type; 00804 typedef _OutIter iter_type; 00805 //@} 00806 00807 /// Numpunct facet id. 00808 static locale::id id; 00809 00810 /** 00811 * @brief Constructor performs initialization. 00812 * 00813 * This is the constructor provided by the standard. 00814 * 00815 * @param __refs Passed to the base facet class. 00816 */ 00817 explicit 00818 time_put(size_t __refs = 0) 00819 : facet(__refs) { } 00820 00821 /** 00822 * @brief Format and output a time or date. 00823 * 00824 * This function formats the data in struct tm according to the 00825 * provided format string. The format string is interpreted as by 00826 * strftime(). 00827 * 00828 * @param __s The stream to write to. 00829 * @param __io Source of locale. 00830 * @param __fill char_type to use for padding. 00831 * @param __tm Struct tm with date and time info to format. 00832 * @param __beg Start of format string. 00833 * @param __end End of format string. 00834 * @return Iterator after writing. 00835 */ 00836 iter_type 00837 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 00838 const _CharT* __beg, const _CharT* __end) const; 00839 00840 /** 00841 * @brief Format and output a time or date. 00842 * 00843 * This function formats the data in struct tm according to the 00844 * provided format char and optional modifier. The format and modifier 00845 * are interpreted as by strftime(). It does so by returning 00846 * time_put::do_put(). 00847 * 00848 * @param __s The stream to write to. 00849 * @param __io Source of locale. 00850 * @param __fill char_type to use for padding. 00851 * @param __tm Struct tm with date and time info to format. 00852 * @param __format Format char. 00853 * @param __mod Optional modifier char. 00854 * @return Iterator after writing. 00855 */ 00856 iter_type 00857 put(iter_type __s, ios_base& __io, char_type __fill, 00858 const tm* __tm, char __format, char __mod = 0) const 00859 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); } 00860 00861 protected: 00862 /// Destructor. 00863 virtual 00864 ~time_put() 00865 { } 00866 00867 /** 00868 * @brief Format and output a time or date. 00869 * 00870 * This function formats the data in struct tm according to the 00871 * provided format char and optional modifier. This function is a hook 00872 * for derived classes to change the value returned. @see put() for 00873 * more details. 00874 * 00875 * @param __s The stream to write to. 00876 * @param __io Source of locale. 00877 * @param __fill char_type to use for padding. 00878 * @param __tm Struct tm with date and time info to format. 00879 * @param __format Format char. 00880 * @param __mod Optional modifier char. 00881 * @return Iterator after writing. 00882 */ 00883 virtual iter_type 00884 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 00885 char __format, char __mod) const; 00886 }; 00887 00888 template<typename _CharT, typename _OutIter> 00889 locale::id time_put<_CharT, _OutIter>::id; 00890 00891 /// class time_put_byname [22.2.5.4]. 00892 template<typename _CharT, typename _OutIter> 00893 class time_put_byname : public time_put<_CharT, _OutIter> 00894 { 00895 public: 00896 // Types: 00897 typedef _CharT char_type; 00898 typedef _OutIter iter_type; 00899 00900 explicit 00901 time_put_byname(const char*, size_t __refs = 0) 00902 : time_put<_CharT, _OutIter>(__refs) 00903 { } 00904 00905 #if __cplusplus >= 201103L 00906 explicit 00907 time_put_byname(const string& __s, size_t __refs = 0) 00908 : time_put_byname(__s.c_str(), __refs) { } 00909 #endif 00910 00911 protected: 00912 virtual 00913 ~time_put_byname() { } 00914 }; 00915 00916 00917 /** 00918 * @brief Money format ordering data. 00919 * @ingroup locales 00920 * 00921 * This class contains an ordered array of 4 fields to represent the 00922 * pattern for formatting a money amount. Each field may contain one entry 00923 * from the part enum. symbol, sign, and value must be present and the 00924 * remaining field must contain either none or space. @see 00925 * moneypunct::pos_format() and moneypunct::neg_format() for details of how 00926 * these fields are interpreted. 00927 */ 00928 class money_base 00929 { 00930 public: 00931 enum part { none, space, symbol, sign, value }; 00932 struct pattern { char field[4]; }; 00933 00934 static const pattern _S_default_pattern; 00935 00936 enum 00937 { 00938 _S_minus, 00939 _S_zero, 00940 _S_end = 11 00941 }; 00942 00943 // String literal of acceptable (narrow) input/output, for 00944 // money_get/money_put. "-0123456789" 00945 static const char* _S_atoms; 00946 00947 // Construct and return valid pattern consisting of some combination of: 00948 // space none symbol sign value 00949 _GLIBCXX_CONST static pattern 00950 _S_construct_pattern(char __precedes, char __space, char __posn) throw (); 00951 }; 00952 00953 template<typename _CharT, bool _Intl> 00954 struct __moneypunct_cache : public locale::facet 00955 { 00956 const char* _M_grouping; 00957 size_t _M_grouping_size; 00958 bool _M_use_grouping; 00959 _CharT _M_decimal_point; 00960 _CharT _M_thousands_sep; 00961 const _CharT* _M_curr_symbol; 00962 size_t _M_curr_symbol_size; 00963 const _CharT* _M_positive_sign; 00964 size_t _M_positive_sign_size; 00965 const _CharT* _M_negative_sign; 00966 size_t _M_negative_sign_size; 00967 int _M_frac_digits; 00968 money_base::pattern _M_pos_format; 00969 money_base::pattern _M_neg_format; 00970 00971 // A list of valid numeric literals for input and output: in the standard 00972 // "C" locale, this is "-0123456789". This array contains the chars after 00973 // having been passed through the current locale's ctype<_CharT>.widen(). 00974 _CharT _M_atoms[money_base::_S_end]; 00975 00976 bool _M_allocated; 00977 00978 __moneypunct_cache(size_t __refs = 0) : facet(__refs), 00979 _M_grouping(0), _M_grouping_size(0), _M_use_grouping(false), 00980 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()), 00981 _M_curr_symbol(0), _M_curr_symbol_size(0), 00982 _M_positive_sign(0), _M_positive_sign_size(0), 00983 _M_negative_sign(0), _M_negative_sign_size(0), 00984 _M_frac_digits(0), 00985 _M_pos_format(money_base::pattern()), 00986 _M_neg_format(money_base::pattern()), _M_allocated(false) 00987 { } 00988 00989 ~__moneypunct_cache(); 00990 00991 void 00992 _M_cache(const locale& __loc); 00993 00994 private: 00995 __moneypunct_cache& 00996 operator=(const __moneypunct_cache&); 00997 00998 explicit 00999 __moneypunct_cache(const __moneypunct_cache&); 01000 }; 01001 01002 template<typename _CharT, bool _Intl> 01003 __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache() 01004 { 01005 if (_M_allocated) 01006 { 01007 delete [] _M_grouping; 01008 delete [] _M_curr_symbol; 01009 delete [] _M_positive_sign; 01010 delete [] _M_negative_sign; 01011 } 01012 } 01013 01014 _GLIBCXX_BEGIN_NAMESPACE_CXX11 01015 01016 /** 01017 * @brief Primary class template moneypunct. 01018 * @ingroup locales 01019 * 01020 * This facet encapsulates the punctuation, grouping and other formatting 01021 * features of money amount string representations. 01022 */ 01023 template<typename _CharT, bool _Intl> 01024 class moneypunct : public locale::facet, public money_base 01025 { 01026 public: 01027 // Types: 01028 //@{ 01029 /// Public typedefs 01030 typedef _CharT char_type; 01031 typedef basic_string<_CharT> string_type; 01032 //@} 01033 typedef __moneypunct_cache<_CharT, _Intl> __cache_type; 01034 01035 private: 01036 __cache_type* _M_data; 01037 01038 public: 01039 /// This value is provided by the standard, but no reason for its 01040 /// existence. 01041 static const bool intl = _Intl; 01042 /// Numpunct facet id. 01043 static locale::id id; 01044 01045 /** 01046 * @brief Constructor performs initialization. 01047 * 01048 * This is the constructor provided by the standard. 01049 * 01050 * @param __refs Passed to the base facet class. 01051 */ 01052 explicit 01053 moneypunct(size_t __refs = 0) 01054 : facet(__refs), _M_data(0) 01055 { _M_initialize_moneypunct(); } 01056 01057 /** 01058 * @brief Constructor performs initialization. 01059 * 01060 * This is an internal constructor. 01061 * 01062 * @param __cache Cache for optimization. 01063 * @param __refs Passed to the base facet class. 01064 */ 01065 explicit 01066 moneypunct(__cache_type* __cache, size_t __refs = 0) 01067 : facet(__refs), _M_data(__cache) 01068 { _M_initialize_moneypunct(); } 01069 01070 /** 01071 * @brief Internal constructor. Not for general use. 01072 * 01073 * This is a constructor for use by the library itself to set up new 01074 * locales. 01075 * 01076 * @param __cloc The C locale. 01077 * @param __s The name of a locale. 01078 * @param __refs Passed to the base facet class. 01079 */ 01080 explicit 01081 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0) 01082 : facet(__refs), _M_data(0) 01083 { _M_initialize_moneypunct(__cloc, __s); } 01084 01085 /** 01086 * @brief Return decimal point character. 01087 * 01088 * This function returns a char_type to use as a decimal point. It 01089 * does so by returning returning 01090 * moneypunct<char_type>::do_decimal_point(). 01091 * 01092 * @return @a char_type representing a decimal point. 01093 */ 01094 char_type 01095 decimal_point() const 01096 { return this->do_decimal_point(); } 01097 01098 /** 01099 * @brief Return thousands separator character. 01100 * 01101 * This function returns a char_type to use as a thousands 01102 * separator. It does so by returning returning 01103 * moneypunct<char_type>::do_thousands_sep(). 01104 * 01105 * @return char_type representing a thousands separator. 01106 */ 01107 char_type 01108 thousands_sep() const 01109 { return this->do_thousands_sep(); } 01110 01111 /** 01112 * @brief Return grouping specification. 01113 * 01114 * This function returns a string representing groupings for the 01115 * integer part of an amount. Groupings indicate where thousands 01116 * separators should be inserted. 01117 * 01118 * Each char in the return string is interpret as an integer rather 01119 * than a character. These numbers represent the number of digits in a 01120 * group. The first char in the string represents the number of digits 01121 * in the least significant group. If a char is negative, it indicates 01122 * an unlimited number of digits for the group. If more chars from the 01123 * string are required to group a number, the last char is used 01124 * repeatedly. 01125 * 01126 * For example, if the grouping() returns <code>\003\002</code> 01127 * and is applied to the number 123456789, this corresponds to 01128 * 12,34,56,789. Note that if the string was <code>32</code>, this would 01129 * put more than 50 digits into the least significant group if 01130 * the character set is ASCII. 01131 * 01132 * The string is returned by calling 01133 * moneypunct<char_type>::do_grouping(). 01134 * 01135 * @return string representing grouping specification. 01136 */ 01137 string 01138 grouping() const 01139 { return this->do_grouping(); } 01140 01141 /** 01142 * @brief Return currency symbol string. 01143 * 01144 * This function returns a string_type to use as a currency symbol. It 01145 * does so by returning returning 01146 * moneypunct<char_type>::do_curr_symbol(). 01147 * 01148 * @return @a string_type representing a currency symbol. 01149 */ 01150 string_type 01151 curr_symbol() const 01152 { return this->do_curr_symbol(); } 01153 01154 /** 01155 * @brief Return positive sign string. 01156 * 01157 * This function returns a string_type to use as a sign for positive 01158 * amounts. It does so by returning returning 01159 * moneypunct<char_type>::do_positive_sign(). 01160 * 01161 * If the return value contains more than one character, the first 01162 * character appears in the position indicated by pos_format() and the 01163 * remainder appear at the end of the formatted string. 01164 * 01165 * @return @a string_type representing a positive sign. 01166 */ 01167 string_type 01168 positive_sign() const 01169 { return this->do_positive_sign(); } 01170 01171 /** 01172 * @brief Return negative sign string. 01173 * 01174 * This function returns a string_type to use as a sign for negative 01175 * amounts. It does so by returning returning 01176 * moneypunct<char_type>::do_negative_sign(). 01177 * 01178 * If the return value contains more than one character, the first 01179 * character appears in the position indicated by neg_format() and the 01180 * remainder appear at the end of the formatted string. 01181 * 01182 * @return @a string_type representing a negative sign. 01183 */ 01184 string_type 01185 negative_sign() const 01186 { return this->do_negative_sign(); } 01187 01188 /** 01189 * @brief Return number of digits in fraction. 01190 * 01191 * This function returns the exact number of digits that make up the 01192 * fractional part of a money amount. It does so by returning 01193 * returning moneypunct<char_type>::do_frac_digits(). 01194 * 01195 * The fractional part of a money amount is optional. But if it is 01196 * present, there must be frac_digits() digits. 01197 * 01198 * @return Number of digits in amount fraction. 01199 */ 01200 int 01201 frac_digits() const 01202 { return this->do_frac_digits(); } 01203 01204 //@{ 01205 /** 01206 * @brief Return pattern for money values. 01207 * 01208 * This function returns a pattern describing the formatting of a 01209 * positive or negative valued money amount. It does so by returning 01210 * returning moneypunct<char_type>::do_pos_format() or 01211 * moneypunct<char_type>::do_neg_format(). 01212 * 01213 * The pattern has 4 fields describing the ordering of symbol, sign, 01214 * value, and none or space. There must be one of each in the pattern. 01215 * The none and space enums may not appear in the first field and space 01216 * may not appear in the final field. 01217 * 01218 * The parts of a money string must appear in the order indicated by 01219 * the fields of the pattern. The symbol field indicates that the 01220 * value of curr_symbol() may be present. The sign field indicates 01221 * that the value of positive_sign() or negative_sign() must be 01222 * present. The value field indicates that the absolute value of the 01223 * money amount is present. none indicates 0 or more whitespace 01224 * characters, except at the end, where it permits no whitespace. 01225 * space indicates that 1 or more whitespace characters must be 01226 * present. 01227 * 01228 * For example, for the US locale and pos_format() pattern 01229 * {symbol,sign,value,none}, curr_symbol() == '$' 01230 * positive_sign() == '+', and value 10.01, and 01231 * options set to force the symbol, the corresponding string is 01232 * <code>$+10.01</code>. 01233 * 01234 * @return Pattern for money values. 01235 */ 01236 pattern 01237 pos_format() const 01238 { return this->do_pos_format(); } 01239 01240 pattern 01241 neg_format() const 01242 { return this->do_neg_format(); } 01243 //@} 01244 01245 protected: 01246 /// Destructor. 01247 virtual 01248 ~moneypunct(); 01249 01250 /** 01251 * @brief Return decimal point character. 01252 * 01253 * Returns a char_type to use as a decimal point. This function is a 01254 * hook for derived classes to change the value returned. 01255 * 01256 * @return @a char_type representing a decimal point. 01257 */ 01258 virtual char_type 01259 do_decimal_point() const 01260 { return _M_data->_M_decimal_point; } 01261 01262 /** 01263 * @brief Return thousands separator character. 01264 * 01265 * Returns a char_type to use as a thousands separator. This function 01266 * is a hook for derived classes to change the value returned. 01267 * 01268 * @return @a char_type representing a thousands separator. 01269 */ 01270 virtual char_type 01271 do_thousands_sep() const 01272 { return _M_data->_M_thousands_sep; } 01273 01274 /** 01275 * @brief Return grouping specification. 01276 * 01277 * Returns a string representing groupings for the integer part of a 01278 * number. This function is a hook for derived classes to change the 01279 * value returned. @see grouping() for details. 01280 * 01281 * @return String representing grouping specification. 01282 */ 01283 virtual string 01284 do_grouping() const 01285 { return _M_data->_M_grouping; } 01286 01287 /** 01288 * @brief Return currency symbol string. 01289 * 01290 * This function returns a string_type to use as a currency symbol. 01291 * This function is a hook for derived classes to change the value 01292 * returned. @see curr_symbol() for details. 01293 * 01294 * @return @a string_type representing a currency symbol. 01295 */ 01296 virtual string_type 01297 do_curr_symbol() const 01298 { return _M_data->_M_curr_symbol; } 01299 01300 /** 01301 * @brief Return positive sign string. 01302 * 01303 * This function returns a string_type to use as a sign for positive 01304 * amounts. This function is a hook for derived classes to change the 01305 * value returned. @see positive_sign() for details. 01306 * 01307 * @return @a string_type representing a positive sign. 01308 */ 01309 virtual string_type 01310 do_positive_sign() const 01311 { return _M_data->_M_positive_sign; } 01312 01313 /** 01314 * @brief Return negative sign string. 01315 * 01316 * This function returns a string_type to use as a sign for negative 01317 * amounts. This function is a hook for derived classes to change the 01318 * value returned. @see negative_sign() for details. 01319 * 01320 * @return @a string_type representing a negative sign. 01321 */ 01322 virtual string_type 01323 do_negative_sign() const 01324 { return _M_data->_M_negative_sign; } 01325 01326 /** 01327 * @brief Return number of digits in fraction. 01328 * 01329 * This function returns the exact number of digits that make up the 01330 * fractional part of a money amount. This function is a hook for 01331 * derived classes to change the value returned. @see frac_digits() 01332 * for details. 01333 * 01334 * @return Number of digits in amount fraction. 01335 */ 01336 virtual int 01337 do_frac_digits() const 01338 { return _M_data->_M_frac_digits; } 01339 01340 /** 01341 * @brief Return pattern for money values. 01342 * 01343 * This function returns a pattern describing the formatting of a 01344 * positive valued money amount. This function is a hook for derived 01345 * classes to change the value returned. @see pos_format() for 01346 * details. 01347 * 01348 * @return Pattern for money values. 01349 */ 01350 virtual pattern 01351 do_pos_format() const 01352 { return _M_data->_M_pos_format; } 01353 01354 /** 01355 * @brief Return pattern for money values. 01356 * 01357 * This function returns a pattern describing the formatting of a 01358 * negative valued money amount. This function is a hook for derived 01359 * classes to change the value returned. @see neg_format() for 01360 * details. 01361 * 01362 * @return Pattern for money values. 01363 */ 01364 virtual pattern 01365 do_neg_format() const 01366 { return _M_data->_M_neg_format; } 01367 01368 // For use at construction time only. 01369 void 01370 _M_initialize_moneypunct(__c_locale __cloc = 0, 01371 const char* __name = 0); 01372 }; 01373 01374 template<typename _CharT, bool _Intl> 01375 locale::id moneypunct<_CharT, _Intl>::id; 01376 01377 template<typename _CharT, bool _Intl> 01378 const bool moneypunct<_CharT, _Intl>::intl; 01379 01380 template<> 01381 moneypunct<char, true>::~moneypunct(); 01382 01383 template<> 01384 moneypunct<char, false>::~moneypunct(); 01385 01386 template<> 01387 void 01388 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*); 01389 01390 template<> 01391 void 01392 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*); 01393 01394 #ifdef _GLIBCXX_USE_WCHAR_T 01395 template<> 01396 moneypunct<wchar_t, true>::~moneypunct(); 01397 01398 template<> 01399 moneypunct<wchar_t, false>::~moneypunct(); 01400 01401 template<> 01402 void 01403 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale, 01404 const char*); 01405 01406 template<> 01407 void 01408 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale, 01409 const char*); 01410 #endif 01411 01412 /// class moneypunct_byname [22.2.6.4]. 01413 template<typename _CharT, bool _Intl> 01414 class moneypunct_byname : public moneypunct<_CharT, _Intl> 01415 { 01416 public: 01417 typedef _CharT char_type; 01418 typedef basic_string<_CharT> string_type; 01419 01420 static const bool intl = _Intl; 01421 01422 explicit 01423 moneypunct_byname(const char* __s, size_t __refs = 0) 01424 : moneypunct<_CharT, _Intl>(__refs) 01425 { 01426 if (__builtin_strcmp(__s, "C") != 0 01427 && __builtin_strcmp(__s, "POSIX") != 0) 01428 { 01429 __c_locale __tmp; 01430 this->_S_create_c_locale(__tmp, __s); 01431 this->_M_initialize_moneypunct(__tmp); 01432 this->_S_destroy_c_locale(__tmp); 01433 } 01434 } 01435 01436 #if __cplusplus >= 201103L 01437 explicit 01438 moneypunct_byname(const string& __s, size_t __refs = 0) 01439 : moneypunct_byname(__s.c_str(), __refs) { } 01440 #endif 01441 01442 protected: 01443 virtual 01444 ~moneypunct_byname() { } 01445 }; 01446 01447 template<typename _CharT, bool _Intl> 01448 const bool moneypunct_byname<_CharT, _Intl>::intl; 01449 01450 _GLIBCXX_END_NAMESPACE_CXX11 01451 01452 _GLIBCXX_BEGIN_NAMESPACE_LDBL_OR_CXX11 01453 01454 /** 01455 * @brief Primary class template money_get. 01456 * @ingroup locales 01457 * 01458 * This facet encapsulates the code to parse and return a monetary 01459 * amount from a string. 01460 * 01461 * The money_get template uses protected virtual functions to 01462 * provide the actual results. The public accessors forward the 01463 * call to the virtual functions. These virtual functions are 01464 * hooks for developers to implement the behavior they require from 01465 * the money_get facet. 01466 */ 01467 template<typename _CharT, typename _InIter> 01468 class money_get : public locale::facet 01469 { 01470 public: 01471 // Types: 01472 //@{ 01473 /// Public typedefs 01474 typedef _CharT char_type; 01475 typedef _InIter iter_type; 01476 typedef basic_string<_CharT> string_type; 01477 //@} 01478 01479 /// Numpunct facet id. 01480 static locale::id id; 01481 01482 /** 01483 * @brief Constructor performs initialization. 01484 * 01485 * This is the constructor provided by the standard. 01486 * 01487 * @param __refs Passed to the base facet class. 01488 */ 01489 explicit 01490 money_get(size_t __refs = 0) : facet(__refs) { } 01491 01492 /** 01493 * @brief Read and parse a monetary value. 01494 * 01495 * This function reads characters from @a __s, interprets them as a 01496 * monetary value according to moneypunct and ctype facets retrieved 01497 * from io.getloc(), and returns the result in @a units as an integral 01498 * value moneypunct::frac_digits() * the actual amount. For example, 01499 * the string $10.01 in a US locale would store 1001 in @a units. 01500 * 01501 * Any characters not part of a valid money amount are not consumed. 01502 * 01503 * If a money value cannot be parsed from the input stream, sets 01504 * err=(err|io.failbit). If the stream is consumed before finishing 01505 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is 01506 * unchanged if parsing fails. 01507 * 01508 * This function works by returning the result of do_get(). 01509 * 01510 * @param __s Start of characters to parse. 01511 * @param __end End of characters to parse. 01512 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 01513 * @param __io Source of facets and io state. 01514 * @param __err Error field to set if parsing fails. 01515 * @param __units Place to store result of parsing. 01516 * @return Iterator referencing first character beyond valid money 01517 * amount. 01518 */ 01519 iter_type 01520 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01521 ios_base::iostate& __err, long double& __units) const 01522 { return this->do_get(__s, __end, __intl, __io, __err, __units); } 01523 01524 /** 01525 * @brief Read and parse a monetary value. 01526 * 01527 * This function reads characters from @a __s, interprets them as 01528 * a monetary value according to moneypunct and ctype facets 01529 * retrieved from io.getloc(), and returns the result in @a 01530 * digits. For example, the string $10.01 in a US locale would 01531 * store <code>1001</code> in @a digits. 01532 * 01533 * Any characters not part of a valid money amount are not consumed. 01534 * 01535 * If a money value cannot be parsed from the input stream, sets 01536 * err=(err|io.failbit). If the stream is consumed before finishing 01537 * parsing, sets err=(err|io.failbit|io.eofbit). 01538 * 01539 * This function works by returning the result of do_get(). 01540 * 01541 * @param __s Start of characters to parse. 01542 * @param __end End of characters to parse. 01543 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 01544 * @param __io Source of facets and io state. 01545 * @param __err Error field to set if parsing fails. 01546 * @param __digits Place to store result of parsing. 01547 * @return Iterator referencing first character beyond valid money 01548 * amount. 01549 */ 01550 iter_type 01551 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01552 ios_base::iostate& __err, string_type& __digits) const 01553 { return this->do_get(__s, __end, __intl, __io, __err, __digits); } 01554 01555 protected: 01556 /// Destructor. 01557 virtual 01558 ~money_get() { } 01559 01560 /** 01561 * @brief Read and parse a monetary value. 01562 * 01563 * This function reads and parses characters representing a monetary 01564 * value. This function is a hook for derived classes to change the 01565 * value returned. @see get() for details. 01566 */ 01567 // XXX GLIBCXX_ABI Deprecated 01568 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ 01569 && _GLIBCXX_USE_CXX11_ABI == 0 01570 virtual iter_type 01571 __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01572 ios_base::iostate& __err, double& __units) const; 01573 #else 01574 virtual iter_type 01575 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01576 ios_base::iostate& __err, long double& __units) const; 01577 #endif 01578 01579 /** 01580 * @brief Read and parse a monetary value. 01581 * 01582 * This function reads and parses characters representing a monetary 01583 * value. This function is a hook for derived classes to change the 01584 * value returned. @see get() for details. 01585 */ 01586 virtual iter_type 01587 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01588 ios_base::iostate& __err, string_type& __digits) const; 01589 01590 // XXX GLIBCXX_ABI Deprecated 01591 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ 01592 && _GLIBCXX_USE_CXX11_ABI == 0 01593 virtual iter_type 01594 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 01595 ios_base::iostate& __err, long double& __units) const; 01596 #endif 01597 01598 template<bool _Intl> 01599 iter_type 01600 _M_extract(iter_type __s, iter_type __end, ios_base& __io, 01601 ios_base::iostate& __err, string& __digits) const; 01602 }; 01603 01604 template<typename _CharT, typename _InIter> 01605 locale::id money_get<_CharT, _InIter>::id; 01606 01607 /** 01608 * @brief Primary class template money_put. 01609 * @ingroup locales 01610 * 01611 * This facet encapsulates the code to format and output a monetary 01612 * amount. 01613 * 01614 * The money_put template uses protected virtual functions to 01615 * provide the actual results. The public accessors forward the 01616 * call to the virtual functions. These virtual functions are 01617 * hooks for developers to implement the behavior they require from 01618 * the money_put facet. 01619 */ 01620 template<typename _CharT, typename _OutIter> 01621 class money_put : public locale::facet 01622 { 01623 public: 01624 //@{ 01625 /// Public typedefs 01626 typedef _CharT char_type; 01627 typedef _OutIter iter_type; 01628 typedef basic_string<_CharT> string_type; 01629 //@} 01630 01631 /// Numpunct facet id. 01632 static locale::id id; 01633 01634 /** 01635 * @brief Constructor performs initialization. 01636 * 01637 * This is the constructor provided by the standard. 01638 * 01639 * @param __refs Passed to the base facet class. 01640 */ 01641 explicit 01642 money_put(size_t __refs = 0) : facet(__refs) { } 01643 01644 /** 01645 * @brief Format and output a monetary value. 01646 * 01647 * This function formats @a units as a monetary value according to 01648 * moneypunct and ctype facets retrieved from io.getloc(), and writes 01649 * the resulting characters to @a __s. For example, the value 1001 in a 01650 * US locale would write <code>$10.01</code> to @a __s. 01651 * 01652 * This function works by returning the result of do_put(). 01653 * 01654 * @param __s The stream to write to. 01655 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 01656 * @param __io Source of facets and io state. 01657 * @param __fill char_type to use for padding. 01658 * @param __units Place to store result of parsing. 01659 * @return Iterator after writing. 01660 */ 01661 iter_type 01662 put(iter_type __s, bool __intl, ios_base& __io, 01663 char_type __fill, long double __units) const 01664 { return this->do_put(__s, __intl, __io, __fill, __units); } 01665 01666 /** 01667 * @brief Format and output a monetary value. 01668 * 01669 * This function formats @a digits as a monetary value 01670 * according to moneypunct and ctype facets retrieved from 01671 * io.getloc(), and writes the resulting characters to @a __s. 01672 * For example, the string <code>1001</code> in a US locale 01673 * would write <code>$10.01</code> to @a __s. 01674 * 01675 * This function works by returning the result of do_put(). 01676 * 01677 * @param __s The stream to write to. 01678 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 01679 * @param __io Source of facets and io state. 01680 * @param __fill char_type to use for padding. 01681 * @param __digits Place to store result of parsing. 01682 * @return Iterator after writing. 01683 */ 01684 iter_type 01685 put(iter_type __s, bool __intl, ios_base& __io, 01686 char_type __fill, const string_type& __digits) const 01687 { return this->do_put(__s, __intl, __io, __fill, __digits); } 01688 01689 protected: 01690 /// Destructor. 01691 virtual 01692 ~money_put() { } 01693 01694 /** 01695 * @brief Format and output a monetary value. 01696 * 01697 * This function formats @a units as a monetary value according to 01698 * moneypunct and ctype facets retrieved from io.getloc(), and writes 01699 * the resulting characters to @a __s. For example, the value 1001 in a 01700 * US locale would write <code>$10.01</code> to @a __s. 01701 * 01702 * This function is a hook for derived classes to change the value 01703 * returned. @see put(). 01704 * 01705 * @param __s The stream to write to. 01706 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 01707 * @param __io Source of facets and io state. 01708 * @param __fill char_type to use for padding. 01709 * @param __units Place to store result of parsing. 01710 * @return Iterator after writing. 01711 */ 01712 // XXX GLIBCXX_ABI Deprecated 01713 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ 01714 && _GLIBCXX_USE_CXX11_ABI == 0 01715 virtual iter_type 01716 __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 01717 double __units) const; 01718 #else 01719 virtual iter_type 01720 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 01721 long double __units) const; 01722 #endif 01723 01724 /** 01725 * @brief Format and output a monetary value. 01726 * 01727 * This function formats @a digits as a monetary value 01728 * according to moneypunct and ctype facets retrieved from 01729 * io.getloc(), and writes the resulting characters to @a __s. 01730 * For example, the string <code>1001</code> in a US locale 01731 * would write <code>$10.01</code> to @a __s. 01732 * 01733 * This function is a hook for derived classes to change the value 01734 * returned. @see put(). 01735 * 01736 * @param __s The stream to write to. 01737 * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >. 01738 * @param __io Source of facets and io state. 01739 * @param __fill char_type to use for padding. 01740 * @param __digits Place to store result of parsing. 01741 * @return Iterator after writing. 01742 */ 01743 virtual iter_type 01744 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 01745 const string_type& __digits) const; 01746 01747 // XXX GLIBCXX_ABI Deprecated 01748 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \ 01749 && _GLIBCXX_USE_CXX11_ABI == 0 01750 virtual iter_type 01751 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 01752 long double __units) const; 01753 #endif 01754 01755 template<bool _Intl> 01756 iter_type 01757 _M_insert(iter_type __s, ios_base& __io, char_type __fill, 01758 const string_type& __digits) const; 01759 }; 01760 01761 template<typename _CharT, typename _OutIter> 01762 locale::id money_put<_CharT, _OutIter>::id; 01763 01764 _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11 01765 01766 /** 01767 * @brief Messages facet base class providing catalog typedef. 01768 * @ingroup locales 01769 */ 01770 struct messages_base 01771 { 01772 typedef int catalog; 01773 }; 01774 01775 _GLIBCXX_BEGIN_NAMESPACE_CXX11 01776 01777 /** 01778 * @brief Primary class template messages. 01779 * @ingroup locales 01780 * 01781 * This facet encapsulates the code to retrieve messages from 01782 * message catalogs. The only thing defined by the standard for this facet 01783 * is the interface. All underlying functionality is 01784 * implementation-defined. 01785 * 01786 * This library currently implements 3 versions of the message facet. The 01787 * first version (gnu) is a wrapper around gettext, provided by libintl. 01788 * The second version (ieee) is a wrapper around catgets. The final 01789 * version (default) does no actual translation. These implementations are 01790 * only provided for char and wchar_t instantiations. 01791 * 01792 * The messages template uses protected virtual functions to 01793 * provide the actual results. The public accessors forward the 01794 * call to the virtual functions. These virtual functions are 01795 * hooks for developers to implement the behavior they require from 01796 * the messages facet. 01797 */ 01798 template<typename _CharT> 01799 class messages : public locale::facet, public messages_base 01800 { 01801 public: 01802 // Types: 01803 //@{ 01804 /// Public typedefs 01805 typedef _CharT char_type; 01806 typedef basic_string<_CharT> string_type; 01807 //@} 01808 01809 protected: 01810 // Underlying "C" library locale information saved from 01811 // initialization, needed by messages_byname as well. 01812 __c_locale _M_c_locale_messages; 01813 const char* _M_name_messages; 01814 01815 public: 01816 /// Numpunct facet id. 01817 static locale::id id; 01818 01819 /** 01820 * @brief Constructor performs initialization. 01821 * 01822 * This is the constructor provided by the standard. 01823 * 01824 * @param __refs Passed to the base facet class. 01825 */ 01826 explicit 01827 messages(size_t __refs = 0); 01828 01829 // Non-standard. 01830 /** 01831 * @brief Internal constructor. Not for general use. 01832 * 01833 * This is a constructor for use by the library itself to set up new 01834 * locales. 01835 * 01836 * @param __cloc The C locale. 01837 * @param __s The name of a locale. 01838 * @param __refs Refcount to pass to the base class. 01839 */ 01840 explicit 01841 messages(__c_locale __cloc, const char* __s, size_t __refs = 0); 01842 01843 /* 01844 * @brief Open a message catalog. 01845 * 01846 * This function opens and returns a handle to a message catalog by 01847 * returning do_open(__s, __loc). 01848 * 01849 * @param __s The catalog to open. 01850 * @param __loc Locale to use for character set conversions. 01851 * @return Handle to the catalog or value < 0 if open fails. 01852 */ 01853 catalog 01854 open(const basic_string<char>& __s, const locale& __loc) const 01855 { return this->do_open(__s, __loc); } 01856 01857 // Non-standard and unorthodox, yet effective. 01858 /* 01859 * @brief Open a message catalog. 01860 * 01861 * This non-standard function opens and returns a handle to a message 01862 * catalog by returning do_open(s, loc). The third argument provides a 01863 * message catalog root directory for gnu gettext and is ignored 01864 * otherwise. 01865 * 01866 * @param __s The catalog to open. 01867 * @param __loc Locale to use for character set conversions. 01868 * @param __dir Message catalog root directory. 01869 * @return Handle to the catalog or value < 0 if open fails. 01870 */ 01871 catalog 01872 open(const basic_string<char>&, const locale&, const char*) const; 01873 01874 /* 01875 * @brief Look up a string in a message catalog. 01876 * 01877 * This function retrieves and returns a message from a catalog by 01878 * returning do_get(c, set, msgid, s). 01879 * 01880 * For gnu, @a __set and @a msgid are ignored. Returns gettext(s). 01881 * For default, returns s. For ieee, returns catgets(c,set,msgid,s). 01882 * 01883 * @param __c The catalog to access. 01884 * @param __set Implementation-defined. 01885 * @param __msgid Implementation-defined. 01886 * @param __s Default return value if retrieval fails. 01887 * @return Retrieved message or @a __s if get fails. 01888 */ 01889 string_type 01890 get(catalog __c, int __set, int __msgid, const string_type& __s) const 01891 { return this->do_get(__c, __set, __msgid, __s); } 01892 01893 /* 01894 * @brief Close a message catalog. 01895 * 01896 * Closes catalog @a c by calling do_close(c). 01897 * 01898 * @param __c The catalog to close. 01899 */ 01900 void 01901 close(catalog __c) const 01902 { return this->do_close(__c); } 01903 01904 protected: 01905 /// Destructor. 01906 virtual 01907 ~messages(); 01908 01909 /* 01910 * @brief Open a message catalog. 01911 * 01912 * This function opens and returns a handle to a message catalog in an 01913 * implementation-defined manner. This function is a hook for derived 01914 * classes to change the value returned. 01915 * 01916 * @param __s The catalog to open. 01917 * @param __loc Locale to use for character set conversions. 01918 * @return Handle to the opened catalog, value < 0 if open failed. 01919 */ 01920 virtual catalog 01921 do_open(const basic_string<char>&, const locale&) const; 01922 01923 /* 01924 * @brief Look up a string in a message catalog. 01925 * 01926 * This function retrieves and returns a message from a catalog in an 01927 * implementation-defined manner. This function is a hook for derived 01928 * classes to change the value returned. 01929 * 01930 * For gnu, @a __set and @a __msgid are ignored. Returns gettext(s). 01931 * For default, returns s. For ieee, returns catgets(c,set,msgid,s). 01932 * 01933 * @param __c The catalog to access. 01934 * @param __set Implementation-defined. 01935 * @param __msgid Implementation-defined. 01936 * @param __s Default return value if retrieval fails. 01937 * @return Retrieved message or @a __s if get fails. 01938 */ 01939 virtual string_type 01940 do_get(catalog, int, int, const string_type& __dfault) const; 01941 01942 /* 01943 * @brief Close a message catalog. 01944 * 01945 * @param __c The catalog to close. 01946 */ 01947 virtual void 01948 do_close(catalog) const; 01949 01950 // Returns a locale and codeset-converted string, given a char* message. 01951 char* 01952 _M_convert_to_char(const string_type& __msg) const 01953 { 01954 // XXX 01955 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str())); 01956 } 01957 01958 // Returns a locale and codeset-converted string, given a char* message. 01959 string_type 01960 _M_convert_from_char(char*) const 01961 { 01962 // XXX 01963 return string_type(); 01964 } 01965 }; 01966 01967 template<typename _CharT> 01968 locale::id messages<_CharT>::id; 01969 01970 /// Specializations for required instantiations. 01971 template<> 01972 string 01973 messages<char>::do_get(catalog, int, int, const string&) const; 01974 01975 #ifdef _GLIBCXX_USE_WCHAR_T 01976 template<> 01977 wstring 01978 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const; 01979 #endif 01980 01981 /// class messages_byname [22.2.7.2]. 01982 template<typename _CharT> 01983 class messages_byname : public messages<_CharT> 01984 { 01985 public: 01986 typedef _CharT char_type; 01987 typedef basic_string<_CharT> string_type; 01988 01989 explicit 01990 messages_byname(const char* __s, size_t __refs = 0); 01991 01992 #if __cplusplus >= 201103L 01993 explicit 01994 messages_byname(const string& __s, size_t __refs = 0) 01995 : messages_byname(__s.c_str(), __refs) { } 01996 #endif 01997 01998 protected: 01999 virtual 02000 ~messages_byname() 02001 { } 02002 }; 02003 02004 _GLIBCXX_END_NAMESPACE_CXX11 02005 02006 _GLIBCXX_END_NAMESPACE_VERSION 02007 } // namespace 02008 02009 // Include host and configuration specific messages functions. 02010 #include <bits/messages_members.h> 02011 02012 // 22.2.1.5 Template class codecvt 02013 #include <bits/codecvt.h> 02014 02015 #include <bits/locale_facets_nonio.tcc> 02016 02017 #endif