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