1// Locale support -*- C++ -*- 2 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 4// Free Software Foundation, Inc. 5// 6// This file is part of the GNU ISO C++ Library. This library is free 7// software; you can redistribute it and/or modify it under the 8// terms of the GNU General Public License as published by the 9// Free Software Foundation; either version 2, or (at your option) 10// any later version. 11 12// This library is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17// You should have received a copy of the GNU General Public License along 18// with this library; see the file COPYING. If not, write to the Free 19// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 20// USA. 21 22// As a special exception, you may use this file as part of a free software 23// library without restriction. Specifically, if other files instantiate 24// templates or use macros or inline functions from this file, or you compile 25// this file and link it with other files to produce an executable, this 26// file does not by itself cause the resulting executable to be covered by 27// the GNU General Public License. This exception does not however 28// invalidate any other reasons why the executable file might be covered by 29// the GNU General Public License. 30 31/** @file locale_facets.h 32 * This is an internal header file, included by other library headers. 33 * You should not attempt to use it directly. 34 */ 35 36// 37// ISO C++ 14882: 22.1 Locales 38// 39 40#ifndef _LOCALE_FACETS_H 41#define _LOCALE_FACETS_H 1 42 43#pragma GCC system_header 44 45#include <ctime> // For struct tm 46#include <cwctype> // For wctype_t 47#include <bits/ctype_base.h> 48#include <iosfwd> 49#include <bits/ios_base.h> // For ios_base, ios_base::iostate 50#include <streambuf> 51#include <bits/cpp_type_traits.h> 52 53_GLIBCXX_BEGIN_NAMESPACE(std) 54 55 // NB: Don't instantiate required wchar_t facets if no wchar_t support. 56#ifdef _GLIBCXX_USE_WCHAR_T 57# define _GLIBCXX_NUM_FACETS 28 58#else 59# define _GLIBCXX_NUM_FACETS 14 60#endif 61 62 // Convert string to numeric value of type _Tv and store results. 63 // NB: This is specialized for all required types, there is no 64 // generic definition. 65 template<typename _Tv> 66 void 67 __convert_to_v(const char* __in, _Tv& __out, ios_base::iostate& __err, 68 const __c_locale& __cloc); 69 70 // Explicit specializations for required types. 71 template<> 72 void 73 __convert_to_v(const char*, float&, ios_base::iostate&, 74 const __c_locale&); 75 76 template<> 77 void 78 __convert_to_v(const char*, double&, ios_base::iostate&, 79 const __c_locale&); 80 81 template<> 82 void 83 __convert_to_v(const char*, long double&, ios_base::iostate&, 84 const __c_locale&); 85 86 // NB: __pad is a struct, rather than a function, so it can be 87 // partially-specialized. 88 template<typename _CharT, typename _Traits> 89 struct __pad 90 { 91 static void 92 _S_pad(ios_base& __io, _CharT __fill, _CharT* __news, 93 const _CharT* __olds, const streamsize __newlen, 94 const streamsize __oldlen, const bool __num); 95 }; 96 97 // Used by both numeric and monetary facets. 98 // Inserts "group separator" characters into an array of characters. 99 // It's recursive, one iteration per group. It moves the characters 100 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this 101 // only with __glen != 0. 102 template<typename _CharT> 103 _CharT* 104 __add_grouping(_CharT* __s, _CharT __sep, 105 const char* __gbeg, size_t __gsize, 106 const _CharT* __first, const _CharT* __last); 107 108 // This template permits specializing facet output code for 109 // ostreambuf_iterator. For ostreambuf_iterator, sputn is 110 // significantly more efficient than incrementing iterators. 111 template<typename _CharT> 112 inline 113 ostreambuf_iterator<_CharT> 114 __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len) 115 { 116 __s._M_put(__ws, __len); 117 return __s; 118 } 119 120 // This is the unspecialized form of the template. 121 template<typename _CharT, typename _OutIter> 122 inline 123 _OutIter 124 __write(_OutIter __s, const _CharT* __ws, int __len) 125 { 126 for (int __j = 0; __j < __len; __j++, ++__s) 127 *__s = __ws[__j]; 128 return __s; 129 } 130 131 132 // 22.2.1.1 Template class ctype 133 // Include host and configuration specific ctype enums for ctype_base. 134 135 // Common base for ctype<_CharT>. 136 /** 137 * @brief Common base for ctype facet 138 * 139 * This template class provides implementations of the public functions 140 * that forward to the protected virtual functions. 141 * 142 * This template also provides abtract stubs for the protected virtual 143 * functions. 144 */ 145 template<typename _CharT> 146 class __ctype_abstract_base : public locale::facet, public ctype_base 147 { 148 public: 149 // Types: 150 /// Typedef for the template parameter 151 typedef _CharT char_type; 152 153 /** 154 * @brief Test char_type classification. 155 * 156 * This function finds a mask M for @a c and compares it to mask @a m. 157 * It does so by returning the value of ctype<char_type>::do_is(). 158 * 159 * @param c The char_type to compare the mask of. 160 * @param m The mask to compare against. 161 * @return (M & m) != 0. 162 */ 163 bool 164 is(mask __m, char_type __c) const 165 { return this->do_is(__m, __c); } 166 167 /** 168 * @brief Return a mask array. 169 * 170 * This function finds the mask for each char_type in the range [lo,hi) 171 * and successively writes it to vec. vec must have as many elements 172 * as the char array. It does so by returning the value of 173 * ctype<char_type>::do_is(). 174 * 175 * @param lo Pointer to start of range. 176 * @param hi Pointer to end of range. 177 * @param vec Pointer to an array of mask storage. 178 * @return @a hi. 179 */ 180 const char_type* 181 is(const char_type *__lo, const char_type *__hi, mask *__vec) const 182 { return this->do_is(__lo, __hi, __vec); } 183 184 /** 185 * @brief Find char_type matching a mask 186 * 187 * This function searches for and returns the first char_type c in 188 * [lo,hi) for which is(m,c) is true. It does so by returning 189 * ctype<char_type>::do_scan_is(). 190 * 191 * @param m The mask to compare against. 192 * @param lo Pointer to start of range. 193 * @param hi Pointer to end of range. 194 * @return Pointer to matching char_type if found, else @a hi. 195 */ 196 const char_type* 197 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const 198 { return this->do_scan_is(__m, __lo, __hi); } 199 200 /** 201 * @brief Find char_type not matching a mask 202 * 203 * This function searches for and returns the first char_type c in 204 * [lo,hi) for which is(m,c) is false. It does so by returning 205 * ctype<char_type>::do_scan_not(). 206 * 207 * @param m The mask to compare against. 208 * @param lo Pointer to first char in range. 209 * @param hi Pointer to end of range. 210 * @return Pointer to non-matching char if found, else @a hi. 211 */ 212 const char_type* 213 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const 214 { return this->do_scan_not(__m, __lo, __hi); } 215 216 /** 217 * @brief Convert to uppercase. 218 * 219 * This function converts the argument to uppercase if possible. 220 * If not possible (for example, '2'), returns the argument. It does 221 * so by returning ctype<char_type>::do_toupper(). 222 * 223 * @param c The char_type to convert. 224 * @return The uppercase char_type if convertible, else @a c. 225 */ 226 char_type 227 toupper(char_type __c) const 228 { return this->do_toupper(__c); } 229 230 /** 231 * @brief Convert array to uppercase. 232 * 233 * This function converts each char_type in the range [lo,hi) to 234 * uppercase if possible. Other elements remain untouched. It does so 235 * by returning ctype<char_type>:: do_toupper(lo, hi). 236 * 237 * @param lo Pointer to start of range. 238 * @param hi Pointer to end of range. 239 * @return @a hi. 240 */ 241 const char_type* 242 toupper(char_type *__lo, const char_type* __hi) const 243 { return this->do_toupper(__lo, __hi); } 244 245 /** 246 * @brief Convert to lowercase. 247 * 248 * This function converts the argument to lowercase if possible. If 249 * not possible (for example, '2'), returns the argument. It does so 250 * by returning ctype<char_type>::do_tolower(c). 251 * 252 * @param c The char_type to convert. 253 * @return The lowercase char_type if convertible, else @a c. 254 */ 255 char_type 256 tolower(char_type __c) const 257 { return this->do_tolower(__c); } 258 259 /** 260 * @brief Convert array to lowercase. 261 * 262 * This function converts each char_type in the range [lo,hi) to 263 * lowercase if possible. Other elements remain untouched. It does so 264 * by returning ctype<char_type>:: do_tolower(lo, hi). 265 * 266 * @param lo Pointer to start of range. 267 * @param hi Pointer to end of range. 268 * @return @a hi. 269 */ 270 const char_type* 271 tolower(char_type* __lo, const char_type* __hi) const 272 { return this->do_tolower(__lo, __hi); } 273 274 /** 275 * @brief Widen char to char_type 276 * 277 * This function converts the char argument to char_type using the 278 * simplest reasonable transformation. It does so by returning 279 * ctype<char_type>::do_widen(c). 280 * 281 * Note: this is not what you want for codepage conversions. See 282 * codecvt for that. 283 * 284 * @param c The char to convert. 285 * @return The converted char_type. 286 */ 287 char_type 288 widen(char __c) const 289 { return this->do_widen(__c); } 290 291 /** 292 * @brief Widen array to char_type 293 * 294 * This function converts each char in the input to char_type using the 295 * simplest reasonable transformation. It does so by returning 296 * ctype<char_type>::do_widen(c). 297 * 298 * Note: this is not what you want for codepage conversions. See 299 * codecvt for that. 300 * 301 * @param lo Pointer to start of range. 302 * @param hi Pointer to end of range. 303 * @param to Pointer to the destination array. 304 * @return @a hi. 305 */ 306 const char* 307 widen(const char* __lo, const char* __hi, char_type* __to) const 308 { return this->do_widen(__lo, __hi, __to); } 309 310 /** 311 * @brief Narrow char_type to char 312 * 313 * This function converts the char_type to char using the simplest 314 * reasonable transformation. If the conversion fails, dfault is 315 * returned instead. It does so by returning 316 * ctype<char_type>::do_narrow(c). 317 * 318 * Note: this is not what you want for codepage conversions. See 319 * codecvt for that. 320 * 321 * @param c The char_type to convert. 322 * @param dfault Char to return if conversion fails. 323 * @return The converted char. 324 */ 325 char 326 narrow(char_type __c, char __dfault) const 327 { return this->do_narrow(__c, __dfault); } 328 329 /** 330 * @brief Narrow array to char array 331 * 332 * This function converts each char_type in the input to char using the 333 * simplest reasonable transformation and writes the results to the 334 * destination array. For any char_type in the input that cannot be 335 * converted, @a dfault is used instead. It does so by returning 336 * ctype<char_type>::do_narrow(lo, hi, dfault, to). 337 * 338 * Note: this is not what you want for codepage conversions. See 339 * codecvt for that. 340 * 341 * @param lo Pointer to start of range. 342 * @param hi Pointer to end of range. 343 * @param dfault Char to use if conversion fails. 344 * @param to Pointer to the destination array. 345 * @return @a hi. 346 */ 347 const char_type* 348 narrow(const char_type* __lo, const char_type* __hi, 349 char __dfault, char *__to) const 350 { return this->do_narrow(__lo, __hi, __dfault, __to); } 351 352 protected: 353 explicit 354 __ctype_abstract_base(size_t __refs = 0): facet(__refs) { } 355 356 virtual 357 ~__ctype_abstract_base() { } 358 359 /** 360 * @brief Test char_type classification. 361 * 362 * This function finds a mask M for @a c and compares it to mask @a m. 363 * 364 * do_is() is a hook for a derived facet to change the behavior of 365 * classifying. do_is() must always return the same result for the 366 * same input. 367 * 368 * @param c The char_type to find the mask of. 369 * @param m The mask to compare against. 370 * @return (M & m) != 0. 371 */ 372 virtual bool 373 do_is(mask __m, char_type __c) const = 0; 374 375 /** 376 * @brief Return a mask array. 377 * 378 * This function finds the mask for each char_type in the range [lo,hi) 379 * and successively writes it to vec. vec must have as many elements 380 * as the input. 381 * 382 * do_is() is a hook for a derived facet to change the behavior of 383 * classifying. do_is() must always return the same result for the 384 * same input. 385 * 386 * @param lo Pointer to start of range. 387 * @param hi Pointer to end of range. 388 * @param vec Pointer to an array of mask storage. 389 * @return @a hi. 390 */ 391 virtual const char_type* 392 do_is(const char_type* __lo, const char_type* __hi, 393 mask* __vec) const = 0; 394 395 /** 396 * @brief Find char_type matching mask 397 * 398 * This function searches for and returns the first char_type c in 399 * [lo,hi) for which is(m,c) is true. 400 * 401 * do_scan_is() is a hook for a derived facet to change the behavior of 402 * match searching. do_is() must always return the same result for the 403 * same input. 404 * 405 * @param m The mask to compare against. 406 * @param lo Pointer to start of range. 407 * @param hi Pointer to end of range. 408 * @return Pointer to a matching char_type if found, else @a hi. 409 */ 410 virtual const char_type* 411 do_scan_is(mask __m, const char_type* __lo, 412 const char_type* __hi) const = 0; 413 414 /** 415 * @brief Find char_type not matching mask 416 * 417 * This function searches for and returns a pointer to the first 418 * char_type c of [lo,hi) for which is(m,c) is false. 419 * 420 * do_scan_is() is a hook for a derived facet to change the behavior of 421 * match searching. do_is() must always return the same result for the 422 * same input. 423 * 424 * @param m The mask to compare against. 425 * @param lo Pointer to start of range. 426 * @param hi Pointer to end of range. 427 * @return Pointer to a non-matching char_type if found, else @a hi. 428 */ 429 virtual const char_type* 430 do_scan_not(mask __m, const char_type* __lo, 431 const char_type* __hi) const = 0; 432 433 /** 434 * @brief Convert to uppercase. 435 * 436 * This virtual function converts the char_type argument to uppercase 437 * if possible. If not possible (for example, '2'), returns the 438 * argument. 439 * 440 * do_toupper() is a hook for a derived facet to change the behavior of 441 * uppercasing. do_toupper() must always return the same result for 442 * the same input. 443 * 444 * @param c The char_type to convert. 445 * @return The uppercase char_type if convertible, else @a c. 446 */ 447 virtual char_type 448 do_toupper(char_type) const = 0; 449 450 /** 451 * @brief Convert array to uppercase. 452 * 453 * This virtual function converts each char_type in the range [lo,hi) 454 * to uppercase if possible. Other elements remain untouched. 455 * 456 * do_toupper() is a hook for a derived facet to change the behavior of 457 * uppercasing. do_toupper() must always return the same result for 458 * the same input. 459 * 460 * @param lo Pointer to start of range. 461 * @param hi Pointer to end of range. 462 * @return @a hi. 463 */ 464 virtual const char_type* 465 do_toupper(char_type* __lo, const char_type* __hi) const = 0; 466 467 /** 468 * @brief Convert to lowercase. 469 * 470 * This virtual function converts the argument to lowercase if 471 * possible. If not possible (for example, '2'), returns the argument. 472 * 473 * do_tolower() is a hook for a derived facet to change the behavior of 474 * lowercasing. do_tolower() must always return the same result for 475 * the same input. 476 * 477 * @param c The char_type to convert. 478 * @return The lowercase char_type if convertible, else @a c. 479 */ 480 virtual char_type 481 do_tolower(char_type) const = 0; 482 483 /** 484 * @brief Convert array to lowercase. 485 * 486 * This virtual function converts each char_type in the range [lo,hi) 487 * to lowercase if possible. Other elements remain untouched. 488 * 489 * do_tolower() is a hook for a derived facet to change the behavior of 490 * lowercasing. do_tolower() must always return the same result for 491 * the same input. 492 * 493 * @param lo Pointer to start of range. 494 * @param hi Pointer to end of range. 495 * @return @a hi. 496 */ 497 virtual const char_type* 498 do_tolower(char_type* __lo, const char_type* __hi) const = 0; 499 500 /** 501 * @brief Widen char 502 * 503 * This virtual function converts the char to char_type using the 504 * simplest reasonable transformation. 505 * 506 * do_widen() is a hook for a derived facet to change the behavior of 507 * widening. do_widen() must always return the same result for the 508 * same input. 509 * 510 * Note: this is not what you want for codepage conversions. See 511 * codecvt for that. 512 * 513 * @param c The char to convert. 514 * @return The converted char_type 515 */ 516 virtual char_type 517 do_widen(char) const = 0; 518 519 /** 520 * @brief Widen char array 521 * 522 * This function converts each char in the input to char_type using the 523 * simplest reasonable transformation. 524 * 525 * do_widen() is a hook for a derived facet to change the behavior of 526 * widening. do_widen() must always return the same result for the 527 * same input. 528 * 529 * Note: this is not what you want for codepage conversions. See 530 * codecvt for that. 531 * 532 * @param lo Pointer to start range. 533 * @param hi Pointer to end of range. 534 * @param to Pointer to the destination array. 535 * @return @a hi. 536 */ 537 virtual const char* 538 do_widen(const char* __lo, const char* __hi, 539 char_type* __dest) const = 0; 540 541 /** 542 * @brief Narrow char_type to char 543 * 544 * This virtual function converts the argument to char using the 545 * simplest reasonable transformation. If the conversion fails, dfault 546 * is returned instead. 547 * 548 * do_narrow() is a hook for a derived facet to change the behavior of 549 * narrowing. do_narrow() must always return the same result for the 550 * same input. 551 * 552 * Note: this is not what you want for codepage conversions. See 553 * codecvt for that. 554 * 555 * @param c The char_type to convert. 556 * @param dfault Char to return if conversion fails. 557 * @return The converted char. 558 */ 559 virtual char 560 do_narrow(char_type, char __dfault) const = 0; 561 562 /** 563 * @brief Narrow char_type array to char 564 * 565 * This virtual function converts each char_type in the range [lo,hi) to 566 * char using the simplest reasonable transformation and writes the 567 * results to the destination array. For any element in the input that 568 * cannot be converted, @a dfault is used instead. 569 * 570 * do_narrow() is a hook for a derived facet to change the behavior of 571 * narrowing. do_narrow() must always return the same result for the 572 * same input. 573 * 574 * Note: this is not what you want for codepage conversions. See 575 * codecvt for that. 576 * 577 * @param lo Pointer to start of range. 578 * @param hi Pointer to end of range. 579 * @param dfault Char to use if conversion fails. 580 * @param to Pointer to the destination array. 581 * @return @a hi. 582 */ 583 virtual const char_type* 584 do_narrow(const char_type* __lo, const char_type* __hi, 585 char __dfault, char* __dest) const = 0; 586 }; 587 588 // NB: Generic, mostly useless implementation. 589 /** 590 * @brief Template ctype facet 591 * 592 * This template class defines classification and conversion functions for 593 * character sets. It wraps <cctype> functionality. Ctype gets used by 594 * streams for many I/O operations. 595 * 596 * This template provides the protected virtual functions the developer 597 * will have to replace in a derived class or specialization to make a 598 * working facet. The public functions that access them are defined in 599 * __ctype_abstract_base, to allow for implementation flexibility. See 600 * ctype<wchar_t> for an example. The functions are documented in 601 * __ctype_abstract_base. 602 * 603 * Note: implementations are provided for all the protected virtual 604 * functions, but will likely not be useful. 605 */ 606 template<typename _CharT> 607 class ctype : public __ctype_abstract_base<_CharT> 608 { 609 public: 610 // Types: 611 typedef _CharT char_type; 612 typedef typename __ctype_abstract_base<_CharT>::mask mask; 613 614 /// The facet id for ctype<char_type> 615 static locale::id id; 616 617 explicit 618 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { } 619 620 protected: 621 virtual 622 ~ctype(); 623 624 virtual bool 625 do_is(mask __m, char_type __c) const; 626 627 virtual const char_type* 628 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const; 629 630 virtual const char_type* 631 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const; 632 633 virtual const char_type* 634 do_scan_not(mask __m, const char_type* __lo, 635 const char_type* __hi) const; 636 637 virtual char_type 638 do_toupper(char_type __c) const; 639 640 virtual const char_type* 641 do_toupper(char_type* __lo, const char_type* __hi) const; 642 643 virtual char_type 644 do_tolower(char_type __c) const; 645 646 virtual const char_type* 647 do_tolower(char_type* __lo, const char_type* __hi) const; 648 649 virtual char_type 650 do_widen(char __c) const; 651 652 virtual const char* 653 do_widen(const char* __lo, const char* __hi, char_type* __dest) const; 654 655 virtual char 656 do_narrow(char_type, char __dfault) const; 657 658 virtual const char_type* 659 do_narrow(const char_type* __lo, const char_type* __hi, 660 char __dfault, char* __dest) const; 661 }; 662 663 template<typename _CharT> 664 locale::id ctype<_CharT>::id; 665 666 // 22.2.1.3 ctype<char> specialization. 667 /** 668 * @brief The ctype<char> specialization. 669 * 670 * This class defines classification and conversion functions for 671 * the char type. It gets used by char streams for many I/O 672 * operations. The char specialization provides a number of 673 * optimizations as well. 674 */ 675 template<> 676 class ctype<char> : public locale::facet, public ctype_base 677 { 678 public: 679 // Types: 680 /// Typedef for the template parameter char. 681 typedef char char_type; 682 683 protected: 684 // Data Members: 685 __c_locale _M_c_locale_ctype; 686 bool _M_del; 687 __to_type _M_toupper; 688 __to_type _M_tolower; 689 const mask* _M_table; 690 mutable char _M_widen_ok; 691 mutable char _M_widen[1 + static_cast<unsigned char>(-1)]; 692 mutable char _M_narrow[1 + static_cast<unsigned char>(-1)]; 693 mutable char _M_narrow_ok; // 0 uninitialized, 1 init, 694 // 2 memcpy can't be used 695 696 public: 697 /// The facet id for ctype<char> 698 static locale::id id; 699 /// The size of the mask table. It is SCHAR_MAX + 1. 700 static const size_t table_size = 1 + static_cast<unsigned char>(-1); 701 702 /** 703 * @brief Constructor performs initialization. 704 * 705 * This is the constructor provided by the standard. 706 * 707 * @param table If non-zero, table is used as the per-char mask. 708 * Else classic_table() is used. 709 * @param del If true, passes ownership of table to this facet. 710 * @param refs Passed to the base facet class. 711 */ 712 explicit 713 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0); 714 715 /** 716 * @brief Constructor performs static initialization. 717 * 718 * This constructor is used to construct the initial C locale facet. 719 * 720 * @param cloc Handle to C locale data. 721 * @param table If non-zero, table is used as the per-char mask. 722 * @param del If true, passes ownership of table to this facet. 723 * @param refs Passed to the base facet class. 724 */ 725 explicit 726 ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false, 727 size_t __refs = 0); 728 729 /** 730 * @brief Test char classification. 731 * 732 * This function compares the mask table[c] to @a m. 733 * 734 * @param c The char to compare the mask of. 735 * @param m The mask to compare against. 736 * @return True if m & table[c] is true, false otherwise. 737 */ 738 inline bool 739 is(mask __m, char __c) const; 740 741 /** 742 * @brief Return a mask array. 743 * 744 * This function finds the mask for each char in the range [lo, hi) and 745 * successively writes it to vec. vec must have as many elements as 746 * the char array. 747 * 748 * @param lo Pointer to start of range. 749 * @param hi Pointer to end of range. 750 * @param vec Pointer to an array of mask storage. 751 * @return @a hi. 752 */ 753 inline const char* 754 is(const char* __lo, const char* __hi, mask* __vec) const; 755 756 /** 757 * @brief Find char matching a mask 758 * 759 * This function searches for and returns the first char in [lo,hi) for 760 * which is(m,char) is true. 761 * 762 * @param m The mask to compare against. 763 * @param lo Pointer to start of range. 764 * @param hi Pointer to end of range. 765 * @return Pointer to a matching char if found, else @a hi. 766 */ 767 inline const char* 768 scan_is(mask __m, const char* __lo, const char* __hi) const; 769 770 /** 771 * @brief Find char not matching a mask 772 * 773 * This function searches for and returns a pointer to the first char 774 * in [lo,hi) for which is(m,char) is false. 775 * 776 * @param m The mask to compare against. 777 * @param lo Pointer to start of range. 778 * @param hi Pointer to end of range. 779 * @return Pointer to a non-matching char if found, else @a hi. 780 */ 781 inline const char* 782 scan_not(mask __m, const char* __lo, const char* __hi) const; 783 784 /** 785 * @brief Convert to uppercase. 786 * 787 * This function converts the char argument to uppercase if possible. 788 * If not possible (for example, '2'), returns the argument. 789 * 790 * toupper() acts as if it returns ctype<char>::do_toupper(c). 791 * do_toupper() must always return the same result for the same input. 792 * 793 * @param c The char to convert. 794 * @return The uppercase char if convertible, else @a c. 795 */ 796 char_type 797 toupper(char_type __c) const 798 { return this->do_toupper(__c); } 799 800 /** 801 * @brief Convert array to uppercase. 802 * 803 * This function converts each char in the range [lo,hi) to uppercase 804 * if possible. Other chars remain untouched. 805 * 806 * toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi). 807 * do_toupper() must always return the same result for the same input. 808 * 809 * @param lo Pointer to first char in range. 810 * @param hi Pointer to end of range. 811 * @return @a hi. 812 */ 813 const char_type* 814 toupper(char_type *__lo, const char_type* __hi) const 815 { return this->do_toupper(__lo, __hi); } 816 817 /** 818 * @brief Convert to lowercase. 819 * 820 * This function converts the char argument to lowercase if possible. 821 * If not possible (for example, '2'), returns the argument. 822 * 823 * tolower() acts as if it returns ctype<char>::do_tolower(c). 824 * do_tolower() must always return the same result for the same input. 825 * 826 * @param c The char to convert. 827 * @return The lowercase char if convertible, else @a c. 828 */ 829 char_type 830 tolower(char_type __c) const 831 { return this->do_tolower(__c); } 832 833 /** 834 * @brief Convert array to lowercase. 835 * 836 * This function converts each char in the range [lo,hi) to lowercase 837 * if possible. Other chars remain untouched. 838 * 839 * tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi). 840 * do_tolower() must always return the same result for the same input. 841 * 842 * @param lo Pointer to first char in range. 843 * @param hi Pointer to end of range. 844 * @return @a hi. 845 */ 846 const char_type* 847 tolower(char_type* __lo, const char_type* __hi) const 848 { return this->do_tolower(__lo, __hi); } 849 850 /** 851 * @brief Widen char 852 * 853 * This function converts the char to char_type using the simplest 854 * reasonable transformation. For an underived ctype<char> facet, the 855 * argument will be returned unchanged. 856 * 857 * This function works as if it returns ctype<char>::do_widen(c). 858 * do_widen() must always return the same result for the same input. 859 * 860 * Note: this is not what you want for codepage conversions. See 861 * codecvt for that. 862 * 863 * @param c The char to convert. 864 * @return The converted character. 865 */ 866 char_type 867 widen(char __c) const 868 { 869 if (_M_widen_ok) 870 return _M_widen[static_cast<unsigned char>(__c)]; 871 this->_M_widen_init(); 872 return this->do_widen(__c); 873 } 874 875 /** 876 * @brief Widen char array 877 * 878 * This function converts each char in the input to char using the 879 * simplest reasonable transformation. For an underived ctype<char> 880 * facet, the argument will be copied unchanged. 881 * 882 * This function works as if it returns ctype<char>::do_widen(c). 883 * do_widen() must always return the same result for the same input. 884 * 885 * Note: this is not what you want for codepage conversions. See 886 * codecvt for that. 887 * 888 * @param lo Pointer to first char in range. 889 * @param hi Pointer to end of range. 890 * @param to Pointer to the destination array. 891 * @return @a hi. 892 */ 893 const char* 894 widen(const char* __lo, const char* __hi, char_type* __to) const 895 { 896 if (_M_widen_ok == 1) 897 { 898 memcpy(__to, __lo, __hi - __lo); 899 return __hi; 900 } 901 if (!_M_widen_ok) 902 _M_widen_init(); 903 return this->do_widen(__lo, __hi, __to); 904 } 905 906 /** 907 * @brief Narrow char 908 * 909 * This function converts the char to char using the simplest 910 * reasonable transformation. If the conversion fails, dfault is 911 * returned instead. For an underived ctype<char> facet, @a c 912 * will be returned unchanged. 913 * 914 * This function works as if it returns ctype<char>::do_narrow(c). 915 * do_narrow() must always return the same result for the same input. 916 * 917 * Note: this is not what you want for codepage conversions. See 918 * codecvt for that. 919 * 920 * @param c The char to convert. 921 * @param dfault Char to return if conversion fails. 922 * @return The converted character. 923 */ 924 char 925 narrow(char_type __c, char __dfault) const 926 { 927 if (_M_narrow[static_cast<unsigned char>(__c)]) 928 return _M_narrow[static_cast<unsigned char>(__c)]; 929 const char __t = do_narrow(__c, __dfault); 930 if (__t != __dfault) 931 _M_narrow[static_cast<unsigned char>(__c)] = __t; 932 return __t; 933 } 934 935 /** 936 * @brief Narrow char array 937 * 938 * This function converts each char in the input to char using the 939 * simplest reasonable transformation and writes the results to the 940 * destination array. For any char in the input that cannot be 941 * converted, @a dfault is used instead. For an underived ctype<char> 942 * facet, the argument will be copied unchanged. 943 * 944 * This function works as if it returns ctype<char>::do_narrow(lo, hi, 945 * dfault, to). do_narrow() must always return the same result for the 946 * same input. 947 * 948 * Note: this is not what you want for codepage conversions. See 949 * codecvt for that. 950 * 951 * @param lo Pointer to start of range. 952 * @param hi Pointer to end of range. 953 * @param dfault Char to use if conversion fails. 954 * @param to Pointer to the destination array. 955 * @return @a hi. 956 */ 957 const char_type* 958 narrow(const char_type* __lo, const char_type* __hi, 959 char __dfault, char *__to) const 960 { 961 if (__builtin_expect(_M_narrow_ok == 1, true)) 962 { 963 memcpy(__to, __lo, __hi - __lo); 964 return __hi; 965 } 966 if (!_M_narrow_ok) 967 _M_narrow_init(); 968 return this->do_narrow(__lo, __hi, __dfault, __to); 969 } 970 971 protected: 972 /// Returns a pointer to the mask table provided to the constructor, or 973 /// the default from classic_table() if none was provided. 974 const mask* 975 table() const throw() 976 { return _M_table; } 977 978 /// Returns a pointer to the C locale mask table. 979 static const mask* 980 classic_table() throw(); 981 982 /** 983 * @brief Destructor. 984 * 985 * This function deletes table() if @a del was true in the 986 * constructor. 987 */ 988 virtual 989 ~ctype(); 990 991 /** 992 * @brief Convert to uppercase. 993 * 994 * This virtual function converts the char argument to uppercase if 995 * possible. If not possible (for example, '2'), returns the argument. 996 * 997 * do_toupper() is a hook for a derived facet to change the behavior of 998 * uppercasing. do_toupper() must always return the same result for 999 * the same input. 1000 * 1001 * @param c The char to convert. 1002 * @return The uppercase char if convertible, else @a c. 1003 */ 1004 virtual char_type 1005 do_toupper(char_type) const; 1006 1007 /** 1008 * @brief Convert array to uppercase. 1009 * 1010 * This virtual function converts each char in the range [lo,hi) to 1011 * uppercase if possible. Other chars remain untouched. 1012 * 1013 * do_toupper() is a hook for a derived facet to change the behavior of 1014 * uppercasing. do_toupper() must always return the same result for 1015 * the same input. 1016 * 1017 * @param lo Pointer to start of range. 1018 * @param hi Pointer to end of range. 1019 * @return @a hi. 1020 */ 1021 virtual const char_type* 1022 do_toupper(char_type* __lo, const char_type* __hi) const; 1023 1024 /** 1025 * @brief Convert to lowercase. 1026 * 1027 * This virtual function converts the char argument to lowercase if 1028 * possible. If not possible (for example, '2'), returns the argument. 1029 * 1030 * do_tolower() is a hook for a derived facet to change the behavior of 1031 * lowercasing. do_tolower() must always return the same result for 1032 * the same input. 1033 * 1034 * @param c The char to convert. 1035 * @return The lowercase char if convertible, else @a c. 1036 */ 1037 virtual char_type 1038 do_tolower(char_type) const; 1039 1040 /** 1041 * @brief Convert array to lowercase. 1042 * 1043 * This virtual function converts each char in the range [lo,hi) to 1044 * lowercase if possible. Other chars remain untouched. 1045 * 1046 * do_tolower() is a hook for a derived facet to change the behavior of 1047 * lowercasing. do_tolower() must always return the same result for 1048 * the same input. 1049 * 1050 * @param lo Pointer to first char in range. 1051 * @param hi Pointer to end of range. 1052 * @return @a hi. 1053 */ 1054 virtual const char_type* 1055 do_tolower(char_type* __lo, const char_type* __hi) const; 1056 1057 /** 1058 * @brief Widen char 1059 * 1060 * This virtual function converts the char to char using the simplest 1061 * reasonable transformation. For an underived ctype<char> facet, the 1062 * argument will be returned unchanged. 1063 * 1064 * do_widen() is a hook for a derived facet to change the behavior of 1065 * widening. do_widen() must always return the same result for the 1066 * same input. 1067 * 1068 * Note: this is not what you want for codepage conversions. See 1069 * codecvt for that. 1070 * 1071 * @param c The char to convert. 1072 * @return The converted character. 1073 */ 1074 virtual char_type 1075 do_widen(char __c) const 1076 { return __c; } 1077 1078 /** 1079 * @brief Widen char array 1080 * 1081 * This function converts each char in the range [lo,hi) to char using 1082 * the simplest reasonable transformation. For an underived 1083 * ctype<char> facet, the argument will be copied unchanged. 1084 * 1085 * do_widen() is a hook for a derived facet to change the behavior of 1086 * widening. do_widen() must always return the same result for the 1087 * same input. 1088 * 1089 * Note: this is not what you want for codepage conversions. See 1090 * codecvt for that. 1091 * 1092 * @param lo Pointer to start of range. 1093 * @param hi Pointer to end of range. 1094 * @param to Pointer to the destination array. 1095 * @return @a hi. 1096 */ 1097 virtual const char* 1098 do_widen(const char* __lo, const char* __hi, char_type* __dest) const 1099 { 1100 memcpy(__dest, __lo, __hi - __lo); 1101 return __hi; 1102 } 1103 1104 /** 1105 * @brief Narrow char 1106 * 1107 * This virtual function converts the char to char using the simplest 1108 * reasonable transformation. If the conversion fails, dfault is 1109 * returned instead. For an underived ctype<char> facet, @a c will be 1110 * returned unchanged. 1111 * 1112 * do_narrow() is a hook for a derived facet to change the behavior of 1113 * narrowing. do_narrow() must always return the same result for the 1114 * same input. 1115 * 1116 * Note: this is not what you want for codepage conversions. See 1117 * codecvt for that. 1118 * 1119 * @param c The char to convert. 1120 * @param dfault Char to return if conversion fails. 1121 * @return The converted char. 1122 */ 1123 virtual char 1124 do_narrow(char_type __c, char) const 1125 { return __c; } 1126 1127 /** 1128 * @brief Narrow char array to char array 1129 * 1130 * This virtual function converts each char in the range [lo,hi) to 1131 * char using the simplest reasonable transformation and writes the 1132 * results to the destination array. For any char in the input that 1133 * cannot be converted, @a dfault is used instead. For an underived 1134 * ctype<char> facet, the argument will be copied unchanged. 1135 * 1136 * do_narrow() is a hook for a derived facet to change the behavior of 1137 * narrowing. do_narrow() must always return the same result for the 1138 * same input. 1139 * 1140 * Note: this is not what you want for codepage conversions. See 1141 * codecvt for that. 1142 * 1143 * @param lo Pointer to start of range. 1144 * @param hi Pointer to end of range. 1145 * @param dfault Char to use if conversion fails. 1146 * @param to Pointer to the destination array. 1147 * @return @a hi. 1148 */ 1149 virtual const char_type* 1150 do_narrow(const char_type* __lo, const char_type* __hi, 1151 char, char* __dest) const 1152 { 1153 memcpy(__dest, __lo, __hi - __lo); 1154 return __hi; 1155 } 1156 1157 private: 1158 1159 void _M_widen_init() const 1160 { 1161 char __tmp[sizeof(_M_widen)]; 1162 for (size_t __i = 0; __i < sizeof(_M_widen); ++__i) 1163 __tmp[__i] = __i; 1164 do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen); 1165 1166 _M_widen_ok = 1; 1167 // Set _M_widen_ok to 2 if memcpy can't be used. 1168 if (memcmp(__tmp, _M_widen, sizeof(_M_widen))) 1169 _M_widen_ok = 2; 1170 } 1171 1172 // Fill in the narrowing cache and flag whether all values are 1173 // valid or not. _M_narrow_ok is set to 2 if memcpy can't 1174 // be used. 1175 void _M_narrow_init() const 1176 { 1177 char __tmp[sizeof(_M_narrow)]; 1178 for (size_t __i = 0; __i < sizeof(_M_narrow); ++__i) 1179 __tmp[__i] = __i; 1180 do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow); 1181 1182 _M_narrow_ok = 1; 1183 if (memcmp(__tmp, _M_narrow, sizeof(_M_narrow))) 1184 _M_narrow_ok = 2; 1185 else 1186 { 1187 // Deal with the special case of zero: renarrow with a 1188 // different default and compare. 1189 char __c; 1190 do_narrow(__tmp, __tmp + 1, 1, &__c); 1191 if (__c == 1) 1192 _M_narrow_ok = 2; 1193 } 1194 } 1195 }; 1196 1197 template<> 1198 const ctype<char>& 1199 use_facet<ctype<char> >(const locale& __loc); 1200 1201#ifdef _GLIBCXX_USE_WCHAR_T 1202 // 22.2.1.3 ctype<wchar_t> specialization 1203 /** 1204 * @brief The ctype<wchar_t> specialization. 1205 * 1206 * This class defines classification and conversion functions for the 1207 * wchar_t type. It gets used by wchar_t streams for many I/O operations. 1208 * The wchar_t specialization provides a number of optimizations as well. 1209 * 1210 * ctype<wchar_t> inherits its public methods from 1211 * __ctype_abstract_base<wchar_t>. 1212 */ 1213 template<> 1214 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t> 1215 { 1216 public: 1217 // Types: 1218 /// Typedef for the template parameter wchar_t. 1219 typedef wchar_t char_type; 1220 typedef wctype_t __wmask_type; 1221 1222 protected: 1223 __c_locale _M_c_locale_ctype; 1224 1225 // Pre-computed narrowed and widened chars. 1226 bool _M_narrow_ok; 1227 char _M_narrow[128]; 1228 wint_t _M_widen[1 + static_cast<unsigned char>(-1)]; 1229 1230 // Pre-computed elements for do_is. 1231 mask _M_bit[16]; 1232 __wmask_type _M_wmask[16]; 1233 1234 public: 1235 // Data Members: 1236 /// The facet id for ctype<wchar_t> 1237 static locale::id id; 1238 1239 /** 1240 * @brief Constructor performs initialization. 1241 * 1242 * This is the constructor provided by the standard. 1243 * 1244 * @param refs Passed to the base facet class. 1245 */ 1246 explicit 1247 ctype(size_t __refs = 0); 1248 1249 /** 1250 * @brief Constructor performs static initialization. 1251 * 1252 * This constructor is used to construct the initial C locale facet. 1253 * 1254 * @param cloc Handle to C locale data. 1255 * @param refs Passed to the base facet class. 1256 */ 1257 explicit 1258 ctype(__c_locale __cloc, size_t __refs = 0); 1259 1260 protected: 1261 __wmask_type 1262 _M_convert_to_wmask(const mask __m) const; 1263 1264 /// Destructor 1265 virtual 1266 ~ctype(); 1267 1268 /** 1269 * @brief Test wchar_t classification. 1270 * 1271 * This function finds a mask M for @a c and compares it to mask @a m. 1272 * 1273 * do_is() is a hook for a derived facet to change the behavior of 1274 * classifying. do_is() must always return the same result for the 1275 * same input. 1276 * 1277 * @param c The wchar_t to find the mask of. 1278 * @param m The mask to compare against. 1279 * @return (M & m) != 0. 1280 */ 1281 virtual bool 1282 do_is(mask __m, char_type __c) const; 1283 1284 /** 1285 * @brief Return a mask array. 1286 * 1287 * This function finds the mask for each wchar_t in the range [lo,hi) 1288 * and successively writes it to vec. vec must have as many elements 1289 * as the input. 1290 * 1291 * do_is() is a hook for a derived facet to change the behavior of 1292 * classifying. do_is() must always return the same result for the 1293 * same input. 1294 * 1295 * @param lo Pointer to start of range. 1296 * @param hi Pointer to end of range. 1297 * @param vec Pointer to an array of mask storage. 1298 * @return @a hi. 1299 */ 1300 virtual const char_type* 1301 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const; 1302 1303 /** 1304 * @brief Find wchar_t matching mask 1305 * 1306 * This function searches for and returns the first wchar_t c in 1307 * [lo,hi) for which is(m,c) is true. 1308 * 1309 * do_scan_is() is a hook for a derived facet to change the behavior of 1310 * match searching. do_is() must always return the same result for the 1311 * same input. 1312 * 1313 * @param m The mask to compare against. 1314 * @param lo Pointer to start of range. 1315 * @param hi Pointer to end of range. 1316 * @return Pointer to a matching wchar_t if found, else @a hi. 1317 */ 1318 virtual const char_type* 1319 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const; 1320 1321 /** 1322 * @brief Find wchar_t not matching mask 1323 * 1324 * This function searches for and returns a pointer to the first 1325 * wchar_t c of [lo,hi) for which is(m,c) is false. 1326 * 1327 * do_scan_is() is a hook for a derived facet to change the behavior of 1328 * match searching. do_is() must always return the same result for the 1329 * same input. 1330 * 1331 * @param m The mask to compare against. 1332 * @param lo Pointer to start of range. 1333 * @param hi Pointer to end of range. 1334 * @return Pointer to a non-matching wchar_t if found, else @a hi. 1335 */ 1336 virtual const char_type* 1337 do_scan_not(mask __m, const char_type* __lo, 1338 const char_type* __hi) const; 1339 1340 /** 1341 * @brief Convert to uppercase. 1342 * 1343 * This virtual function converts the wchar_t argument to uppercase if 1344 * possible. If not possible (for example, '2'), returns the argument. 1345 * 1346 * do_toupper() is a hook for a derived facet to change the behavior of 1347 * uppercasing. do_toupper() must always return the same result for 1348 * the same input. 1349 * 1350 * @param c The wchar_t to convert. 1351 * @return The uppercase wchar_t if convertible, else @a c. 1352 */ 1353 virtual char_type 1354 do_toupper(char_type) const; 1355 1356 /** 1357 * @brief Convert array to uppercase. 1358 * 1359 * This virtual function converts each wchar_t in the range [lo,hi) to 1360 * uppercase if possible. Other elements remain untouched. 1361 * 1362 * do_toupper() is a hook for a derived facet to change the behavior of 1363 * uppercasing. do_toupper() must always return the same result for 1364 * the same input. 1365 * 1366 * @param lo Pointer to start of range. 1367 * @param hi Pointer to end of range. 1368 * @return @a hi. 1369 */ 1370 virtual const char_type* 1371 do_toupper(char_type* __lo, const char_type* __hi) const; 1372 1373 /** 1374 * @brief Convert to lowercase. 1375 * 1376 * This virtual function converts the argument to lowercase if 1377 * possible. If not possible (for example, '2'), returns the argument. 1378 * 1379 * do_tolower() is a hook for a derived facet to change the behavior of 1380 * lowercasing. do_tolower() must always return the same result for 1381 * the same input. 1382 * 1383 * @param c The wchar_t to convert. 1384 * @return The lowercase wchar_t if convertible, else @a c. 1385 */ 1386 virtual char_type 1387 do_tolower(char_type) const; 1388 1389 /** 1390 * @brief Convert array to lowercase. 1391 * 1392 * This virtual function converts each wchar_t in the range [lo,hi) to 1393 * lowercase if possible. Other elements remain untouched. 1394 * 1395 * do_tolower() is a hook for a derived facet to change the behavior of 1396 * lowercasing. do_tolower() must always return the same result for 1397 * the same input. 1398 * 1399 * @param lo Pointer to start of range. 1400 * @param hi Pointer to end of range. 1401 * @return @a hi. 1402 */ 1403 virtual const char_type* 1404 do_tolower(char_type* __lo, const char_type* __hi) const; 1405 1406 /** 1407 * @brief Widen char to wchar_t 1408 * 1409 * This virtual function converts the char to wchar_t using the 1410 * simplest reasonable transformation. For an underived ctype<wchar_t> 1411 * facet, the argument will be cast to wchar_t. 1412 * 1413 * do_widen() is a hook for a derived facet to change the behavior of 1414 * widening. do_widen() must always return the same result for the 1415 * same input. 1416 * 1417 * Note: this is not what you want for codepage conversions. See 1418 * codecvt for that. 1419 * 1420 * @param c The char to convert. 1421 * @return The converted wchar_t. 1422 */ 1423 virtual char_type 1424 do_widen(char) const; 1425 1426 /** 1427 * @brief Widen char array to wchar_t array 1428 * 1429 * This function converts each char in the input to wchar_t using the 1430 * simplest reasonable transformation. For an underived ctype<wchar_t> 1431 * facet, the argument will be copied, casting each element to wchar_t. 1432 * 1433 * do_widen() is a hook for a derived facet to change the behavior of 1434 * widening. do_widen() must always return the same result for the 1435 * same input. 1436 * 1437 * Note: this is not what you want for codepage conversions. See 1438 * codecvt for that. 1439 * 1440 * @param lo Pointer to start range. 1441 * @param hi Pointer to end of range. 1442 * @param to Pointer to the destination array. 1443 * @return @a hi. 1444 */ 1445 virtual const char* 1446 do_widen(const char* __lo, const char* __hi, char_type* __dest) const; 1447 1448 /** 1449 * @brief Narrow wchar_t to char 1450 * 1451 * This virtual function converts the argument to char using 1452 * the simplest reasonable transformation. If the conversion 1453 * fails, dfault is returned instead. For an underived 1454 * ctype<wchar_t> facet, @a c will be cast to char and 1455 * returned. 1456 * 1457 * do_narrow() is a hook for a derived facet to change the 1458 * behavior of narrowing. do_narrow() must always return the 1459 * same result for the same input. 1460 * 1461 * Note: this is not what you want for codepage conversions. See 1462 * codecvt for that. 1463 * 1464 * @param c The wchar_t to convert. 1465 * @param dfault Char to return if conversion fails. 1466 * @return The converted char. 1467 */ 1468 virtual char 1469 do_narrow(char_type, char __dfault) const; 1470 1471 /** 1472 * @brief Narrow wchar_t array to char array 1473 * 1474 * This virtual function converts each wchar_t in the range [lo,hi) to 1475 * char using the simplest reasonable transformation and writes the 1476 * results to the destination array. For any wchar_t in the input that 1477 * cannot be converted, @a dfault is used instead. For an underived 1478 * ctype<wchar_t> facet, the argument will be copied, casting each 1479 * element to char. 1480 * 1481 * do_narrow() is a hook for a derived facet to change the behavior of 1482 * narrowing. do_narrow() must always return the same result for the 1483 * same input. 1484 * 1485 * Note: this is not what you want for codepage conversions. See 1486 * codecvt for that. 1487 * 1488 * @param lo Pointer to start of range. 1489 * @param hi Pointer to end of range. 1490 * @param dfault Char to use if conversion fails. 1491 * @param to Pointer to the destination array. 1492 * @return @a hi. 1493 */ 1494 virtual const char_type* 1495 do_narrow(const char_type* __lo, const char_type* __hi, 1496 char __dfault, char* __dest) const; 1497 1498 // For use at construction time only. 1499 void 1500 _M_initialize_ctype(); 1501 }; 1502 1503 template<> 1504 const ctype<wchar_t>& 1505 use_facet<ctype<wchar_t> >(const locale& __loc); 1506#endif //_GLIBCXX_USE_WCHAR_T 1507 1508 /// @brief class ctype_byname [22.2.1.2]. 1509 template<typename _CharT> 1510 class ctype_byname : public ctype<_CharT> 1511 { 1512 public: 1513 typedef _CharT char_type; 1514 1515 explicit 1516 ctype_byname(const char* __s, size_t __refs = 0); 1517 1518 protected: 1519 virtual 1520 ~ctype_byname() { }; 1521 }; 1522 1523 /// 22.2.1.4 Class ctype_byname specializations. 1524 template<> 1525 ctype_byname<char>::ctype_byname(const char*, size_t refs); 1526 1527 template<> 1528 ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs); 1529 1530_GLIBCXX_END_NAMESPACE 1531 1532// Include host and configuration specific ctype inlines. 1533#include <bits/ctype_inline.h> 1534 1535// 22.2.1.5 Template class codecvt 1536#include <bits/codecvt.h> 1537 1538_GLIBCXX_BEGIN_NAMESPACE(std) 1539 1540 // 22.2.2 The numeric category. 1541 class __num_base 1542 { 1543 public: 1544 // NB: Code depends on the order of _S_atoms_out elements. 1545 // Below are the indices into _S_atoms_out. 1546 enum 1547 { 1548 _S_ominus, 1549 _S_oplus, 1550 _S_ox, 1551 _S_oX, 1552 _S_odigits, 1553 _S_odigits_end = _S_odigits + 16, 1554 _S_oudigits = _S_odigits_end, 1555 _S_oudigits_end = _S_oudigits + 16, 1556 _S_oe = _S_odigits + 14, // For scientific notation, 'e' 1557 _S_oE = _S_oudigits + 14, // For scientific notation, 'E' 1558 _S_oend = _S_oudigits_end 1559 }; 1560 1561 // A list of valid numeric literals for output. This array 1562 // contains chars that will be passed through the current locale's 1563 // ctype<_CharT>.widen() and then used to render numbers. 1564 // For the standard "C" locale, this is 1565 // "-+xX0123456789abcdef0123456789ABCDEF". 1566 static const char* _S_atoms_out; 1567 1568 // String literal of acceptable (narrow) input, for num_get. 1569 // "-+xX0123456789abcdefABCDEF" 1570 static const char* _S_atoms_in; 1571 1572 enum 1573 { 1574 _S_iminus, 1575 _S_iplus, 1576 _S_ix, 1577 _S_iX, 1578 _S_izero, 1579 _S_ie = _S_izero + 14, 1580 _S_iE = _S_izero + 20, 1581 _S_iend = 26 1582 }; 1583 1584 // num_put 1585 // Construct and return valid scanf format for floating point types. 1586 static void 1587 _S_format_float(const ios_base& __io, char* __fptr, char __mod); 1588 }; 1589 1590 template<typename _CharT> 1591 struct __numpunct_cache : public locale::facet 1592 { 1593 const char* _M_grouping; 1594 size_t _M_grouping_size; 1595 bool _M_use_grouping; 1596 const _CharT* _M_truename; 1597 size_t _M_truename_size; 1598 const _CharT* _M_falsename; 1599 size_t _M_falsename_size; 1600 _CharT _M_decimal_point; 1601 _CharT _M_thousands_sep; 1602 1603 // A list of valid numeric literals for output: in the standard 1604 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF". 1605 // This array contains the chars after having been passed 1606 // through the current locale's ctype<_CharT>.widen(). 1607 _CharT _M_atoms_out[__num_base::_S_oend]; 1608 1609 // A list of valid numeric literals for input: in the standard 1610 // "C" locale, this is "-+xX0123456789abcdefABCDEF" 1611 // This array contains the chars after having been passed 1612 // through the current locale's ctype<_CharT>.widen(). 1613 _CharT _M_atoms_in[__num_base::_S_iend]; 1614 1615 bool _M_allocated; 1616 1617 __numpunct_cache(size_t __refs = 0) : facet(__refs), 1618 _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false), 1619 _M_truename(NULL), _M_truename_size(0), _M_falsename(NULL), 1620 _M_falsename_size(0), _M_decimal_point(_CharT()), 1621 _M_thousands_sep(_CharT()), _M_allocated(false) 1622 { } 1623 1624 ~__numpunct_cache(); 1625 1626 void 1627 _M_cache(const locale& __loc); 1628 1629 private: 1630 __numpunct_cache& 1631 operator=(const __numpunct_cache&); 1632 1633 explicit 1634 __numpunct_cache(const __numpunct_cache&); 1635 }; 1636 1637 template<typename _CharT> 1638 __numpunct_cache<_CharT>::~__numpunct_cache() 1639 { 1640 if (_M_allocated) 1641 { 1642 delete [] _M_grouping; 1643 delete [] _M_truename; 1644 delete [] _M_falsename; 1645 } 1646 } 1647 1648 /** 1649 * @brief Numpunct facet. 1650 * 1651 * This facet stores several pieces of information related to printing and 1652 * scanning numbers, such as the decimal point character. It takes a 1653 * template parameter specifying the char type. The numpunct facet is 1654 * used by streams for many I/O operations involving numbers. 1655 * 1656 * The numpunct template uses protected virtual functions to provide the 1657 * actual results. The public accessors forward the call to the virtual 1658 * functions. These virtual functions are hooks for developers to 1659 * implement the behavior they require from a numpunct facet. 1660 */ 1661 template<typename _CharT> 1662 class numpunct : public locale::facet 1663 { 1664 public: 1665 // Types: 1666 //@{ 1667 /// Public typedefs 1668 typedef _CharT char_type; 1669 typedef basic_string<_CharT> string_type; 1670 //@} 1671 typedef __numpunct_cache<_CharT> __cache_type; 1672 1673 protected: 1674 __cache_type* _M_data; 1675 1676 public: 1677 /// Numpunct facet id. 1678 static locale::id id; 1679 1680 /** 1681 * @brief Numpunct constructor. 1682 * 1683 * @param refs Refcount to pass to the base class. 1684 */ 1685 explicit 1686 numpunct(size_t __refs = 0) : facet(__refs), _M_data(NULL) 1687 { _M_initialize_numpunct(); } 1688 1689 /** 1690 * @brief Internal constructor. Not for general use. 1691 * 1692 * This is a constructor for use by the library itself to set up the 1693 * predefined locale facets. 1694 * 1695 * @param cache __numpunct_cache object. 1696 * @param refs Refcount to pass to the base class. 1697 */ 1698 explicit 1699 numpunct(__cache_type* __cache, size_t __refs = 0) 1700 : facet(__refs), _M_data(__cache) 1701 { _M_initialize_numpunct(); } 1702 1703 /** 1704 * @brief Internal constructor. Not for general use. 1705 * 1706 * This is a constructor for use by the library itself to set up new 1707 * locales. 1708 * 1709 * @param cloc The "C" locale. 1710 * @param refs Refcount to pass to the base class. 1711 */ 1712 explicit 1713 numpunct(__c_locale __cloc, size_t __refs = 0) 1714 : facet(__refs), _M_data(NULL) 1715 { _M_initialize_numpunct(__cloc); } 1716 1717 /** 1718 * @brief Return decimal point character. 1719 * 1720 * This function returns a char_type to use as a decimal point. It 1721 * does so by returning returning 1722 * numpunct<char_type>::do_decimal_point(). 1723 * 1724 * @return @a char_type representing a decimal point. 1725 */ 1726 char_type 1727 decimal_point() const 1728 { return this->do_decimal_point(); } 1729 1730 /** 1731 * @brief Return thousands separator character. 1732 * 1733 * This function returns a char_type to use as a thousands 1734 * separator. It does so by returning returning 1735 * numpunct<char_type>::do_thousands_sep(). 1736 * 1737 * @return char_type representing a thousands separator. 1738 */ 1739 char_type 1740 thousands_sep() const 1741 { return this->do_thousands_sep(); } 1742 1743 /** 1744 * @brief Return grouping specification. 1745 * 1746 * This function returns a string representing groupings for the 1747 * integer part of a number. Groupings indicate where thousands 1748 * separators should be inserted in the integer part of a number. 1749 * 1750 * Each char in the return string is interpret as an integer 1751 * rather than a character. These numbers represent the number 1752 * of digits in a group. The first char in the string 1753 * represents the number of digits in the least significant 1754 * group. If a char is negative, it indicates an unlimited 1755 * number of digits for the group. If more chars from the 1756 * string are required to group a number, the last char is used 1757 * repeatedly. 1758 * 1759 * For example, if the grouping() returns "\003\002" and is 1760 * applied to the number 123456789, this corresponds to 1761 * 12,34,56,789. Note that if the string was "32", this would 1762 * put more than 50 digits into the least significant group if 1763 * the character set is ASCII. 1764 * 1765 * The string is returned by calling 1766 * numpunct<char_type>::do_grouping(). 1767 * 1768 * @return string representing grouping specification. 1769 */ 1770 string 1771 grouping() const 1772 { return this->do_grouping(); } 1773 1774 /** 1775 * @brief Return string representation of bool true. 1776 * 1777 * This function returns a string_type containing the text 1778 * representation for true bool variables. It does so by calling 1779 * numpunct<char_type>::do_truename(). 1780 * 1781 * @return string_type representing printed form of true. 1782 */ 1783 string_type 1784 truename() const 1785 { return this->do_truename(); } 1786 1787 /** 1788 * @brief Return string representation of bool false. 1789 * 1790 * This function returns a string_type containing the text 1791 * representation for false bool variables. It does so by calling 1792 * numpunct<char_type>::do_falsename(). 1793 * 1794 * @return string_type representing printed form of false. 1795 */ 1796 string_type 1797 falsename() const 1798 { return this->do_falsename(); } 1799 1800 protected: 1801 /// Destructor. 1802 virtual 1803 ~numpunct(); 1804 1805 /** 1806 * @brief Return decimal point character. 1807 * 1808 * Returns a char_type to use as a decimal point. This function is a 1809 * hook for derived classes to change the value returned. 1810 * 1811 * @return @a char_type representing a decimal point. 1812 */ 1813 virtual char_type 1814 do_decimal_point() const 1815 { return _M_data->_M_decimal_point; } 1816 1817 /** 1818 * @brief Return thousands separator character. 1819 * 1820 * Returns a char_type to use as a thousands separator. This function 1821 * is a hook for derived classes to change the value returned. 1822 * 1823 * @return @a char_type representing a thousands separator. 1824 */ 1825 virtual char_type 1826 do_thousands_sep() const 1827 { return _M_data->_M_thousands_sep; } 1828 1829 /** 1830 * @brief Return grouping specification. 1831 * 1832 * Returns a string representing groupings for the integer part of a 1833 * number. This function is a hook for derived classes to change the 1834 * value returned. @see grouping() for details. 1835 * 1836 * @return String representing grouping specification. 1837 */ 1838 virtual string 1839 do_grouping() const 1840 { return _M_data->_M_grouping; } 1841 1842 /** 1843 * @brief Return string representation of bool true. 1844 * 1845 * Returns a string_type containing the text representation for true 1846 * bool variables. This function is a hook for derived classes to 1847 * change the value returned. 1848 * 1849 * @return string_type representing printed form of true. 1850 */ 1851 virtual string_type 1852 do_truename() const 1853 { return _M_data->_M_truename; } 1854 1855 /** 1856 * @brief Return string representation of bool false. 1857 * 1858 * Returns a string_type containing the text representation for false 1859 * bool variables. This function is a hook for derived classes to 1860 * change the value returned. 1861 * 1862 * @return string_type representing printed form of false. 1863 */ 1864 virtual string_type 1865 do_falsename() const 1866 { return _M_data->_M_falsename; } 1867 1868 // For use at construction time only. 1869 void 1870 _M_initialize_numpunct(__c_locale __cloc = NULL); 1871 }; 1872 1873 template<typename _CharT> 1874 locale::id numpunct<_CharT>::id; 1875 1876 template<> 1877 numpunct<char>::~numpunct(); 1878 1879 template<> 1880 void 1881 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc); 1882 1883#ifdef _GLIBCXX_USE_WCHAR_T 1884 template<> 1885 numpunct<wchar_t>::~numpunct(); 1886 1887 template<> 1888 void 1889 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc); 1890#endif 1891 1892 /// @brief class numpunct_byname [22.2.3.2]. 1893 template<typename _CharT> 1894 class numpunct_byname : public numpunct<_CharT> 1895 { 1896 public: 1897 typedef _CharT char_type; 1898 typedef basic_string<_CharT> string_type; 1899 1900 explicit 1901 numpunct_byname(const char* __s, size_t __refs = 0) 1902 : numpunct<_CharT>(__refs) 1903 { 1904 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0) 1905 { 1906 __c_locale __tmp; 1907 this->_S_create_c_locale(__tmp, __s); 1908 this->_M_initialize_numpunct(__tmp); 1909 this->_S_destroy_c_locale(__tmp); 1910 } 1911 } 1912 1913 protected: 1914 virtual 1915 ~numpunct_byname() { } 1916 }; 1917 1918_GLIBCXX_BEGIN_LDBL_NAMESPACE 1919 /** 1920 * @brief Facet for parsing number strings. 1921 * 1922 * This facet encapsulates the code to parse and return a number 1923 * from a string. It is used by the istream numeric extraction 1924 * operators. 1925 * 1926 * The num_get template uses protected virtual functions to provide the 1927 * actual results. The public accessors forward the call to the virtual 1928 * functions. These virtual functions are hooks for developers to 1929 * implement the behavior they require from the num_get facet. 1930 */ 1931 template<typename _CharT, typename _InIter> 1932 class num_get : public locale::facet 1933 { 1934 public: 1935 // Types: 1936 //@{ 1937 /// Public typedefs 1938 typedef _CharT char_type; 1939 typedef _InIter iter_type; 1940 //@} 1941 1942 /// Numpunct facet id. 1943 static locale::id id; 1944 1945 /** 1946 * @brief Constructor performs initialization. 1947 * 1948 * This is the constructor provided by the standard. 1949 * 1950 * @param refs Passed to the base facet class. 1951 */ 1952 explicit 1953 num_get(size_t __refs = 0) : facet(__refs) { } 1954 1955 /** 1956 * @brief Numeric parsing. 1957 * 1958 * Parses the input stream into the bool @a v. It does so by calling 1959 * num_get::do_get(). 1960 * 1961 * If ios_base::boolalpha is set, attempts to read 1962 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets 1963 * @a v to true or false if successful. Sets err to 1964 * ios_base::failbit if reading the string fails. Sets err to 1965 * ios_base::eofbit if the stream is emptied. 1966 * 1967 * If ios_base::boolalpha is not set, proceeds as with reading a long, 1968 * except if the value is 1, sets @a v to true, if the value is 0, sets 1969 * @a v to false, and otherwise set err to ios_base::failbit. 1970 * 1971 * @param in Start of input stream. 1972 * @param end End of input stream. 1973 * @param io Source of locale and flags. 1974 * @param err Error flags to set. 1975 * @param v Value to format and insert. 1976 * @return Iterator after reading. 1977 */ 1978 iter_type 1979 get(iter_type __in, iter_type __end, ios_base& __io, 1980 ios_base::iostate& __err, bool& __v) const 1981 { return this->do_get(__in, __end, __io, __err, __v); } 1982 1983 //@{ 1984 /** 1985 * @brief Numeric parsing. 1986 * 1987 * Parses the input stream into the integral variable @a v. It does so 1988 * by calling num_get::do_get(). 1989 * 1990 * Parsing is affected by the flag settings in @a io. 1991 * 1992 * The basic parse is affected by the value of io.flags() & 1993 * ios_base::basefield. If equal to ios_base::oct, parses like the 1994 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X 1995 * specifier. Else if basefield equal to 0, parses like the %i 1996 * specifier. Otherwise, parses like %d for signed and %u for unsigned 1997 * types. The matching type length modifier is also used. 1998 * 1999 * Digit grouping is intrepreted according to numpunct::grouping() and 2000 * numpunct::thousands_sep(). If the pattern of digit groups isn't 2001 * consistent, sets err to ios_base::failbit. 2002 * 2003 * If parsing the string yields a valid value for @a v, @a v is set. 2004 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered. 2005 * Sets err to ios_base::eofbit if the stream is emptied. 2006 * 2007 * @param in Start of input stream. 2008 * @param end End of input stream. 2009 * @param io Source of locale and flags. 2010 * @param err Error flags to set. 2011 * @param v Value to format and insert. 2012 * @return Iterator after reading. 2013 */ 2014 iter_type 2015 get(iter_type __in, iter_type __end, ios_base& __io, 2016 ios_base::iostate& __err, long& __v) const 2017 { return this->do_get(__in, __end, __io, __err, __v); } 2018 2019 iter_type 2020 get(iter_type __in, iter_type __end, ios_base& __io, 2021 ios_base::iostate& __err, unsigned short& __v) const 2022 { return this->do_get(__in, __end, __io, __err, __v); } 2023 2024 iter_type 2025 get(iter_type __in, iter_type __end, ios_base& __io, 2026 ios_base::iostate& __err, unsigned int& __v) const 2027 { return this->do_get(__in, __end, __io, __err, __v); } 2028 2029 iter_type 2030 get(iter_type __in, iter_type __end, ios_base& __io, 2031 ios_base::iostate& __err, unsigned long& __v) const 2032 { return this->do_get(__in, __end, __io, __err, __v); } 2033 2034#ifdef _GLIBCXX_USE_LONG_LONG 2035 iter_type 2036 get(iter_type __in, iter_type __end, ios_base& __io, 2037 ios_base::iostate& __err, long long& __v) const 2038 { return this->do_get(__in, __end, __io, __err, __v); } 2039 2040 iter_type 2041 get(iter_type __in, iter_type __end, ios_base& __io, 2042 ios_base::iostate& __err, unsigned long long& __v) const 2043 { return this->do_get(__in, __end, __io, __err, __v); } 2044#endif 2045 //@} 2046 2047 //@{ 2048 /** 2049 * @brief Numeric parsing. 2050 * 2051 * Parses the input stream into the integral variable @a v. It does so 2052 * by calling num_get::do_get(). 2053 * 2054 * The input characters are parsed like the scanf %g specifier. The 2055 * matching type length modifier is also used. 2056 * 2057 * The decimal point character used is numpunct::decimal_point(). 2058 * Digit grouping is intrepreted according to numpunct::grouping() and 2059 * numpunct::thousands_sep(). If the pattern of digit groups isn't 2060 * consistent, sets err to ios_base::failbit. 2061 * 2062 * If parsing the string yields a valid value for @a v, @a v is set. 2063 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered. 2064 * Sets err to ios_base::eofbit if the stream is emptied. 2065 * 2066 * @param in Start of input stream. 2067 * @param end End of input stream. 2068 * @param io Source of locale and flags. 2069 * @param err Error flags to set. 2070 * @param v Value to format and insert. 2071 * @return Iterator after reading. 2072 */ 2073 iter_type 2074 get(iter_type __in, iter_type __end, ios_base& __io, 2075 ios_base::iostate& __err, float& __v) const 2076 { return this->do_get(__in, __end, __io, __err, __v); } 2077 2078 iter_type 2079 get(iter_type __in, iter_type __end, ios_base& __io, 2080 ios_base::iostate& __err, double& __v) const 2081 { return this->do_get(__in, __end, __io, __err, __v); } 2082 2083 iter_type 2084 get(iter_type __in, iter_type __end, ios_base& __io, 2085 ios_base::iostate& __err, long double& __v) const 2086 { return this->do_get(__in, __end, __io, __err, __v); } 2087 //@} 2088 2089 /** 2090 * @brief Numeric parsing. 2091 * 2092 * Parses the input stream into the pointer variable @a v. It does so 2093 * by calling num_get::do_get(). 2094 * 2095 * The input characters are parsed like the scanf %p specifier. 2096 * 2097 * Digit grouping is intrepreted according to numpunct::grouping() and 2098 * numpunct::thousands_sep(). If the pattern of digit groups isn't 2099 * consistent, sets err to ios_base::failbit. 2100 * 2101 * Note that the digit grouping effect for pointers is a bit ambiguous 2102 * in the standard and shouldn't be relied on. See DR 344. 2103 * 2104 * If parsing the string yields a valid value for @a v, @a v is set. 2105 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered. 2106 * Sets err to ios_base::eofbit if the stream is emptied. 2107 * 2108 * @param in Start of input stream. 2109 * @param end End of input stream. 2110 * @param io Source of locale and flags. 2111 * @param err Error flags to set. 2112 * @param v Value to format and insert. 2113 * @return Iterator after reading. 2114 */ 2115 iter_type 2116 get(iter_type __in, iter_type __end, ios_base& __io, 2117 ios_base::iostate& __err, void*& __v) const 2118 { return this->do_get(__in, __end, __io, __err, __v); } 2119 2120 protected: 2121 /// Destructor. 2122 virtual ~num_get() { } 2123 2124 iter_type 2125 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&, 2126 string& __xtrc) const; 2127 2128 template<typename _ValueT> 2129 iter_type 2130 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&, 2131 _ValueT& __v) const; 2132 2133 template<typename _CharT2> 2134 typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, int>::__type 2135 _M_find(const _CharT2*, size_t __len, _CharT2 __c) const 2136 { 2137 int __ret = -1; 2138 if (__len <= 10) 2139 { 2140 if (__c >= _CharT2('0') && __c < _CharT2(_CharT2('0') + __len)) 2141 __ret = __c - _CharT2('0'); 2142 } 2143 else 2144 { 2145 if (__c >= _CharT2('0') && __c <= _CharT2('9')) 2146 __ret = __c - _CharT2('0'); 2147 else if (__c >= _CharT2('a') && __c <= _CharT2('f')) 2148 __ret = 10 + (__c - _CharT2('a')); 2149 else if (__c >= _CharT2('A') && __c <= _CharT2('F')) 2150 __ret = 10 + (__c - _CharT2('A')); 2151 } 2152 return __ret; 2153 } 2154 2155 template<typename _CharT2> 2156 typename __gnu_cxx::__enable_if<!__is_char<_CharT2>::__value, 2157 int>::__type 2158 _M_find(const _CharT2* __zero, size_t __len, _CharT2 __c) const 2159 { 2160 int __ret = -1; 2161 const char_type* __q = char_traits<_CharT2>::find(__zero, __len, __c); 2162 if (__q) 2163 { 2164 __ret = __q - __zero; 2165 if (__ret > 15) 2166 __ret -= 6; 2167 } 2168 return __ret; 2169 } 2170 2171 //@{ 2172 /** 2173 * @brief Numeric parsing. 2174 * 2175 * Parses the input stream into the variable @a v. This function is a 2176 * hook for derived classes to change the value returned. @see get() 2177 * for more details. 2178 * 2179 * @param in Start of input stream. 2180 * @param end End of input stream. 2181 * @param io Source of locale and flags. 2182 * @param err Error flags to set. 2183 * @param v Value to format and insert. 2184 * @return Iterator after reading. 2185 */ 2186 virtual iter_type 2187 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const; 2188 2189 2190 virtual iter_type 2191 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const; 2192 2193 virtual iter_type 2194 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2195 unsigned short&) const; 2196 2197 virtual iter_type 2198 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2199 unsigned int&) const; 2200 2201 virtual iter_type 2202 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2203 unsigned long&) const; 2204 2205#ifdef _GLIBCXX_USE_LONG_LONG 2206 virtual iter_type 2207 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2208 long long&) const; 2209 2210 virtual iter_type 2211 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2212 unsigned long long&) const; 2213#endif 2214 2215 virtual iter_type 2216 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2217 float&) const; 2218 2219 virtual iter_type 2220 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2221 double&) const; 2222 2223 // XXX GLIBCXX_ABI Deprecated 2224#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 2225 virtual iter_type 2226 __do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2227 double&) const; 2228#else 2229 virtual iter_type 2230 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2231 long double&) const; 2232#endif 2233 2234 virtual iter_type 2235 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2236 void*&) const; 2237 2238 // XXX GLIBCXX_ABI Deprecated 2239#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 2240 virtual iter_type 2241 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, 2242 long double&) const; 2243#endif 2244 //@} 2245 }; 2246 2247 template<typename _CharT, typename _InIter> 2248 locale::id num_get<_CharT, _InIter>::id; 2249 2250 2251 /** 2252 * @brief Facet for converting numbers to strings. 2253 * 2254 * This facet encapsulates the code to convert a number to a string. It is 2255 * used by the ostream numeric insertion operators. 2256 * 2257 * The num_put template uses protected virtual functions to provide the 2258 * actual results. The public accessors forward the call to the virtual 2259 * functions. These virtual functions are hooks for developers to 2260 * implement the behavior they require from the num_put facet. 2261 */ 2262 template<typename _CharT, typename _OutIter> 2263 class num_put : public locale::facet 2264 { 2265 public: 2266 // Types: 2267 //@{ 2268 /// Public typedefs 2269 typedef _CharT char_type; 2270 typedef _OutIter iter_type; 2271 //@} 2272 2273 /// Numpunct facet id. 2274 static locale::id id; 2275 2276 /** 2277 * @brief Constructor performs initialization. 2278 * 2279 * This is the constructor provided by the standard. 2280 * 2281 * @param refs Passed to the base facet class. 2282 */ 2283 explicit 2284 num_put(size_t __refs = 0) : facet(__refs) { } 2285 2286 /** 2287 * @brief Numeric formatting. 2288 * 2289 * Formats the boolean @a v and inserts it into a stream. It does so 2290 * by calling num_put::do_put(). 2291 * 2292 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or 2293 * ctype<CharT>::falsename(). Otherwise formats @a v as an int. 2294 * 2295 * @param s Stream to write to. 2296 * @param io Source of locale and flags. 2297 * @param fill Char_type to use for filling. 2298 * @param v Value to format and insert. 2299 * @return Iterator after writing. 2300 */ 2301 iter_type 2302 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const 2303 { return this->do_put(__s, __f, __fill, __v); } 2304 2305 //@{ 2306 /** 2307 * @brief Numeric formatting. 2308 * 2309 * Formats the integral value @a v and inserts it into a 2310 * stream. It does so by calling num_put::do_put(). 2311 * 2312 * Formatting is affected by the flag settings in @a io. 2313 * 2314 * The basic format is affected by the value of io.flags() & 2315 * ios_base::basefield. If equal to ios_base::oct, formats like the 2316 * printf %o specifier. Else if equal to ios_base::hex, formats like 2317 * %x or %X with ios_base::uppercase unset or set respectively. 2318 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu 2319 * for unsigned values. Note that if both oct and hex are set, neither 2320 * will take effect. 2321 * 2322 * If ios_base::showpos is set, '+' is output before positive values. 2323 * If ios_base::showbase is set, '0' precedes octal values (except 0) 2324 * and '0[xX]' precedes hex values. 2325 * 2326 * Thousands separators are inserted according to numpunct::grouping() 2327 * and numpunct::thousands_sep(). The decimal point character used is 2328 * numpunct::decimal_point(). 2329 * 2330 * If io.width() is non-zero, enough @a fill characters are inserted to 2331 * make the result at least that wide. If 2332 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is 2333 * padded at the end. If ios_base::internal, then padding occurs 2334 * immediately after either a '+' or '-' or after '0x' or '0X'. 2335 * Otherwise, padding occurs at the beginning. 2336 * 2337 * @param s Stream to write to. 2338 * @param io Source of locale and flags. 2339 * @param fill Char_type to use for filling. 2340 * @param v Value to format and insert. 2341 * @return Iterator after writing. 2342 */ 2343 iter_type 2344 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const 2345 { return this->do_put(__s, __f, __fill, __v); } 2346 2347 iter_type 2348 put(iter_type __s, ios_base& __f, char_type __fill, 2349 unsigned long __v) const 2350 { return this->do_put(__s, __f, __fill, __v); } 2351 2352#ifdef _GLIBCXX_USE_LONG_LONG 2353 iter_type 2354 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const 2355 { return this->do_put(__s, __f, __fill, __v); } 2356 2357 iter_type 2358 put(iter_type __s, ios_base& __f, char_type __fill, 2359 unsigned long long __v) const 2360 { return this->do_put(__s, __f, __fill, __v); } 2361#endif 2362 //@} 2363 2364 //@{ 2365 /** 2366 * @brief Numeric formatting. 2367 * 2368 * Formats the floating point value @a v and inserts it into a stream. 2369 * It does so by calling num_put::do_put(). 2370 * 2371 * Formatting is affected by the flag settings in @a io. 2372 * 2373 * The basic format is affected by the value of io.flags() & 2374 * ios_base::floatfield. If equal to ios_base::fixed, formats like the 2375 * printf %f specifier. Else if equal to ios_base::scientific, formats 2376 * like %e or %E with ios_base::uppercase unset or set respectively. 2377 * Otherwise, formats like %g or %G depending on uppercase. Note that 2378 * if both fixed and scientific are set, the effect will also be like 2379 * %g or %G. 2380 * 2381 * The output precision is given by io.precision(). This precision is 2382 * capped at numeric_limits::digits10 + 2 (different for double and 2383 * long double). The default precision is 6. 2384 * 2385 * If ios_base::showpos is set, '+' is output before positive values. 2386 * If ios_base::showpoint is set, a decimal point will always be 2387 * output. 2388 * 2389 * Thousands separators are inserted according to numpunct::grouping() 2390 * and numpunct::thousands_sep(). The decimal point character used is 2391 * numpunct::decimal_point(). 2392 * 2393 * If io.width() is non-zero, enough @a fill characters are inserted to 2394 * make the result at least that wide. If 2395 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is 2396 * padded at the end. If ios_base::internal, then padding occurs 2397 * immediately after either a '+' or '-' or after '0x' or '0X'. 2398 * Otherwise, padding occurs at the beginning. 2399 * 2400 * @param s Stream to write to. 2401 * @param io Source of locale and flags. 2402 * @param fill Char_type to use for filling. 2403 * @param v Value to format and insert. 2404 * @return Iterator after writing. 2405 */ 2406 iter_type 2407 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const 2408 { return this->do_put(__s, __f, __fill, __v); } 2409 2410 iter_type 2411 put(iter_type __s, ios_base& __f, char_type __fill, 2412 long double __v) const 2413 { return this->do_put(__s, __f, __fill, __v); } 2414 //@} 2415 2416 /** 2417 * @brief Numeric formatting. 2418 * 2419 * Formats the pointer value @a v and inserts it into a stream. It 2420 * does so by calling num_put::do_put(). 2421 * 2422 * This function formats @a v as an unsigned long with ios_base::hex 2423 * and ios_base::showbase set. 2424 * 2425 * @param s Stream to write to. 2426 * @param io Source of locale and flags. 2427 * @param fill Char_type to use for filling. 2428 * @param v Value to format and insert. 2429 * @return Iterator after writing. 2430 */ 2431 iter_type 2432 put(iter_type __s, ios_base& __f, char_type __fill, 2433 const void* __v) const 2434 { return this->do_put(__s, __f, __fill, __v); } 2435 2436 protected: 2437 template<typename _ValueT> 2438 iter_type 2439 _M_insert_float(iter_type, ios_base& __io, char_type __fill, 2440 char __mod, _ValueT __v) const; 2441 2442 void 2443 _M_group_float(const char* __grouping, size_t __grouping_size, 2444 char_type __sep, const char_type* __p, char_type* __new, 2445 char_type* __cs, int& __len) const; 2446 2447 template<typename _ValueT> 2448 iter_type 2449 _M_insert_int(iter_type, ios_base& __io, char_type __fill, 2450 _ValueT __v) const; 2451 2452 void 2453 _M_group_int(const char* __grouping, size_t __grouping_size, 2454 char_type __sep, ios_base& __io, char_type* __new, 2455 char_type* __cs, int& __len) const; 2456 2457 void 2458 _M_pad(char_type __fill, streamsize __w, ios_base& __io, 2459 char_type* __new, const char_type* __cs, int& __len) const; 2460 2461 /// Destructor. 2462 virtual 2463 ~num_put() { }; 2464 2465 //@{ 2466 /** 2467 * @brief Numeric formatting. 2468 * 2469 * These functions do the work of formatting numeric values and 2470 * inserting them into a stream. This function is a hook for derived 2471 * classes to change the value returned. 2472 * 2473 * @param s Stream to write to. 2474 * @param io Source of locale and flags. 2475 * @param fill Char_type to use for filling. 2476 * @param v Value to format and insert. 2477 * @return Iterator after writing. 2478 */ 2479 virtual iter_type 2480 do_put(iter_type, ios_base&, char_type __fill, bool __v) const; 2481 2482 virtual iter_type 2483 do_put(iter_type, ios_base&, char_type __fill, long __v) const; 2484 2485 virtual iter_type 2486 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const; 2487 2488#ifdef _GLIBCXX_USE_LONG_LONG 2489 virtual iter_type 2490 do_put(iter_type, ios_base&, char_type __fill, long long __v) const; 2491 2492 virtual iter_type 2493 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const; 2494#endif 2495 2496 virtual iter_type 2497 do_put(iter_type, ios_base&, char_type __fill, double __v) const; 2498 2499 // XXX GLIBCXX_ABI Deprecated 2500#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 2501 virtual iter_type 2502 __do_put(iter_type, ios_base&, char_type __fill, double __v) const; 2503#else 2504 virtual iter_type 2505 do_put(iter_type, ios_base&, char_type __fill, long double __v) const; 2506#endif 2507 2508 virtual iter_type 2509 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const; 2510 2511 // XXX GLIBCXX_ABI Deprecated 2512#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 2513 virtual iter_type 2514 do_put(iter_type, ios_base&, char_type __fill, long double __v) const; 2515#endif 2516 //@} 2517 }; 2518 2519 template <typename _CharT, typename _OutIter> 2520 locale::id num_put<_CharT, _OutIter>::id; 2521 2522_GLIBCXX_END_LDBL_NAMESPACE 2523 2524 /** 2525 * @brief Facet for localized string comparison. 2526 * 2527 * This facet encapsulates the code to compare strings in a localized 2528 * manner. 2529 * 2530 * The collate template uses protected virtual functions to provide 2531 * the actual results. The public accessors forward the call to 2532 * the virtual functions. These virtual functions are hooks for 2533 * developers to implement the behavior they require from the 2534 * collate facet. 2535 */ 2536 template<typename _CharT> 2537 class collate : public locale::facet 2538 { 2539 public: 2540 // Types: 2541 //@{ 2542 /// Public typedefs 2543 typedef _CharT char_type; 2544 typedef basic_string<_CharT> string_type; 2545 //@} 2546 2547 protected: 2548 // Underlying "C" library locale information saved from 2549 // initialization, needed by collate_byname as well. 2550 __c_locale _M_c_locale_collate; 2551 2552 public: 2553 /// Numpunct facet id. 2554 static locale::id id; 2555 2556 /** 2557 * @brief Constructor performs initialization. 2558 * 2559 * This is the constructor provided by the standard. 2560 * 2561 * @param refs Passed to the base facet class. 2562 */ 2563 explicit 2564 collate(size_t __refs = 0) 2565 : facet(__refs), _M_c_locale_collate(_S_get_c_locale()) 2566 { } 2567 2568 /** 2569 * @brief Internal constructor. Not for general use. 2570 * 2571 * This is a constructor for use by the library itself to set up new 2572 * locales. 2573 * 2574 * @param cloc The "C" locale. 2575 * @param refs Passed to the base facet class. 2576 */ 2577 explicit 2578 collate(__c_locale __cloc, size_t __refs = 0) 2579 : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc)) 2580 { } 2581 2582 /** 2583 * @brief Compare two strings. 2584 * 2585 * This function compares two strings and returns the result by calling 2586 * collate::do_compare(). 2587 * 2588 * @param lo1 Start of string 1. 2589 * @param hi1 End of string 1. 2590 * @param lo2 Start of string 2. 2591 * @param hi2 End of string 2. 2592 * @return 1 if string1 > string2, -1 if string1 < string2, else 0. 2593 */ 2594 int 2595 compare(const _CharT* __lo1, const _CharT* __hi1, 2596 const _CharT* __lo2, const _CharT* __hi2) const 2597 { return this->do_compare(__lo1, __hi1, __lo2, __hi2); } 2598 2599 /** 2600 * @brief Transform string to comparable form. 2601 * 2602 * This function is a wrapper for strxfrm functionality. It takes the 2603 * input string and returns a modified string that can be directly 2604 * compared to other transformed strings. In the "C" locale, this 2605 * function just returns a copy of the input string. In some other 2606 * locales, it may replace two chars with one, change a char for 2607 * another, etc. It does so by returning collate::do_transform(). 2608 * 2609 * @param lo Start of string. 2610 * @param hi End of string. 2611 * @return Transformed string_type. 2612 */ 2613 string_type 2614 transform(const _CharT* __lo, const _CharT* __hi) const 2615 { return this->do_transform(__lo, __hi); } 2616 2617 /** 2618 * @brief Return hash of a string. 2619 * 2620 * This function computes and returns a hash on the input string. It 2621 * does so by returning collate::do_hash(). 2622 * 2623 * @param lo Start of string. 2624 * @param hi End of string. 2625 * @return Hash value. 2626 */ 2627 long 2628 hash(const _CharT* __lo, const _CharT* __hi) const 2629 { return this->do_hash(__lo, __hi); } 2630 2631 // Used to abstract out _CharT bits in virtual member functions, below. 2632 int 2633 _M_compare(const _CharT*, const _CharT*) const; 2634 2635 size_t 2636 _M_transform(_CharT*, const _CharT*, size_t) const; 2637 2638 protected: 2639 /// Destructor. 2640 virtual 2641 ~collate() 2642 { _S_destroy_c_locale(_M_c_locale_collate); } 2643 2644 /** 2645 * @brief Compare two strings. 2646 * 2647 * This function is a hook for derived classes to change the value 2648 * returned. @see compare(). 2649 * 2650 * @param lo1 Start of string 1. 2651 * @param hi1 End of string 1. 2652 * @param lo2 Start of string 2. 2653 * @param hi2 End of string 2. 2654 * @return 1 if string1 > string2, -1 if string1 < string2, else 0. 2655 */ 2656 virtual int 2657 do_compare(const _CharT* __lo1, const _CharT* __hi1, 2658 const _CharT* __lo2, const _CharT* __hi2) const; 2659 2660 /** 2661 * @brief Transform string to comparable form. 2662 * 2663 * This function is a hook for derived classes to change the value 2664 * returned. 2665 * 2666 * @param lo1 Start of string 1. 2667 * @param hi1 End of string 1. 2668 * @param lo2 Start of string 2. 2669 * @param hi2 End of string 2. 2670 * @return 1 if string1 > string2, -1 if string1 < string2, else 0. 2671 */ 2672 virtual string_type 2673 do_transform(const _CharT* __lo, const _CharT* __hi) const; 2674 2675 /** 2676 * @brief Return hash of a string. 2677 * 2678 * This function computes and returns a hash on the input string. This 2679 * function is a hook for derived classes to change the value returned. 2680 * 2681 * @param lo Start of string. 2682 * @param hi End of string. 2683 * @return Hash value. 2684 */ 2685 virtual long 2686 do_hash(const _CharT* __lo, const _CharT* __hi) const; 2687 }; 2688 2689 template<typename _CharT> 2690 locale::id collate<_CharT>::id; 2691 2692 // Specializations. 2693 template<> 2694 int 2695 collate<char>::_M_compare(const char*, const char*) const; 2696 2697 template<> 2698 size_t 2699 collate<char>::_M_transform(char*, const char*, size_t) const; 2700 2701#ifdef _GLIBCXX_USE_WCHAR_T 2702 template<> 2703 int 2704 collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const; 2705 2706 template<> 2707 size_t 2708 collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const; 2709#endif 2710 2711 /// @brief class collate_byname [22.2.4.2]. 2712 template<typename _CharT> 2713 class collate_byname : public collate<_CharT> 2714 { 2715 public: 2716 //@{ 2717 /// Public typedefs 2718 typedef _CharT char_type; 2719 typedef basic_string<_CharT> string_type; 2720 //@} 2721 2722 explicit 2723 collate_byname(const char* __s, size_t __refs = 0) 2724 : collate<_CharT>(__refs) 2725 { 2726 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0) 2727 { 2728 this->_S_destroy_c_locale(this->_M_c_locale_collate); 2729 this->_S_create_c_locale(this->_M_c_locale_collate, __s); 2730 } 2731 } 2732 2733 protected: 2734 virtual 2735 ~collate_byname() { } 2736 }; 2737 2738 2739 /** 2740 * @brief Time format ordering data. 2741 * 2742 * This class provides an enum representing different orderings of day, 2743 * month, and year. 2744 */ 2745 class time_base 2746 { 2747 public: 2748 enum dateorder { no_order, dmy, mdy, ymd, ydm }; 2749 }; 2750 2751 template<typename _CharT> 2752 struct __timepunct_cache : public locale::facet 2753 { 2754 // List of all known timezones, with GMT first. 2755 static const _CharT* _S_timezones[14]; 2756 2757 const _CharT* _M_date_format; 2758 const _CharT* _M_date_era_format; 2759 const _CharT* _M_time_format; 2760 const _CharT* _M_time_era_format; 2761 const _CharT* _M_date_time_format; 2762 const _CharT* _M_date_time_era_format; 2763 const _CharT* _M_am; 2764 const _CharT* _M_pm; 2765 const _CharT* _M_am_pm_format; 2766 2767 // Day names, starting with "C"'s Sunday. 2768 const _CharT* _M_day1; 2769 const _CharT* _M_day2; 2770 const _CharT* _M_day3; 2771 const _CharT* _M_day4; 2772 const _CharT* _M_day5; 2773 const _CharT* _M_day6; 2774 const _CharT* _M_day7; 2775 2776 // Abbreviated day names, starting with "C"'s Sun. 2777 const _CharT* _M_aday1; 2778 const _CharT* _M_aday2; 2779 const _CharT* _M_aday3; 2780 const _CharT* _M_aday4; 2781 const _CharT* _M_aday5; 2782 const _CharT* _M_aday6; 2783 const _CharT* _M_aday7; 2784 2785 // Month names, starting with "C"'s January. 2786 const _CharT* _M_month01; 2787 const _CharT* _M_month02; 2788 const _CharT* _M_month03; 2789 const _CharT* _M_month04; 2790 const _CharT* _M_month05; 2791 const _CharT* _M_month06; 2792 const _CharT* _M_month07; 2793 const _CharT* _M_month08; 2794 const _CharT* _M_month09; 2795 const _CharT* _M_month10; 2796 const _CharT* _M_month11; 2797 const _CharT* _M_month12; 2798 2799 // Abbreviated month names, starting with "C"'s Jan. 2800 const _CharT* _M_amonth01; 2801 const _CharT* _M_amonth02; 2802 const _CharT* _M_amonth03; 2803 const _CharT* _M_amonth04; 2804 const _CharT* _M_amonth05; 2805 const _CharT* _M_amonth06; 2806 const _CharT* _M_amonth07; 2807 const _CharT* _M_amonth08; 2808 const _CharT* _M_amonth09; 2809 const _CharT* _M_amonth10; 2810 const _CharT* _M_amonth11; 2811 const _CharT* _M_amonth12; 2812 2813 bool _M_allocated; 2814 2815 __timepunct_cache(size_t __refs = 0) : facet(__refs), 2816 _M_date_format(NULL), _M_date_era_format(NULL), _M_time_format(NULL), 2817 _M_time_era_format(NULL), _M_date_time_format(NULL), 2818 _M_date_time_era_format(NULL), _M_am(NULL), _M_pm(NULL), 2819 _M_am_pm_format(NULL), _M_day1(NULL), _M_day2(NULL), _M_day3(NULL), 2820 _M_day4(NULL), _M_day5(NULL), _M_day6(NULL), _M_day7(NULL), 2821 _M_aday1(NULL), _M_aday2(NULL), _M_aday3(NULL), _M_aday4(NULL), 2822 _M_aday5(NULL), _M_aday6(NULL), _M_aday7(NULL), _M_month01(NULL), 2823 _M_month02(NULL), _M_month03(NULL), _M_month04(NULL), _M_month05(NULL), 2824 _M_month06(NULL), _M_month07(NULL), _M_month08(NULL), _M_month09(NULL), 2825 _M_month10(NULL), _M_month11(NULL), _M_month12(NULL), _M_amonth01(NULL), 2826 _M_amonth02(NULL), _M_amonth03(NULL), _M_amonth04(NULL), 2827 _M_amonth05(NULL), _M_amonth06(NULL), _M_amonth07(NULL), 2828 _M_amonth08(NULL), _M_amonth09(NULL), _M_amonth10(NULL), 2829 _M_amonth11(NULL), _M_amonth12(NULL), _M_allocated(false) 2830 { } 2831 2832 ~__timepunct_cache(); 2833 2834 void 2835 _M_cache(const locale& __loc); 2836 2837 private: 2838 __timepunct_cache& 2839 operator=(const __timepunct_cache&); 2840 2841 explicit 2842 __timepunct_cache(const __timepunct_cache&); 2843 }; 2844 2845 template<typename _CharT> 2846 __timepunct_cache<_CharT>::~__timepunct_cache() 2847 { 2848 if (_M_allocated) 2849 { 2850 // Unused. 2851 } 2852 } 2853 2854 // Specializations. 2855 template<> 2856 const char* 2857 __timepunct_cache<char>::_S_timezones[14]; 2858 2859#ifdef _GLIBCXX_USE_WCHAR_T 2860 template<> 2861 const wchar_t* 2862 __timepunct_cache<wchar_t>::_S_timezones[14]; 2863#endif 2864 2865 // Generic. 2866 template<typename _CharT> 2867 const _CharT* __timepunct_cache<_CharT>::_S_timezones[14]; 2868 2869 template<typename _CharT> 2870 class __timepunct : public locale::facet 2871 { 2872 public: 2873 // Types: 2874 typedef _CharT __char_type; 2875 typedef basic_string<_CharT> __string_type; 2876 typedef __timepunct_cache<_CharT> __cache_type; 2877 2878 protected: 2879 __cache_type* _M_data; 2880 __c_locale _M_c_locale_timepunct; 2881 const char* _M_name_timepunct; 2882 2883 public: 2884 /// Numpunct facet id. 2885 static locale::id id; 2886 2887 explicit 2888 __timepunct(size_t __refs = 0); 2889 2890 explicit 2891 __timepunct(__cache_type* __cache, size_t __refs = 0); 2892 2893 /** 2894 * @brief Internal constructor. Not for general use. 2895 * 2896 * This is a constructor for use by the library itself to set up new 2897 * locales. 2898 * 2899 * @param cloc The "C" locale. 2900 * @param s The name of a locale. 2901 * @param refs Passed to the base facet class. 2902 */ 2903 explicit 2904 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0); 2905 2906 // FIXME: for error checking purposes _M_put should return the return 2907 // value of strftime/wcsftime. 2908 void 2909 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format, 2910 const tm* __tm) const; 2911 2912 void 2913 _M_date_formats(const _CharT** __date) const 2914 { 2915 // Always have default first. 2916 __date[0] = _M_data->_M_date_format; 2917 __date[1] = _M_data->_M_date_era_format; 2918 } 2919 2920 void 2921 _M_time_formats(const _CharT** __time) const 2922 { 2923 // Always have default first. 2924 __time[0] = _M_data->_M_time_format; 2925 __time[1] = _M_data->_M_time_era_format; 2926 } 2927 2928 void 2929 _M_date_time_formats(const _CharT** __dt) const 2930 { 2931 // Always have default first. 2932 __dt[0] = _M_data->_M_date_time_format; 2933 __dt[1] = _M_data->_M_date_time_era_format; 2934 } 2935 2936 void 2937 _M_am_pm_format(const _CharT* __ampm) const 2938 { __ampm = _M_data->_M_am_pm_format; } 2939 2940 void 2941 _M_am_pm(const _CharT** __ampm) const 2942 { 2943 __ampm[0] = _M_data->_M_am; 2944 __ampm[1] = _M_data->_M_pm; 2945 } 2946 2947 void 2948 _M_days(const _CharT** __days) const 2949 { 2950 __days[0] = _M_data->_M_day1; 2951 __days[1] = _M_data->_M_day2; 2952 __days[2] = _M_data->_M_day3; 2953 __days[3] = _M_data->_M_day4; 2954 __days[4] = _M_data->_M_day5; 2955 __days[5] = _M_data->_M_day6; 2956 __days[6] = _M_data->_M_day7; 2957 } 2958 2959 void 2960 _M_days_abbreviated(const _CharT** __days) const 2961 { 2962 __days[0] = _M_data->_M_aday1; 2963 __days[1] = _M_data->_M_aday2; 2964 __days[2] = _M_data->_M_aday3; 2965 __days[3] = _M_data->_M_aday4; 2966 __days[4] = _M_data->_M_aday5; 2967 __days[5] = _M_data->_M_aday6; 2968 __days[6] = _M_data->_M_aday7; 2969 } 2970 2971 void 2972 _M_months(const _CharT** __months) const 2973 { 2974 __months[0] = _M_data->_M_month01; 2975 __months[1] = _M_data->_M_month02; 2976 __months[2] = _M_data->_M_month03; 2977 __months[3] = _M_data->_M_month04; 2978 __months[4] = _M_data->_M_month05; 2979 __months[5] = _M_data->_M_month06; 2980 __months[6] = _M_data->_M_month07; 2981 __months[7] = _M_data->_M_month08; 2982 __months[8] = _M_data->_M_month09; 2983 __months[9] = _M_data->_M_month10; 2984 __months[10] = _M_data->_M_month11; 2985 __months[11] = _M_data->_M_month12; 2986 } 2987 2988 void 2989 _M_months_abbreviated(const _CharT** __months) const 2990 { 2991 __months[0] = _M_data->_M_amonth01; 2992 __months[1] = _M_data->_M_amonth02; 2993 __months[2] = _M_data->_M_amonth03; 2994 __months[3] = _M_data->_M_amonth04; 2995 __months[4] = _M_data->_M_amonth05; 2996 __months[5] = _M_data->_M_amonth06; 2997 __months[6] = _M_data->_M_amonth07; 2998 __months[7] = _M_data->_M_amonth08; 2999 __months[8] = _M_data->_M_amonth09; 3000 __months[9] = _M_data->_M_amonth10; 3001 __months[10] = _M_data->_M_amonth11; 3002 __months[11] = _M_data->_M_amonth12; 3003 } 3004 3005 protected: 3006 virtual 3007 ~__timepunct(); 3008 3009 // For use at construction time only. 3010 void 3011 _M_initialize_timepunct(__c_locale __cloc = NULL); 3012 }; 3013 3014 template<typename _CharT> 3015 locale::id __timepunct<_CharT>::id; 3016 3017 // Specializations. 3018 template<> 3019 void 3020 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc); 3021 3022 template<> 3023 void 3024 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const; 3025 3026#ifdef _GLIBCXX_USE_WCHAR_T 3027 template<> 3028 void 3029 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc); 3030 3031 template<> 3032 void 3033 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*, 3034 const tm*) const; 3035#endif 3036 3037_GLIBCXX_END_NAMESPACE 3038 3039 // Include host and configuration specific timepunct functions. 3040 #include <bits/time_members.h> 3041 3042_GLIBCXX_BEGIN_NAMESPACE(std) 3043 3044 /** 3045 * @brief Facet for parsing dates and times. 3046 * 3047 * This facet encapsulates the code to parse and return a date or 3048 * time from a string. It is used by the istream numeric 3049 * extraction operators. 3050 * 3051 * The time_get template uses protected virtual functions to provide the 3052 * actual results. The public accessors forward the call to the virtual 3053 * functions. These virtual functions are hooks for developers to 3054 * implement the behavior they require from the time_get facet. 3055 */ 3056 template<typename _CharT, typename _InIter> 3057 class time_get : public locale::facet, public time_base 3058 { 3059 public: 3060 // Types: 3061 //@{ 3062 /// Public typedefs 3063 typedef _CharT char_type; 3064 typedef _InIter iter_type; 3065 //@} 3066 typedef basic_string<_CharT> __string_type; 3067 3068 /// Numpunct facet id. 3069 static locale::id id; 3070 3071 /** 3072 * @brief Constructor performs initialization. 3073 * 3074 * This is the constructor provided by the standard. 3075 * 3076 * @param refs Passed to the base facet class. 3077 */ 3078 explicit 3079 time_get(size_t __refs = 0) 3080 : facet (__refs) { } 3081 3082 /** 3083 * @brief Return preferred order of month, day, and year. 3084 * 3085 * This function returns an enum from timebase::dateorder giving the 3086 * preferred ordering if the format "x" given to time_put::put() only 3087 * uses month, day, and year. If the format "x" for the associated 3088 * locale uses other fields, this function returns 3089 * timebase::dateorder::noorder. 3090 * 3091 * NOTE: The library always returns noorder at the moment. 3092 * 3093 * @return A member of timebase::dateorder. 3094 */ 3095 dateorder 3096 date_order() const 3097 { return this->do_date_order(); } 3098 3099 /** 3100 * @brief Parse input time string. 3101 * 3102 * This function parses a time according to the format "x" and puts the 3103 * results into a user-supplied struct tm. The result is returned by 3104 * calling time_get::do_get_time(). 3105 * 3106 * If there is a valid time string according to format "x", @a tm will 3107 * be filled in accordingly and the returned iterator will point to the 3108 * first character beyond the time string. If an error occurs before 3109 * the end, err |= ios_base::failbit. If parsing reads all the 3110 * characters, err |= ios_base::eofbit. 3111 * 3112 * @param beg Start of string to parse. 3113 * @param end End of string to parse. 3114 * @param io Source of the locale. 3115 * @param err Error flags to set. 3116 * @param tm Pointer to struct tm to fill in. 3117 * @return Iterator to first char beyond time string. 3118 */ 3119 iter_type 3120 get_time(iter_type __beg, iter_type __end, ios_base& __io, 3121 ios_base::iostate& __err, tm* __tm) const 3122 { return this->do_get_time(__beg, __end, __io, __err, __tm); } 3123 3124 /** 3125 * @brief Parse input date string. 3126 * 3127 * This function parses a date according to the format "X" and puts the 3128 * results into a user-supplied struct tm. The result is returned by 3129 * calling time_get::do_get_date(). 3130 * 3131 * If there is a valid date string according to format "X", @a tm will 3132 * be filled in accordingly and the returned iterator will point to the 3133 * first character beyond the date string. If an error occurs before 3134 * the end, err |= ios_base::failbit. If parsing reads all the 3135 * characters, err |= ios_base::eofbit. 3136 * 3137 * @param beg Start of string to parse. 3138 * @param end End of string to parse. 3139 * @param io Source of the locale. 3140 * @param err Error flags to set. 3141 * @param tm Pointer to struct tm to fill in. 3142 * @return Iterator to first char beyond date string. 3143 */ 3144 iter_type 3145 get_date(iter_type __beg, iter_type __end, ios_base& __io, 3146 ios_base::iostate& __err, tm* __tm) const 3147 { return this->do_get_date(__beg, __end, __io, __err, __tm); } 3148 3149 /** 3150 * @brief Parse input weekday string. 3151 * 3152 * This function parses a weekday name and puts the results into a 3153 * user-supplied struct tm. The result is returned by calling 3154 * time_get::do_get_weekday(). 3155 * 3156 * Parsing starts by parsing an abbreviated weekday name. If a valid 3157 * abbreviation is followed by a character that would lead to the full 3158 * weekday name, parsing continues until the full name is found or an 3159 * error occurs. Otherwise parsing finishes at the end of the 3160 * abbreviated name. 3161 * 3162 * If an error occurs before the end, err |= ios_base::failbit. If 3163 * parsing reads all the characters, err |= ios_base::eofbit. 3164 * 3165 * @param beg Start of string to parse. 3166 * @param end End of string to parse. 3167 * @param io Source of the locale. 3168 * @param err Error flags to set. 3169 * @param tm Pointer to struct tm to fill in. 3170 * @return Iterator to first char beyond weekday name. 3171 */ 3172 iter_type 3173 get_weekday(iter_type __beg, iter_type __end, ios_base& __io, 3174 ios_base::iostate& __err, tm* __tm) const 3175 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); } 3176 3177 /** 3178 * @brief Parse input month string. 3179 * 3180 * This function parses a month name and puts the results into a 3181 * user-supplied struct tm. The result is returned by calling 3182 * time_get::do_get_monthname(). 3183 * 3184 * Parsing starts by parsing an abbreviated month name. If a valid 3185 * abbreviation is followed by a character that would lead to the full 3186 * month name, parsing continues until the full name is found or an 3187 * error occurs. Otherwise parsing finishes at the end of the 3188 * abbreviated name. 3189 * 3190 * If an error occurs before the end, err |= ios_base::failbit. If 3191 * parsing reads all the characters, err |= 3192 * ios_base::eofbit. 3193 * 3194 * @param beg Start of string to parse. 3195 * @param end End of string to parse. 3196 * @param io Source of the locale. 3197 * @param err Error flags to set. 3198 * @param tm Pointer to struct tm to fill in. 3199 * @return Iterator to first char beyond month name. 3200 */ 3201 iter_type 3202 get_monthname(iter_type __beg, iter_type __end, ios_base& __io, 3203 ios_base::iostate& __err, tm* __tm) const 3204 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); } 3205 3206 /** 3207 * @brief Parse input year string. 3208 * 3209 * This function reads up to 4 characters to parse a year string and 3210 * puts the results into a user-supplied struct tm. The result is 3211 * returned by calling time_get::do_get_year(). 3212 * 3213 * 4 consecutive digits are interpreted as a full year. If there are 3214 * exactly 2 consecutive digits, the library interprets this as the 3215 * number of years since 1900. 3216 * 3217 * If an error occurs before the end, err |= ios_base::failbit. If 3218 * parsing reads all the characters, err |= ios_base::eofbit. 3219 * 3220 * @param beg Start of string to parse. 3221 * @param end End of string to parse. 3222 * @param io Source of the locale. 3223 * @param err Error flags to set. 3224 * @param tm Pointer to struct tm to fill in. 3225 * @return Iterator to first char beyond year. 3226 */ 3227 iter_type 3228 get_year(iter_type __beg, iter_type __end, ios_base& __io, 3229 ios_base::iostate& __err, tm* __tm) const 3230 { return this->do_get_year(__beg, __end, __io, __err, __tm); } 3231 3232 protected: 3233 /// Destructor. 3234 virtual 3235 ~time_get() { } 3236 3237 /** 3238 * @brief Return preferred order of month, day, and year. 3239 * 3240 * This function returns an enum from timebase::dateorder giving the 3241 * preferred ordering if the format "x" given to time_put::put() only 3242 * uses month, day, and year. This function is a hook for derived 3243 * classes to change the value returned. 3244 * 3245 * @return A member of timebase::dateorder. 3246 */ 3247 virtual dateorder 3248 do_date_order() const; 3249 3250 /** 3251 * @brief Parse input time string. 3252 * 3253 * This function parses a time according to the format "x" and puts the 3254 * results into a user-supplied struct tm. This function is a hook for 3255 * derived classes to change the value returned. @see get_time() for 3256 * details. 3257 * 3258 * @param beg Start of string to parse. 3259 * @param end End of string to parse. 3260 * @param io Source of the locale. 3261 * @param err Error flags to set. 3262 * @param tm Pointer to struct tm to fill in. 3263 * @return Iterator to first char beyond time string. 3264 */ 3265 virtual iter_type 3266 do_get_time(iter_type __beg, iter_type __end, ios_base& __io, 3267 ios_base::iostate& __err, tm* __tm) const; 3268 3269 /** 3270 * @brief Parse input date string. 3271 * 3272 * This function parses a date according to the format "X" and puts the 3273 * results into a user-supplied struct tm. This function is a hook for 3274 * derived classes to change the value returned. @see get_date() for 3275 * details. 3276 * 3277 * @param beg Start of string to parse. 3278 * @param end End of string to parse. 3279 * @param io Source of the locale. 3280 * @param err Error flags to set. 3281 * @param tm Pointer to struct tm to fill in. 3282 * @return Iterator to first char beyond date string. 3283 */ 3284 virtual iter_type 3285 do_get_date(iter_type __beg, iter_type __end, ios_base& __io, 3286 ios_base::iostate& __err, tm* __tm) const; 3287 3288 /** 3289 * @brief Parse input weekday string. 3290 * 3291 * This function parses a weekday name and puts the results into a 3292 * user-supplied struct tm. This function is a hook for derived 3293 * classes to change the value returned. @see get_weekday() for 3294 * details. 3295 * 3296 * @param beg Start of string to parse. 3297 * @param end End of string to parse. 3298 * @param io Source of the locale. 3299 * @param err Error flags to set. 3300 * @param tm Pointer to struct tm to fill in. 3301 * @return Iterator to first char beyond weekday name. 3302 */ 3303 virtual iter_type 3304 do_get_weekday(iter_type __beg, iter_type __end, ios_base&, 3305 ios_base::iostate& __err, tm* __tm) const; 3306 3307 /** 3308 * @brief Parse input month string. 3309 * 3310 * This function parses a month name and puts the results into a 3311 * user-supplied struct tm. This function is a hook for derived 3312 * classes to change the value returned. @see get_monthname() for 3313 * details. 3314 * 3315 * @param beg Start of string to parse. 3316 * @param end End of string to parse. 3317 * @param io Source of the locale. 3318 * @param err Error flags to set. 3319 * @param tm Pointer to struct tm to fill in. 3320 * @return Iterator to first char beyond month name. 3321 */ 3322 virtual iter_type 3323 do_get_monthname(iter_type __beg, iter_type __end, ios_base&, 3324 ios_base::iostate& __err, tm* __tm) const; 3325 3326 /** 3327 * @brief Parse input year string. 3328 * 3329 * This function reads up to 4 characters to parse a year string and 3330 * puts the results into a user-supplied struct tm. This function is a 3331 * hook for derived classes to change the value returned. @see 3332 * get_year() for details. 3333 * 3334 * @param beg Start of string to parse. 3335 * @param end End of string to parse. 3336 * @param io Source of the locale. 3337 * @param err Error flags to set. 3338 * @param tm Pointer to struct tm to fill in. 3339 * @return Iterator to first char beyond year. 3340 */ 3341 virtual iter_type 3342 do_get_year(iter_type __beg, iter_type __end, ios_base& __io, 3343 ios_base::iostate& __err, tm* __tm) const; 3344 3345 // Extract numeric component of length __len. 3346 iter_type 3347 _M_extract_num(iter_type __beg, iter_type __end, int& __member, 3348 int __min, int __max, size_t __len, 3349 ios_base& __io, ios_base::iostate& __err) const; 3350 3351 // Extract day or month name, or any unique array of string 3352 // literals in a const _CharT* array. 3353 iter_type 3354 _M_extract_name(iter_type __beg, iter_type __end, int& __member, 3355 const _CharT** __names, size_t __indexlen, 3356 ios_base& __io, ios_base::iostate& __err) const; 3357 3358 // Extract on a component-by-component basis, via __format argument. 3359 iter_type 3360 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io, 3361 ios_base::iostate& __err, tm* __tm, 3362 const _CharT* __format) const; 3363 }; 3364 3365 template<typename _CharT, typename _InIter> 3366 locale::id time_get<_CharT, _InIter>::id; 3367 3368 /// @brief class time_get_byname [22.2.5.2]. 3369 template<typename _CharT, typename _InIter> 3370 class time_get_byname : public time_get<_CharT, _InIter> 3371 { 3372 public: 3373 // Types: 3374 typedef _CharT char_type; 3375 typedef _InIter iter_type; 3376 3377 explicit 3378 time_get_byname(const char*, size_t __refs = 0) 3379 : time_get<_CharT, _InIter>(__refs) { } 3380 3381 protected: 3382 virtual 3383 ~time_get_byname() { } 3384 }; 3385 3386 /** 3387 * @brief Facet for outputting dates and times. 3388 * 3389 * This facet encapsulates the code to format and output dates and times 3390 * according to formats used by strftime(). 3391 * 3392 * The time_put template uses protected virtual functions to provide the 3393 * actual results. The public accessors forward the call to the virtual 3394 * functions. These virtual functions are hooks for developers to 3395 * implement the behavior they require from the time_put facet. 3396 */ 3397 template<typename _CharT, typename _OutIter> 3398 class time_put : public locale::facet 3399 { 3400 public: 3401 // Types: 3402 //@{ 3403 /// Public typedefs 3404 typedef _CharT char_type; 3405 typedef _OutIter iter_type; 3406 //@} 3407 3408 /// Numpunct facet id. 3409 static locale::id id; 3410 3411 /** 3412 * @brief Constructor performs initialization. 3413 * 3414 * This is the constructor provided by the standard. 3415 * 3416 * @param refs Passed to the base facet class. 3417 */ 3418 explicit 3419 time_put(size_t __refs = 0) 3420 : facet(__refs) { } 3421 3422 /** 3423 * @brief Format and output a time or date. 3424 * 3425 * This function formats the data in struct tm according to the 3426 * provided format string. The format string is interpreted as by 3427 * strftime(). 3428 * 3429 * @param s The stream to write to. 3430 * @param io Source of locale. 3431 * @param fill char_type to use for padding. 3432 * @param tm Struct tm with date and time info to format. 3433 * @param beg Start of format string. 3434 * @param end End of format string. 3435 * @return Iterator after writing. 3436 */ 3437 iter_type 3438 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 3439 const _CharT* __beg, const _CharT* __end) const; 3440 3441 /** 3442 * @brief Format and output a time or date. 3443 * 3444 * This function formats the data in struct tm according to the 3445 * provided format char and optional modifier. The format and modifier 3446 * are interpreted as by strftime(). It does so by returning 3447 * time_put::do_put(). 3448 * 3449 * @param s The stream to write to. 3450 * @param io Source of locale. 3451 * @param fill char_type to use for padding. 3452 * @param tm Struct tm with date and time info to format. 3453 * @param format Format char. 3454 * @param mod Optional modifier char. 3455 * @return Iterator after writing. 3456 */ 3457 iter_type 3458 put(iter_type __s, ios_base& __io, char_type __fill, 3459 const tm* __tm, char __format, char __mod = 0) const 3460 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); } 3461 3462 protected: 3463 /// Destructor. 3464 virtual 3465 ~time_put() 3466 { } 3467 3468 /** 3469 * @brief Format and output a time or date. 3470 * 3471 * This function formats the data in struct tm according to the 3472 * provided format char and optional modifier. This function is a hook 3473 * for derived classes to change the value returned. @see put() for 3474 * more details. 3475 * 3476 * @param s The stream to write to. 3477 * @param io Source of locale. 3478 * @param fill char_type to use for padding. 3479 * @param tm Struct tm with date and time info to format. 3480 * @param format Format char. 3481 * @param mod Optional modifier char. 3482 * @return Iterator after writing. 3483 */ 3484 virtual iter_type 3485 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, 3486 char __format, char __mod) const; 3487 }; 3488 3489 template<typename _CharT, typename _OutIter> 3490 locale::id time_put<_CharT, _OutIter>::id; 3491 3492 /// @brief class time_put_byname [22.2.5.4]. 3493 template<typename _CharT, typename _OutIter> 3494 class time_put_byname : public time_put<_CharT, _OutIter> 3495 { 3496 public: 3497 // Types: 3498 typedef _CharT char_type; 3499 typedef _OutIter iter_type; 3500 3501 explicit 3502 time_put_byname(const char*, size_t __refs = 0) 3503 : time_put<_CharT, _OutIter>(__refs) 3504 { }; 3505 3506 protected: 3507 virtual 3508 ~time_put_byname() { } 3509 }; 3510 3511 3512 /** 3513 * @brief Money format ordering data. 3514 * 3515 * This class contains an ordered array of 4 fields to represent the 3516 * pattern for formatting a money amount. Each field may contain one entry 3517 * from the part enum. symbol, sign, and value must be present and the 3518 * remaining field must contain either none or space. @see 3519 * moneypunct::pos_format() and moneypunct::neg_format() for details of how 3520 * these fields are interpreted. 3521 */ 3522 class money_base 3523 { 3524 public: 3525 enum part { none, space, symbol, sign, value }; 3526 struct pattern { char field[4]; }; 3527 3528 static const pattern _S_default_pattern; 3529 3530 enum 3531 { 3532 _S_minus, 3533 _S_zero, 3534 _S_end = 11 3535 }; 3536 3537 // String literal of acceptable (narrow) input/output, for 3538 // money_get/money_put. "-0123456789" 3539 static const char* _S_atoms; 3540 3541 // Construct and return valid pattern consisting of some combination of: 3542 // space none symbol sign value 3543 static pattern 3544 _S_construct_pattern(char __precedes, char __space, char __posn); 3545 }; 3546 3547 template<typename _CharT, bool _Intl> 3548 struct __moneypunct_cache : public locale::facet 3549 { 3550 const char* _M_grouping; 3551 size_t _M_grouping_size; 3552 bool _M_use_grouping; 3553 _CharT _M_decimal_point; 3554 _CharT _M_thousands_sep; 3555 const _CharT* _M_curr_symbol; 3556 size_t _M_curr_symbol_size; 3557 const _CharT* _M_positive_sign; 3558 size_t _M_positive_sign_size; 3559 const _CharT* _M_negative_sign; 3560 size_t _M_negative_sign_size; 3561 int _M_frac_digits; 3562 money_base::pattern _M_pos_format; 3563 money_base::pattern _M_neg_format; 3564 3565 // A list of valid numeric literals for input and output: in the standard 3566 // "C" locale, this is "-0123456789". This array contains the chars after 3567 // having been passed through the current locale's ctype<_CharT>.widen(). 3568 _CharT _M_atoms[money_base::_S_end]; 3569 3570 bool _M_allocated; 3571 3572 __moneypunct_cache(size_t __refs = 0) : facet(__refs), 3573 _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false), 3574 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()), 3575 _M_curr_symbol(NULL), _M_curr_symbol_size(0), 3576 _M_positive_sign(NULL), _M_positive_sign_size(0), 3577 _M_negative_sign(NULL), _M_negative_sign_size(0), 3578 _M_frac_digits(0), 3579 _M_pos_format(money_base::pattern()), 3580 _M_neg_format(money_base::pattern()), _M_allocated(false) 3581 { } 3582 3583 ~__moneypunct_cache(); 3584 3585 void 3586 _M_cache(const locale& __loc); 3587 3588 private: 3589 __moneypunct_cache& 3590 operator=(const __moneypunct_cache&); 3591 3592 explicit 3593 __moneypunct_cache(const __moneypunct_cache&); 3594 }; 3595 3596 template<typename _CharT, bool _Intl> 3597 __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache() 3598 { 3599 if (_M_allocated) 3600 { 3601 delete [] _M_grouping; 3602 delete [] _M_curr_symbol; 3603 delete [] _M_positive_sign; 3604 delete [] _M_negative_sign; 3605 } 3606 } 3607 3608 /** 3609 * @brief Facet for formatting data for money amounts. 3610 * 3611 * This facet encapsulates the punctuation, grouping and other formatting 3612 * features of money amount string representations. 3613 */ 3614 template<typename _CharT, bool _Intl> 3615 class moneypunct : public locale::facet, public money_base 3616 { 3617 public: 3618 // Types: 3619 //@{ 3620 /// Public typedefs 3621 typedef _CharT char_type; 3622 typedef basic_string<_CharT> string_type; 3623 //@} 3624 typedef __moneypunct_cache<_CharT, _Intl> __cache_type; 3625 3626 private: 3627 __cache_type* _M_data; 3628 3629 public: 3630 /// This value is provided by the standard, but no reason for its 3631 /// existence. 3632 static const bool intl = _Intl; 3633 /// Numpunct facet id. 3634 static locale::id id; 3635 3636 /** 3637 * @brief Constructor performs initialization. 3638 * 3639 * This is the constructor provided by the standard. 3640 * 3641 * @param refs Passed to the base facet class. 3642 */ 3643 explicit 3644 moneypunct(size_t __refs = 0) : facet(__refs), _M_data(NULL) 3645 { _M_initialize_moneypunct(); } 3646 3647 /** 3648 * @brief Constructor performs initialization. 3649 * 3650 * This is an internal constructor. 3651 * 3652 * @param cache Cache for optimization. 3653 * @param refs Passed to the base facet class. 3654 */ 3655 explicit 3656 moneypunct(__cache_type* __cache, size_t __refs = 0) 3657 : facet(__refs), _M_data(__cache) 3658 { _M_initialize_moneypunct(); } 3659 3660 /** 3661 * @brief Internal constructor. Not for general use. 3662 * 3663 * This is a constructor for use by the library itself to set up new 3664 * locales. 3665 * 3666 * @param cloc The "C" locale. 3667 * @param s The name of a locale. 3668 * @param refs Passed to the base facet class. 3669 */ 3670 explicit 3671 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0) 3672 : facet(__refs), _M_data(NULL) 3673 { _M_initialize_moneypunct(__cloc, __s); } 3674 3675 /** 3676 * @brief Return decimal point character. 3677 * 3678 * This function returns a char_type to use as a decimal point. It 3679 * does so by returning returning 3680 * moneypunct<char_type>::do_decimal_point(). 3681 * 3682 * @return @a char_type representing a decimal point. 3683 */ 3684 char_type 3685 decimal_point() const 3686 { return this->do_decimal_point(); } 3687 3688 /** 3689 * @brief Return thousands separator character. 3690 * 3691 * This function returns a char_type to use as a thousands 3692 * separator. It does so by returning returning 3693 * moneypunct<char_type>::do_thousands_sep(). 3694 * 3695 * @return char_type representing a thousands separator. 3696 */ 3697 char_type 3698 thousands_sep() const 3699 { return this->do_thousands_sep(); } 3700 3701 /** 3702 * @brief Return grouping specification. 3703 * 3704 * This function returns a string representing groupings for the 3705 * integer part of an amount. Groupings indicate where thousands 3706 * separators should be inserted. 3707 * 3708 * Each char in the return string is interpret as an integer rather 3709 * than a character. These numbers represent the number of digits in a 3710 * group. The first char in the string represents the number of digits 3711 * in the least significant group. If a char is negative, it indicates 3712 * an unlimited number of digits for the group. If more chars from the 3713 * string are required to group a number, the last char is used 3714 * repeatedly. 3715 * 3716 * For example, if the grouping() returns "\003\002" and is applied to 3717 * the number 123456789, this corresponds to 12,34,56,789. Note that 3718 * if the string was "32", this would put more than 50 digits into the 3719 * least significant group if the character set is ASCII. 3720 * 3721 * The string is returned by calling 3722 * moneypunct<char_type>::do_grouping(). 3723 * 3724 * @return string representing grouping specification. 3725 */ 3726 string 3727 grouping() const 3728 { return this->do_grouping(); } 3729 3730 /** 3731 * @brief Return currency symbol string. 3732 * 3733 * This function returns a string_type to use as a currency symbol. It 3734 * does so by returning returning 3735 * moneypunct<char_type>::do_curr_symbol(). 3736 * 3737 * @return @a string_type representing a currency symbol. 3738 */ 3739 string_type 3740 curr_symbol() const 3741 { return this->do_curr_symbol(); } 3742 3743 /** 3744 * @brief Return positive sign string. 3745 * 3746 * This function returns a string_type to use as a sign for positive 3747 * amounts. It does so by returning returning 3748 * moneypunct<char_type>::do_positive_sign(). 3749 * 3750 * If the return value contains more than one character, the first 3751 * character appears in the position indicated by pos_format() and the 3752 * remainder appear at the end of the formatted string. 3753 * 3754 * @return @a string_type representing a positive sign. 3755 */ 3756 string_type 3757 positive_sign() const 3758 { return this->do_positive_sign(); } 3759 3760 /** 3761 * @brief Return negative sign string. 3762 * 3763 * This function returns a string_type to use as a sign for negative 3764 * amounts. It does so by returning returning 3765 * moneypunct<char_type>::do_negative_sign(). 3766 * 3767 * If the return value contains more than one character, the first 3768 * character appears in the position indicated by neg_format() and the 3769 * remainder appear at the end of the formatted string. 3770 * 3771 * @return @a string_type representing a negative sign. 3772 */ 3773 string_type 3774 negative_sign() const 3775 { return this->do_negative_sign(); } 3776 3777 /** 3778 * @brief Return number of digits in fraction. 3779 * 3780 * This function returns the exact number of digits that make up the 3781 * fractional part of a money amount. It does so by returning 3782 * returning moneypunct<char_type>::do_frac_digits(). 3783 * 3784 * The fractional part of a money amount is optional. But if it is 3785 * present, there must be frac_digits() digits. 3786 * 3787 * @return Number of digits in amount fraction. 3788 */ 3789 int 3790 frac_digits() const 3791 { return this->do_frac_digits(); } 3792 3793 //@{ 3794 /** 3795 * @brief Return pattern for money values. 3796 * 3797 * This function returns a pattern describing the formatting of a 3798 * positive or negative valued money amount. It does so by returning 3799 * returning moneypunct<char_type>::do_pos_format() or 3800 * moneypunct<char_type>::do_neg_format(). 3801 * 3802 * The pattern has 4 fields describing the ordering of symbol, sign, 3803 * value, and none or space. There must be one of each in the pattern. 3804 * The none and space enums may not appear in the first field and space 3805 * may not appear in the final field. 3806 * 3807 * The parts of a money string must appear in the order indicated by 3808 * the fields of the pattern. The symbol field indicates that the 3809 * value of curr_symbol() may be present. The sign field indicates 3810 * that the value of positive_sign() or negative_sign() must be 3811 * present. The value field indicates that the absolute value of the 3812 * money amount is present. none indicates 0 or more whitespace 3813 * characters, except at the end, where it permits no whitespace. 3814 * space indicates that 1 or more whitespace characters must be 3815 * present. 3816 * 3817 * For example, for the US locale and pos_format() pattern 3818 * {symbol,sign,value,none}, curr_symbol() == '$' positive_sign() == 3819 * '+', and value 10.01, and options set to force the symbol, the 3820 * corresponding string is "$+10.01". 3821 * 3822 * @return Pattern for money values. 3823 */ 3824 pattern 3825 pos_format() const 3826 { return this->do_pos_format(); } 3827 3828 pattern 3829 neg_format() const 3830 { return this->do_neg_format(); } 3831 //@} 3832 3833 protected: 3834 /// Destructor. 3835 virtual 3836 ~moneypunct(); 3837 3838 /** 3839 * @brief Return decimal point character. 3840 * 3841 * Returns a char_type to use as a decimal point. This function is a 3842 * hook for derived classes to change the value returned. 3843 * 3844 * @return @a char_type representing a decimal point. 3845 */ 3846 virtual char_type 3847 do_decimal_point() const 3848 { return _M_data->_M_decimal_point; } 3849 3850 /** 3851 * @brief Return thousands separator character. 3852 * 3853 * Returns a char_type to use as a thousands separator. This function 3854 * is a hook for derived classes to change the value returned. 3855 * 3856 * @return @a char_type representing a thousands separator. 3857 */ 3858 virtual char_type 3859 do_thousands_sep() const 3860 { return _M_data->_M_thousands_sep; } 3861 3862 /** 3863 * @brief Return grouping specification. 3864 * 3865 * Returns a string representing groupings for the integer part of a 3866 * number. This function is a hook for derived classes to change the 3867 * value returned. @see grouping() for details. 3868 * 3869 * @return String representing grouping specification. 3870 */ 3871 virtual string 3872 do_grouping() const 3873 { return _M_data->_M_grouping; } 3874 3875 /** 3876 * @brief Return currency symbol string. 3877 * 3878 * This function returns a string_type to use as a currency symbol. 3879 * This function is a hook for derived classes to change the value 3880 * returned. @see curr_symbol() for details. 3881 * 3882 * @return @a string_type representing a currency symbol. 3883 */ 3884 virtual string_type 3885 do_curr_symbol() const 3886 { return _M_data->_M_curr_symbol; } 3887 3888 /** 3889 * @brief Return positive sign string. 3890 * 3891 * This function returns a string_type to use as a sign for positive 3892 * amounts. This function is a hook for derived classes to change the 3893 * value returned. @see positive_sign() for details. 3894 * 3895 * @return @a string_type representing a positive sign. 3896 */ 3897 virtual string_type 3898 do_positive_sign() const 3899 { return _M_data->_M_positive_sign; } 3900 3901 /** 3902 * @brief Return negative sign string. 3903 * 3904 * This function returns a string_type to use as a sign for negative 3905 * amounts. This function is a hook for derived classes to change the 3906 * value returned. @see negative_sign() for details. 3907 * 3908 * @return @a string_type representing a negative sign. 3909 */ 3910 virtual string_type 3911 do_negative_sign() const 3912 { return _M_data->_M_negative_sign; } 3913 3914 /** 3915 * @brief Return number of digits in fraction. 3916 * 3917 * This function returns the exact number of digits that make up the 3918 * fractional part of a money amount. This function is a hook for 3919 * derived classes to change the value returned. @see frac_digits() 3920 * for details. 3921 * 3922 * @return Number of digits in amount fraction. 3923 */ 3924 virtual int 3925 do_frac_digits() const 3926 { return _M_data->_M_frac_digits; } 3927 3928 /** 3929 * @brief Return pattern for money values. 3930 * 3931 * This function returns a pattern describing the formatting of a 3932 * positive valued money amount. This function is a hook for derived 3933 * classes to change the value returned. @see pos_format() for 3934 * details. 3935 * 3936 * @return Pattern for money values. 3937 */ 3938 virtual pattern 3939 do_pos_format() const 3940 { return _M_data->_M_pos_format; } 3941 3942 /** 3943 * @brief Return pattern for money values. 3944 * 3945 * This function returns a pattern describing the formatting of a 3946 * negative valued money amount. This function is a hook for derived 3947 * classes to change the value returned. @see neg_format() for 3948 * details. 3949 * 3950 * @return Pattern for money values. 3951 */ 3952 virtual pattern 3953 do_neg_format() const 3954 { return _M_data->_M_neg_format; } 3955 3956 // For use at construction time only. 3957 void 3958 _M_initialize_moneypunct(__c_locale __cloc = NULL, 3959 const char* __name = NULL); 3960 }; 3961 3962 template<typename _CharT, bool _Intl> 3963 locale::id moneypunct<_CharT, _Intl>::id; 3964 3965 template<typename _CharT, bool _Intl> 3966 const bool moneypunct<_CharT, _Intl>::intl; 3967 3968 template<> 3969 moneypunct<char, true>::~moneypunct(); 3970 3971 template<> 3972 moneypunct<char, false>::~moneypunct(); 3973 3974 template<> 3975 void 3976 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*); 3977 3978 template<> 3979 void 3980 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*); 3981 3982#ifdef _GLIBCXX_USE_WCHAR_T 3983 template<> 3984 moneypunct<wchar_t, true>::~moneypunct(); 3985 3986 template<> 3987 moneypunct<wchar_t, false>::~moneypunct(); 3988 3989 template<> 3990 void 3991 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale, 3992 const char*); 3993 3994 template<> 3995 void 3996 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale, 3997 const char*); 3998#endif 3999 4000 /// @brief class moneypunct_byname [22.2.6.4]. 4001 template<typename _CharT, bool _Intl> 4002 class moneypunct_byname : public moneypunct<_CharT, _Intl> 4003 { 4004 public: 4005 typedef _CharT char_type; 4006 typedef basic_string<_CharT> string_type; 4007 4008 static const bool intl = _Intl; 4009 4010 explicit 4011 moneypunct_byname(const char* __s, size_t __refs = 0) 4012 : moneypunct<_CharT, _Intl>(__refs) 4013 { 4014 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0) 4015 { 4016 __c_locale __tmp; 4017 this->_S_create_c_locale(__tmp, __s); 4018 this->_M_initialize_moneypunct(__tmp); 4019 this->_S_destroy_c_locale(__tmp); 4020 } 4021 } 4022 4023 protected: 4024 virtual 4025 ~moneypunct_byname() { } 4026 }; 4027 4028 template<typename _CharT, bool _Intl> 4029 const bool moneypunct_byname<_CharT, _Intl>::intl; 4030 4031_GLIBCXX_BEGIN_LDBL_NAMESPACE 4032 /** 4033 * @brief Facet for parsing monetary amounts. 4034 * 4035 * This facet encapsulates the code to parse and return a monetary 4036 * amount from a string. 4037 * 4038 * The money_get template uses protected virtual functions to 4039 * provide the actual results. The public accessors forward the 4040 * call to the virtual functions. These virtual functions are 4041 * hooks for developers to implement the behavior they require from 4042 * the money_get facet. 4043 */ 4044 template<typename _CharT, typename _InIter> 4045 class money_get : public locale::facet 4046 { 4047 public: 4048 // Types: 4049 //@{ 4050 /// Public typedefs 4051 typedef _CharT char_type; 4052 typedef _InIter iter_type; 4053 typedef basic_string<_CharT> string_type; 4054 //@} 4055 4056 /// Numpunct facet id. 4057 static locale::id id; 4058 4059 /** 4060 * @brief Constructor performs initialization. 4061 * 4062 * This is the constructor provided by the standard. 4063 * 4064 * @param refs Passed to the base facet class. 4065 */ 4066 explicit 4067 money_get(size_t __refs = 0) : facet(__refs) { } 4068 4069 /** 4070 * @brief Read and parse a monetary value. 4071 * 4072 * This function reads characters from @a s, interprets them as a 4073 * monetary value according to moneypunct and ctype facets retrieved 4074 * from io.getloc(), and returns the result in @a units as an integral 4075 * value moneypunct::frac_digits() * the actual amount. For example, 4076 * the string $10.01 in a US locale would store 1001 in @a units. 4077 * 4078 * Any characters not part of a valid money amount are not consumed. 4079 * 4080 * If a money value cannot be parsed from the input stream, sets 4081 * err=(err|io.failbit). If the stream is consumed before finishing 4082 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is 4083 * unchanged if parsing fails. 4084 * 4085 * This function works by returning the result of do_get(). 4086 * 4087 * @param s Start of characters to parse. 4088 * @param end End of characters to parse. 4089 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 4090 * @param io Source of facets and io state. 4091 * @param err Error field to set if parsing fails. 4092 * @param units Place to store result of parsing. 4093 * @return Iterator referencing first character beyond valid money 4094 * amount. 4095 */ 4096 iter_type 4097 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 4098 ios_base::iostate& __err, long double& __units) const 4099 { return this->do_get(__s, __end, __intl, __io, __err, __units); } 4100 4101 /** 4102 * @brief Read and parse a monetary value. 4103 * 4104 * This function reads characters from @a s, interprets them as a 4105 * monetary value according to moneypunct and ctype facets retrieved 4106 * from io.getloc(), and returns the result in @a digits. For example, 4107 * the string $10.01 in a US locale would store "1001" in @a digits. 4108 * 4109 * Any characters not part of a valid money amount are not consumed. 4110 * 4111 * If a money value cannot be parsed from the input stream, sets 4112 * err=(err|io.failbit). If the stream is consumed before finishing 4113 * parsing, sets err=(err|io.failbit|io.eofbit). 4114 * 4115 * This function works by returning the result of do_get(). 4116 * 4117 * @param s Start of characters to parse. 4118 * @param end End of characters to parse. 4119 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 4120 * @param io Source of facets and io state. 4121 * @param err Error field to set if parsing fails. 4122 * @param digits Place to store result of parsing. 4123 * @return Iterator referencing first character beyond valid money 4124 * amount. 4125 */ 4126 iter_type 4127 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 4128 ios_base::iostate& __err, string_type& __digits) const 4129 { return this->do_get(__s, __end, __intl, __io, __err, __digits); } 4130 4131 protected: 4132 /// Destructor. 4133 virtual 4134 ~money_get() { } 4135 4136 /** 4137 * @brief Read and parse a monetary value. 4138 * 4139 * This function reads and parses characters representing a monetary 4140 * value. This function is a hook for derived classes to change the 4141 * value returned. @see get() for details. 4142 */ 4143 // XXX GLIBCXX_ABI Deprecated 4144#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 4145 virtual iter_type 4146 __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 4147 ios_base::iostate& __err, double& __units) const; 4148#else 4149 virtual iter_type 4150 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 4151 ios_base::iostate& __err, long double& __units) const; 4152#endif 4153 4154 /** 4155 * @brief Read and parse a monetary value. 4156 * 4157 * This function reads and parses characters representing a monetary 4158 * value. This function is a hook for derived classes to change the 4159 * value returned. @see get() for details. 4160 */ 4161 virtual iter_type 4162 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 4163 ios_base::iostate& __err, string_type& __digits) const; 4164 4165 // XXX GLIBCXX_ABI Deprecated 4166#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 4167 virtual iter_type 4168 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, 4169 ios_base::iostate& __err, long double& __units) const; 4170#endif 4171 4172 template<bool _Intl> 4173 iter_type 4174 _M_extract(iter_type __s, iter_type __end, ios_base& __io, 4175 ios_base::iostate& __err, string& __digits) const; 4176 }; 4177 4178 template<typename _CharT, typename _InIter> 4179 locale::id money_get<_CharT, _InIter>::id; 4180 4181 /** 4182 * @brief Facet for outputting monetary amounts. 4183 * 4184 * This facet encapsulates the code to format and output a monetary 4185 * amount. 4186 * 4187 * The money_put template uses protected virtual functions to 4188 * provide the actual results. The public accessors forward the 4189 * call to the virtual functions. These virtual functions are 4190 * hooks for developers to implement the behavior they require from 4191 * the money_put facet. 4192 */ 4193 template<typename _CharT, typename _OutIter> 4194 class money_put : public locale::facet 4195 { 4196 public: 4197 //@{ 4198 /// Public typedefs 4199 typedef _CharT char_type; 4200 typedef _OutIter iter_type; 4201 typedef basic_string<_CharT> string_type; 4202 //@} 4203 4204 /// Numpunct facet id. 4205 static locale::id id; 4206 4207 /** 4208 * @brief Constructor performs initialization. 4209 * 4210 * This is the constructor provided by the standard. 4211 * 4212 * @param refs Passed to the base facet class. 4213 */ 4214 explicit 4215 money_put(size_t __refs = 0) : facet(__refs) { } 4216 4217 /** 4218 * @brief Format and output a monetary value. 4219 * 4220 * This function formats @a units as a monetary value according to 4221 * moneypunct and ctype facets retrieved from io.getloc(), and writes 4222 * the resulting characters to @a s. For example, the value 1001 in a 4223 * US locale would write "$10.01" to @a s. 4224 * 4225 * This function works by returning the result of do_put(). 4226 * 4227 * @param s The stream to write to. 4228 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 4229 * @param io Source of facets and io state. 4230 * @param fill char_type to use for padding. 4231 * @param units Place to store result of parsing. 4232 * @return Iterator after writing. 4233 */ 4234 iter_type 4235 put(iter_type __s, bool __intl, ios_base& __io, 4236 char_type __fill, long double __units) const 4237 { return this->do_put(__s, __intl, __io, __fill, __units); } 4238 4239 /** 4240 * @brief Format and output a monetary value. 4241 * 4242 * This function formats @a digits as a monetary value according to 4243 * moneypunct and ctype facets retrieved from io.getloc(), and writes 4244 * the resulting characters to @a s. For example, the string "1001" in 4245 * a US locale would write "$10.01" to @a s. 4246 * 4247 * This function works by returning the result of do_put(). 4248 * 4249 * @param s The stream to write to. 4250 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 4251 * @param io Source of facets and io state. 4252 * @param fill char_type to use for padding. 4253 * @param units Place to store result of parsing. 4254 * @return Iterator after writing. 4255 */ 4256 iter_type 4257 put(iter_type __s, bool __intl, ios_base& __io, 4258 char_type __fill, const string_type& __digits) const 4259 { return this->do_put(__s, __intl, __io, __fill, __digits); } 4260 4261 protected: 4262 /// Destructor. 4263 virtual 4264 ~money_put() { } 4265 4266 /** 4267 * @brief Format and output a monetary value. 4268 * 4269 * This function formats @a units as a monetary value according to 4270 * moneypunct and ctype facets retrieved from io.getloc(), and writes 4271 * the resulting characters to @a s. For example, the value 1001 in a 4272 * US locale would write "$10.01" to @a s. 4273 * 4274 * This function is a hook for derived classes to change the value 4275 * returned. @see put(). 4276 * 4277 * @param s The stream to write to. 4278 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 4279 * @param io Source of facets and io state. 4280 * @param fill char_type to use for padding. 4281 * @param units Place to store result of parsing. 4282 * @return Iterator after writing. 4283 */ 4284 // XXX GLIBCXX_ABI Deprecated 4285#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 4286 virtual iter_type 4287 __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 4288 double __units) const; 4289#else 4290 virtual iter_type 4291 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 4292 long double __units) const; 4293#endif 4294 4295 /** 4296 * @brief Format and output a monetary value. 4297 * 4298 * This function formats @a digits as a monetary value according to 4299 * moneypunct and ctype facets retrieved from io.getloc(), and writes 4300 * the resulting characters to @a s. For example, the string "1001" in 4301 * a US locale would write "$10.01" to @a s. 4302 * 4303 * This function is a hook for derived classes to change the value 4304 * returned. @see put(). 4305 * 4306 * @param s The stream to write to. 4307 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. 4308 * @param io Source of facets and io state. 4309 * @param fill char_type to use for padding. 4310 * @param units Place to store result of parsing. 4311 * @return Iterator after writing. 4312 */ 4313 virtual iter_type 4314 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 4315 const string_type& __digits) const; 4316 4317 // XXX GLIBCXX_ABI Deprecated 4318#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ 4319 virtual iter_type 4320 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, 4321 long double __units) const; 4322#endif 4323 4324 template<bool _Intl> 4325 iter_type 4326 _M_insert(iter_type __s, ios_base& __io, char_type __fill, 4327 const string_type& __digits) const; 4328 }; 4329 4330 template<typename _CharT, typename _OutIter> 4331 locale::id money_put<_CharT, _OutIter>::id; 4332 4333_GLIBCXX_END_LDBL_NAMESPACE 4334 4335 /** 4336 * @brief Messages facet base class providing catalog typedef. 4337 */ 4338 class messages_base 4339 { 4340 public: 4341 typedef int catalog; 4342 }; 4343 4344 /** 4345 * @brief Facet for handling message catalogs 4346 * 4347 * This facet encapsulates the code to retrieve messages from 4348 * message catalogs. The only thing defined by the standard for this facet 4349 * is the interface. All underlying functionality is 4350 * implementation-defined. 4351 * 4352 * This library currently implements 3 versions of the message facet. The 4353 * first version (gnu) is a wrapper around gettext, provided by libintl. 4354 * The second version (ieee) is a wrapper around catgets. The final 4355 * version (default) does no actual translation. These implementations are 4356 * only provided for char and wchar_t instantiations. 4357 * 4358 * The messages template uses protected virtual functions to 4359 * provide the actual results. The public accessors forward the 4360 * call to the virtual functions. These virtual functions are 4361 * hooks for developers to implement the behavior they require from 4362 * the messages facet. 4363 */ 4364 template<typename _CharT> 4365 class messages : public locale::facet, public messages_base 4366 { 4367 public: 4368 // Types: 4369 //@{ 4370 /// Public typedefs 4371 typedef _CharT char_type; 4372 typedef basic_string<_CharT> string_type; 4373 //@} 4374 4375 protected: 4376 // Underlying "C" library locale information saved from 4377 // initialization, needed by messages_byname as well. 4378 __c_locale _M_c_locale_messages; 4379 const char* _M_name_messages; 4380 4381 public: 4382 /// Numpunct facet id. 4383 static locale::id id; 4384 4385 /** 4386 * @brief Constructor performs initialization. 4387 * 4388 * This is the constructor provided by the standard. 4389 * 4390 * @param refs Passed to the base facet class. 4391 */ 4392 explicit 4393 messages(size_t __refs = 0); 4394 4395 // Non-standard. 4396 /** 4397 * @brief Internal constructor. Not for general use. 4398 * 4399 * This is a constructor for use by the library itself to set up new 4400 * locales. 4401 * 4402 * @param cloc The "C" locale. 4403 * @param s The name of a locale. 4404 * @param refs Refcount to pass to the base class. 4405 */ 4406 explicit 4407 messages(__c_locale __cloc, const char* __s, size_t __refs = 0); 4408 4409 /* 4410 * @brief Open a message catalog. 4411 * 4412 * This function opens and returns a handle to a message catalog by 4413 * returning do_open(s, loc). 4414 * 4415 * @param s The catalog to open. 4416 * @param loc Locale to use for character set conversions. 4417 * @return Handle to the catalog or value < 0 if open fails. 4418 */ 4419 catalog 4420 open(const basic_string<char>& __s, const locale& __loc) const 4421 { return this->do_open(__s, __loc); } 4422 4423 // Non-standard and unorthodox, yet effective. 4424 /* 4425 * @brief Open a message catalog. 4426 * 4427 * This non-standard function opens and returns a handle to a message 4428 * catalog by returning do_open(s, loc). The third argument provides a 4429 * message catalog root directory for gnu gettext and is ignored 4430 * otherwise. 4431 * 4432 * @param s The catalog to open. 4433 * @param loc Locale to use for character set conversions. 4434 * @param dir Message catalog root directory. 4435 * @return Handle to the catalog or value < 0 if open fails. 4436 */ 4437 catalog 4438 open(const basic_string<char>&, const locale&, const char*) const; 4439 4440 /* 4441 * @brief Look up a string in a message catalog. 4442 * 4443 * This function retrieves and returns a message from a catalog by 4444 * returning do_get(c, set, msgid, s). 4445 * 4446 * For gnu, @a set and @a msgid are ignored. Returns gettext(s). 4447 * For default, returns s. For ieee, returns catgets(c,set,msgid,s). 4448 * 4449 * @param c The catalog to access. 4450 * @param set Implementation-defined. 4451 * @param msgid Implementation-defined. 4452 * @param s Default return value if retrieval fails. 4453 * @return Retrieved message or @a s if get fails. 4454 */ 4455 string_type 4456 get(catalog __c, int __set, int __msgid, const string_type& __s) const 4457 { return this->do_get(__c, __set, __msgid, __s); } 4458 4459 /* 4460 * @brief Close a message catalog. 4461 * 4462 * Closes catalog @a c by calling do_close(c). 4463 * 4464 * @param c The catalog to close. 4465 */ 4466 void 4467 close(catalog __c) const 4468 { return this->do_close(__c); } 4469 4470 protected: 4471 /// Destructor. 4472 virtual 4473 ~messages(); 4474 4475 /* 4476 * @brief Open a message catalog. 4477 * 4478 * This function opens and returns a handle to a message catalog in an 4479 * implementation-defined manner. This function is a hook for derived 4480 * classes to change the value returned. 4481 * 4482 * @param s The catalog to open. 4483 * @param loc Locale to use for character set conversions. 4484 * @return Handle to the opened catalog, value < 0 if open failed. 4485 */ 4486 virtual catalog 4487 do_open(const basic_string<char>&, const locale&) const; 4488 4489 /* 4490 * @brief Look up a string in a message catalog. 4491 * 4492 * This function retrieves and returns a message from a catalog in an 4493 * implementation-defined manner. This function is a hook for derived 4494 * classes to change the value returned. 4495 * 4496 * For gnu, @a set and @a msgid are ignored. Returns gettext(s). 4497 * For default, returns s. For ieee, returns catgets(c,set,msgid,s). 4498 * 4499 * @param c The catalog to access. 4500 * @param set Implementation-defined. 4501 * @param msgid Implementation-defined. 4502 * @param s Default return value if retrieval fails. 4503 * @return Retrieved message or @a s if get fails. 4504 */ 4505 virtual string_type 4506 do_get(catalog, int, int, const string_type& __dfault) const; 4507 4508 /* 4509 * @brief Close a message catalog. 4510 * 4511 * @param c The catalog to close. 4512 */ 4513 virtual void 4514 do_close(catalog) const; 4515 4516 // Returns a locale and codeset-converted string, given a char* message. 4517 char* 4518 _M_convert_to_char(const string_type& __msg) const 4519 { 4520 // XXX 4521 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str())); 4522 } 4523 4524 // Returns a locale and codeset-converted string, given a char* message. 4525 string_type 4526 _M_convert_from_char(char*) const 4527 { 4528#if 0 4529 // Length of message string without terminating null. 4530 size_t __len = char_traits<char>::length(__msg) - 1; 4531 4532 // "everybody can easily convert the string using 4533 // mbsrtowcs/wcsrtombs or with iconv()" 4534 4535 // Convert char* to _CharT in locale used to open catalog. 4536 // XXX need additional template parameter on messages class for this.. 4537 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type; 4538 typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type; 4539 4540 __codecvt_type::state_type __state; 4541 // XXX may need to initialize state. 4542 //initialize_state(__state._M_init()); 4543 4544 char* __from_next; 4545 // XXX what size for this string? 4546 _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1)); 4547 const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv); 4548 __cvt.out(__state, __msg, __msg + __len, __from_next, 4549 __to, __to + __len + 1, __to_next); 4550 return string_type(__to); 4551#endif 4552#if 0 4553 typedef ctype<_CharT> __ctype_type; 4554 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg); 4555 const __ctype_type& __cvt = use_facet<__ctype_type>(locale()); 4556 // XXX Again, proper length of converted string an issue here. 4557 // For now, assume the converted length is not larger. 4558 _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1)); 4559 __cvt.widen(__msg, __msg + __len, __dest); 4560 return basic_string<_CharT>(__dest); 4561#endif 4562 return string_type(); 4563 } 4564 }; 4565 4566 template<typename _CharT> 4567 locale::id messages<_CharT>::id; 4568 4569 // Specializations for required instantiations. 4570 template<> 4571 string 4572 messages<char>::do_get(catalog, int, int, const string&) const; 4573 4574#ifdef _GLIBCXX_USE_WCHAR_T 4575 template<> 4576 wstring 4577 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const; 4578#endif 4579 4580 /// @brief class messages_byname [22.2.7.2]. 4581 template<typename _CharT> 4582 class messages_byname : public messages<_CharT> 4583 { 4584 public: 4585 typedef _CharT char_type; 4586 typedef basic_string<_CharT> string_type; 4587 4588 explicit 4589 messages_byname(const char* __s, size_t __refs = 0); 4590 4591 protected: 4592 virtual 4593 ~messages_byname() 4594 { } 4595 }; 4596 4597_GLIBCXX_END_NAMESPACE 4598 4599 // Include host and configuration specific messages functions. 4600 #include <bits/messages_members.h> 4601 4602_GLIBCXX_BEGIN_NAMESPACE(std) 4603 4604 // Subclause convenience interfaces, inlines. 4605 // NB: These are inline because, when used in a loop, some compilers 4606 // can hoist the body out of the loop; then it's just as fast as the 4607 // C is*() function. 4608 4609 /// Convenience interface to ctype.is(ctype_base::space, __c). 4610 template<typename _CharT> 4611 inline bool 4612 isspace(_CharT __c, const locale& __loc) 4613 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); } 4614 4615 /// Convenience interface to ctype.is(ctype_base::print, __c). 4616 template<typename _CharT> 4617 inline bool 4618 isprint(_CharT __c, const locale& __loc) 4619 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); } 4620 4621 /// Convenience interface to ctype.is(ctype_base::cntrl, __c). 4622 template<typename _CharT> 4623 inline bool 4624 iscntrl(_CharT __c, const locale& __loc) 4625 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); } 4626 4627 /// Convenience interface to ctype.is(ctype_base::upper, __c). 4628 template<typename _CharT> 4629 inline bool 4630 isupper(_CharT __c, const locale& __loc) 4631 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); } 4632 4633 /// Convenience interface to ctype.is(ctype_base::lower, __c). 4634 template<typename _CharT> 4635 inline bool 4636 islower(_CharT __c, const locale& __loc) 4637 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); } 4638 4639 /// Convenience interface to ctype.is(ctype_base::alpha, __c). 4640 template<typename _CharT> 4641 inline bool 4642 isalpha(_CharT __c, const locale& __loc) 4643 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); } 4644 4645 /// Convenience interface to ctype.is(ctype_base::digit, __c). 4646 template<typename _CharT> 4647 inline bool 4648 isdigit(_CharT __c, const locale& __loc) 4649 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); } 4650 4651 /// Convenience interface to ctype.is(ctype_base::punct, __c). 4652 template<typename _CharT> 4653 inline bool 4654 ispunct(_CharT __c, const locale& __loc) 4655 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); } 4656 4657 /// Convenience interface to ctype.is(ctype_base::xdigit, __c). 4658 template<typename _CharT> 4659 inline bool 4660 isxdigit(_CharT __c, const locale& __loc) 4661 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); } 4662 4663 /// Convenience interface to ctype.is(ctype_base::alnum, __c). 4664 template<typename _CharT> 4665 inline bool 4666 isalnum(_CharT __c, const locale& __loc) 4667 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); } 4668 4669 /// Convenience interface to ctype.is(ctype_base::graph, __c). 4670 template<typename _CharT> 4671 inline bool 4672 isgraph(_CharT __c, const locale& __loc) 4673 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); } 4674 4675 /// Convenience interface to ctype.toupper(__c). 4676 template<typename _CharT> 4677 inline _CharT 4678 toupper(_CharT __c, const locale& __loc) 4679 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); } 4680 4681 /// Convenience interface to ctype.tolower(__c). 4682 template<typename _CharT> 4683 inline _CharT 4684 tolower(_CharT __c, const locale& __loc) 4685 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); } 4686 4687_GLIBCXX_END_NAMESPACE 4688 4689#endif 4690