STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
locale_facets.h
Go to the documentation of this file.
1 // Locale support -*- C++ -*-
2 
3 // Copyright (C) 1997-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
30 //
31 // ISO C++ 14882: 22.1 Locales
32 //
33 
34 #ifndef _LOCALE_FACETS_H
35 #define _LOCALE_FACETS_H 1
36 
37 #pragma GCC system_header
38 
39 #include <cwctype> // For wctype_t
40 #include <cctype>
41 #include <bits/ctype_base.h>
42 #include <iosfwd>
43 #include <bits/ios_base.h> // For ios_base, ios_base::iostate
44 #include <streambuf>
45 #include <bits/cpp_type_traits.h>
46 #include <ext/type_traits.h>
47 #include <ext/numeric_traits.h>
49 
50 namespace std _GLIBCXX_VISIBILITY(default)
51 {
52 _GLIBCXX_BEGIN_NAMESPACE_VERSION
53 
54  // NB: Don't instantiate required wchar_t facets if no wchar_t support.
55 #ifdef _GLIBCXX_USE_WCHAR_T
56 # define _GLIBCXX_NUM_FACETS 28
57 #else
58 # define _GLIBCXX_NUM_FACETS 14
59 #endif
60 
61  // Convert string to numeric value of type _Tp and store results.
62  // NB: This is specialized for all required types, there is no
63  // generic definition.
64  template<typename _Tp>
65  void
66  __convert_to_v(const char*, _Tp&, ios_base::iostate&,
67  const __c_locale&) throw();
68 
69  // Explicit specializations for required types.
70  template<>
71  void
72  __convert_to_v(const char*, float&, ios_base::iostate&,
73  const __c_locale&) throw();
74 
75  template<>
76  void
77  __convert_to_v(const char*, double&, ios_base::iostate&,
78  const __c_locale&) throw();
79 
80  template<>
81  void
82  __convert_to_v(const char*, long double&, ios_base::iostate&,
83  const __c_locale&) throw();
84 
85  // NB: __pad is a struct, rather than a function, so it can be
86  // partially-specialized.
87  template<typename _CharT, typename _Traits>
88  struct __pad
89  {
90  static void
91  _S_pad(ios_base& __io, _CharT __fill, _CharT* __news,
92  const _CharT* __olds, streamsize __newlen, streamsize __oldlen);
93  };
94 
95  // Used by both numeric and monetary facets.
96  // Inserts "group separator" characters into an array of characters.
97  // It's recursive, one iteration per group. It moves the characters
98  // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
99  // only with __gsize != 0.
100  template<typename _CharT>
101  _CharT*
102  __add_grouping(_CharT* __s, _CharT __sep,
103  const char* __gbeg, size_t __gsize,
104  const _CharT* __first, const _CharT* __last);
105 
106  // This template permits specializing facet output code for
107  // ostreambuf_iterator. For ostreambuf_iterator, sputn is
108  // significantly more efficient than incrementing iterators.
109  template<typename _CharT>
110  inline
111  ostreambuf_iterator<_CharT>
112  __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len)
113  {
114  __s._M_put(__ws, __len);
115  return __s;
116  }
117 
118  // This is the unspecialized form of the template.
119  template<typename _CharT, typename _OutIter>
120  inline
121  _OutIter
122  __write(_OutIter __s, const _CharT* __ws, int __len)
123  {
124  for (int __j = 0; __j < __len; __j++, ++__s)
125  *__s = __ws[__j];
126  return __s;
127  }
128 
129 
130  // 22.2.1.1 Template class ctype
131  // Include host and configuration specific ctype enums for ctype_base.
132 
142  template<typename _CharT>
143  class __ctype_abstract_base : public locale::facet, public ctype_base
144  {
145  public:
146  // Types:
148  typedef _CharT char_type;
149 
161  bool
162  is(mask __m, char_type __c) const
163  { return this->do_is(__m, __c); }
164 
178  const char_type*
179  is(const char_type *__lo, const char_type *__hi, mask *__vec) const
180  { return this->do_is(__lo, __hi, __vec); }
181 
194  const char_type*
195  scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
196  { return this->do_scan_is(__m, __lo, __hi); }
197 
210  const char_type*
211  scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
212  { return this->do_scan_not(__m, __lo, __hi); }
213 
224  char_type
225  toupper(char_type __c) const
226  { return this->do_toupper(__c); }
227 
239  const char_type*
240  toupper(char_type *__lo, const char_type* __hi) const
241  { return this->do_toupper(__lo, __hi); }
242 
253  char_type
254  tolower(char_type __c) const
255  { return this->do_tolower(__c); }
256 
268  const char_type*
269  tolower(char_type* __lo, const char_type* __hi) const
270  { return this->do_tolower(__lo, __hi); }
271 
285  char_type
286  widen(char __c) const
287  { return this->do_widen(__c); }
288 
304  const char*
305  widen(const char* __lo, const char* __hi, char_type* __to) const
306  { return this->do_widen(__lo, __hi, __to); }
307 
323  char
324  narrow(char_type __c, char __dfault) const
325  { return this->do_narrow(__c, __dfault); }
326 
345  const char_type*
346  narrow(const char_type* __lo, const char_type* __hi,
347  char __dfault, char* __to) const
348  { return this->do_narrow(__lo, __hi, __dfault, __to); }
349 
350  protected:
351  explicit
352  __ctype_abstract_base(size_t __refs = 0): facet(__refs) { }
353 
354  virtual
355  ~__ctype_abstract_base() { }
356 
370  virtual bool
371  do_is(mask __m, char_type __c) const = 0;
372 
389  virtual const char_type*
390  do_is(const char_type* __lo, const char_type* __hi,
391  mask* __vec) const = 0;
392 
408  virtual const char_type*
409  do_scan_is(mask __m, const char_type* __lo,
410  const char_type* __hi) const = 0;
411 
427  virtual const char_type*
428  do_scan_not(mask __m, const char_type* __lo,
429  const char_type* __hi) const = 0;
430 
445  virtual char_type
446  do_toupper(char_type __c) const = 0;
447 
462  virtual const char_type*
463  do_toupper(char_type* __lo, const char_type* __hi) const = 0;
464 
478  virtual char_type
479  do_tolower(char_type __c) const = 0;
480 
495  virtual const char_type*
496  do_tolower(char_type* __lo, const char_type* __hi) const = 0;
497 
514  virtual char_type
515  do_widen(char __c) const = 0;
516 
535  virtual const char*
536  do_widen(const char* __lo, const char* __hi, char_type* __to) const = 0;
537 
556  virtual char
557  do_narrow(char_type __c, char __dfault) const = 0;
558 
581  virtual const char_type*
582  do_narrow(const char_type* __lo, const char_type* __hi,
583  char __dfault, char* __to) const = 0;
584  };
585 
604  template<typename _CharT>
605  class ctype : public __ctype_abstract_base<_CharT>
606  {
607  public:
608  // Types:
609  typedef _CharT char_type;
610  typedef typename __ctype_abstract_base<_CharT>::mask mask;
611 
613  static locale::id id;
614 
615  explicit
616  ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
617 
618  protected:
619  virtual
620  ~ctype();
621 
622  virtual bool
623  do_is(mask __m, char_type __c) const;
624 
625  virtual const char_type*
626  do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
627 
628  virtual const char_type*
629  do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
630 
631  virtual const char_type*
632  do_scan_not(mask __m, const char_type* __lo,
633  const char_type* __hi) const;
634 
635  virtual char_type
636  do_toupper(char_type __c) const;
637 
638  virtual const char_type*
639  do_toupper(char_type* __lo, const char_type* __hi) const;
640 
641  virtual char_type
642  do_tolower(char_type __c) const;
643 
644  virtual const char_type*
645  do_tolower(char_type* __lo, const char_type* __hi) const;
646 
647  virtual char_type
648  do_widen(char __c) const;
649 
650  virtual const char*
651  do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
652 
653  virtual char
654  do_narrow(char_type, char __dfault) const;
655 
656  virtual const char_type*
657  do_narrow(const char_type* __lo, const char_type* __hi,
658  char __dfault, char* __to) const;
659  };
660 
661  template<typename _CharT>
663 
673  template<>
674  class ctype<char> : public locale::facet, public ctype_base
675  {
676  public:
677  // Types:
679  typedef char char_type;
680 
681  protected:
682  // Data Members:
683  __c_locale _M_c_locale_ctype;
684  bool _M_del;
685  __to_type _M_toupper;
686  __to_type _M_tolower;
687  const mask* _M_table;
688  mutable char _M_widen_ok;
689  mutable char _M_widen[1 + static_cast<unsigned char>(-1)];
690  mutable char _M_narrow[1 + static_cast<unsigned char>(-1)];
691  mutable char _M_narrow_ok; // 0 uninitialized, 1 init,
692  // 2 memcpy can't be used
693 
694  public:
696  static locale::id id;
698  static const size_t table_size = 1 + static_cast<unsigned char>(-1);
699 
710  explicit
711  ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
712 
723  explicit
724  ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
725  size_t __refs = 0);
726 
736  inline bool
737  is(mask __m, char __c) const;
738 
751  inline const char*
752  is(const char* __lo, const char* __hi, mask* __vec) const;
753 
765  inline const char*
766  scan_is(mask __m, const char* __lo, const char* __hi) const;
767 
779  inline const char*
780  scan_not(mask __m, const char* __lo, const char* __hi) const;
781 
794  char_type
795  toupper(char_type __c) const
796  { return this->do_toupper(__c); }
797 
811  const char_type*
812  toupper(char_type *__lo, const char_type* __hi) const
813  { return this->do_toupper(__lo, __hi); }
814 
827  char_type
828  tolower(char_type __c) const
829  { return this->do_tolower(__c); }
830 
844  const char_type*
845  tolower(char_type* __lo, const char_type* __hi) const
846  { return this->do_tolower(__lo, __hi); }
847 
864  char_type
865  widen(char __c) const
866  {
867  if (_M_widen_ok)
868  return _M_widen[static_cast<unsigned char>(__c)];
869  this->_M_widen_init();
870  return this->do_widen(__c);
871  }
872 
891  const char*
892  widen(const char* __lo, const char* __hi, char_type* __to) const
893  {
894  if (_M_widen_ok == 1)
895  {
896  __builtin_memcpy(__to, __lo, __hi - __lo);
897  return __hi;
898  }
899  if (!_M_widen_ok)
900  _M_widen_init();
901  return this->do_widen(__lo, __hi, __to);
902  }
903 
922  char
923  narrow(char_type __c, char __dfault) const
924  {
925  if (_M_narrow[static_cast<unsigned char>(__c)])
926  return _M_narrow[static_cast<unsigned char>(__c)];
927  const char __t = do_narrow(__c, __dfault);
928  if (__t != __dfault)
929  _M_narrow[static_cast<unsigned char>(__c)] = __t;
930  return __t;
931  }
932 
955  const char_type*
956  narrow(const char_type* __lo, const char_type* __hi,
957  char __dfault, char* __to) const
958  {
959  if (__builtin_expect(_M_narrow_ok == 1, true))
960  {
961  __builtin_memcpy(__to, __lo, __hi - __lo);
962  return __hi;
963  }
964  if (!_M_narrow_ok)
965  _M_narrow_init();
966  return this->do_narrow(__lo, __hi, __dfault, __to);
967  }
968 
969  // _GLIBCXX_RESOLVE_LIB_DEFECTS
970  // DR 695. ctype<char>::classic_table() not accessible.
973  const mask*
974  table() const throw()
975  { return _M_table; }
976 
978  static const mask*
979  classic_table() throw();
980  protected:
981 
988  virtual
989  ~ctype();
990 
1004  virtual char_type
1005  do_toupper(char_type __c) const;
1006 
1021  virtual const char_type*
1022  do_toupper(char_type* __lo, const char_type* __hi) const;
1023 
1037  virtual char_type
1038  do_tolower(char_type __c) const;
1039 
1054  virtual const char_type*
1055  do_tolower(char_type* __lo, const char_type* __hi) const;
1056 
1074  virtual char_type
1075  do_widen(char __c) const
1076  { return __c; }
1077 
1097  virtual const char*
1098  do_widen(const char* __lo, const char* __hi, char_type* __to) const
1099  {
1100  __builtin_memcpy(__to, __lo, __hi - __lo);
1101  return __hi;
1102  }
1103 
1123  virtual char
1124  do_narrow(char_type __c, char __dfault) const
1125  { return __c; }
1126 
1149  virtual const char_type*
1150  do_narrow(const char_type* __lo, const char_type* __hi,
1151  char __dfault, char* __to) const
1152  {
1153  __builtin_memcpy(__to, __lo, __hi - __lo);
1154  return __hi;
1155  }
1156 
1157  private:
1158  void _M_narrow_init() const;
1159  void _M_widen_init() const;
1160  };
1161 
1162 #ifdef _GLIBCXX_USE_WCHAR_T
1163 
1174  template<>
1175  class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
1176  {
1177  public:
1178  // Types:
1180  typedef wchar_t char_type;
1181  typedef wctype_t __wmask_type;
1182 
1183  protected:
1184  __c_locale _M_c_locale_ctype;
1185 
1186  // Pre-computed narrowed and widened chars.
1187  bool _M_narrow_ok;
1188  char _M_narrow[128];
1189  wint_t _M_widen[1 + static_cast<unsigned char>(-1)];
1190 
1191  // Pre-computed elements for do_is.
1192  mask _M_bit[16];
1193  __wmask_type _M_wmask[16];
1194 
1195  public:
1196  // Data Members:
1198  static locale::id id;
1199 
1207  explicit
1208  ctype(size_t __refs = 0);
1209 
1218  explicit
1219  ctype(__c_locale __cloc, size_t __refs = 0);
1220 
1221  protected:
1222  __wmask_type
1223  _M_convert_to_wmask(const mask __m) const throw();
1224 
1226  virtual
1227  ~ctype();
1228 
1242  virtual bool
1243  do_is(mask __m, char_type __c) const;
1244 
1261  virtual const char_type*
1262  do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
1263 
1279  virtual const char_type*
1280  do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
1281 
1297  virtual const char_type*
1298  do_scan_not(mask __m, const char_type* __lo,
1299  const char_type* __hi) const;
1300 
1314  virtual char_type
1315  do_toupper(char_type __c) const;
1316 
1331  virtual const char_type*
1332  do_toupper(char_type* __lo, const char_type* __hi) const;
1333 
1347  virtual char_type
1348  do_tolower(char_type __c) const;
1349 
1364  virtual const char_type*
1365  do_tolower(char_type* __lo, const char_type* __hi) const;
1366 
1384  virtual char_type
1385  do_widen(char __c) const;
1386 
1406  virtual const char*
1407  do_widen(const char* __lo, const char* __hi, char_type* __to) const;
1408 
1429  virtual char
1430  do_narrow(char_type __c, char __dfault) const;
1431 
1455  virtual const char_type*
1456  do_narrow(const char_type* __lo, const char_type* __hi,
1457  char __dfault, char* __to) const;
1458 
1459  // For use at construction time only.
1460  void
1461  _M_initialize_ctype() throw();
1462  };
1463 #endif //_GLIBCXX_USE_WCHAR_T
1464 
1466  template<typename _CharT>
1467  class ctype_byname : public ctype<_CharT>
1468  {
1469  public:
1470  typedef typename ctype<_CharT>::mask mask;
1471 
1472  explicit
1473  ctype_byname(const char* __s, size_t __refs = 0);
1474 
1475  protected:
1476  virtual
1477  ~ctype_byname() { };
1478  };
1479 
1481  template<>
1482  class ctype_byname<char> : public ctype<char>
1483  {
1484  public:
1485  explicit
1486  ctype_byname(const char* __s, size_t __refs = 0);
1487 
1488  protected:
1489  virtual
1490  ~ctype_byname();
1491  };
1492 
1493 #ifdef _GLIBCXX_USE_WCHAR_T
1494  template<>
1495  class ctype_byname<wchar_t> : public ctype<wchar_t>
1496  {
1497  public:
1498  explicit
1499  ctype_byname(const char* __s, size_t __refs = 0);
1500 
1501  protected:
1502  virtual
1503  ~ctype_byname();
1504  };
1505 #endif
1506 
1507 _GLIBCXX_END_NAMESPACE_VERSION
1508 } // namespace
1509 
1510 // Include host and configuration specific ctype inlines.
1511 #include <bits/ctype_inline.h>
1512 
1513 namespace std _GLIBCXX_VISIBILITY(default)
1514 {
1515 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1516 
1517  // 22.2.2 The numeric category.
1518  class __num_base
1519  {
1520  public:
1521  // NB: Code depends on the order of _S_atoms_out elements.
1522  // Below are the indices into _S_atoms_out.
1523  enum
1524  {
1525  _S_ominus,
1526  _S_oplus,
1527  _S_ox,
1528  _S_oX,
1529  _S_odigits,
1530  _S_odigits_end = _S_odigits + 16,
1531  _S_oudigits = _S_odigits_end,
1532  _S_oudigits_end = _S_oudigits + 16,
1533  _S_oe = _S_odigits + 14, // For scientific notation, 'e'
1534  _S_oE = _S_oudigits + 14, // For scientific notation, 'E'
1535  _S_oend = _S_oudigits_end
1536  };
1537 
1538  // A list of valid numeric literals for output. This array
1539  // contains chars that will be passed through the current locale's
1540  // ctype<_CharT>.widen() and then used to render numbers.
1541  // For the standard "C" locale, this is
1542  // "-+xX0123456789abcdef0123456789ABCDEF".
1543  static const char* _S_atoms_out;
1544 
1545  // String literal of acceptable (narrow) input, for num_get.
1546  // "-+xX0123456789abcdefABCDEF"
1547  static const char* _S_atoms_in;
1548 
1549  enum
1550  {
1551  _S_iminus,
1552  _S_iplus,
1553  _S_ix,
1554  _S_iX,
1555  _S_izero,
1556  _S_ie = _S_izero + 14,
1557  _S_iE = _S_izero + 20,
1558  _S_iend = 26
1559  };
1560 
1561  // num_put
1562  // Construct and return valid scanf format for floating point types.
1563  static void
1564  _S_format_float(const ios_base& __io, char* __fptr, char __mod) throw();
1565  };
1566 
1567  template<typename _CharT>
1568  struct __numpunct_cache : public locale::facet
1569  {
1570  const char* _M_grouping;
1571  size_t _M_grouping_size;
1572  bool _M_use_grouping;
1573  const _CharT* _M_truename;
1574  size_t _M_truename_size;
1575  const _CharT* _M_falsename;
1576  size_t _M_falsename_size;
1577  _CharT _M_decimal_point;
1578  _CharT _M_thousands_sep;
1579 
1580  // A list of valid numeric literals for output: in the standard
1581  // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1582  // This array contains the chars after having been passed
1583  // through the current locale's ctype<_CharT>.widen().
1584  _CharT _M_atoms_out[__num_base::_S_oend];
1585 
1586  // A list of valid numeric literals for input: in the standard
1587  // "C" locale, this is "-+xX0123456789abcdefABCDEF"
1588  // This array contains the chars after having been passed
1589  // through the current locale's ctype<_CharT>.widen().
1590  _CharT _M_atoms_in[__num_base::_S_iend];
1591 
1592  bool _M_allocated;
1593 
1594  __numpunct_cache(size_t __refs = 0)
1595  : facet(__refs), _M_grouping(0), _M_grouping_size(0),
1596  _M_use_grouping(false),
1597  _M_truename(0), _M_truename_size(0), _M_falsename(0),
1598  _M_falsename_size(0), _M_decimal_point(_CharT()),
1599  _M_thousands_sep(_CharT()), _M_allocated(false)
1600  { }
1601 
1602  ~__numpunct_cache();
1603 
1604  void
1605  _M_cache(const locale& __loc);
1606 
1607  private:
1608  __numpunct_cache&
1609  operator=(const __numpunct_cache&);
1610 
1611  explicit
1612  __numpunct_cache(const __numpunct_cache&);
1613  };
1614 
1615  template<typename _CharT>
1616  __numpunct_cache<_CharT>::~__numpunct_cache()
1617  {
1618  if (_M_allocated)
1619  {
1620  delete [] _M_grouping;
1621  delete [] _M_truename;
1622  delete [] _M_falsename;
1623  }
1624  }
1625 
1640  template<typename _CharT>
1641  class numpunct : public locale::facet
1642  {
1643  public:
1644  // Types:
1646  typedef _CharT char_type;
1648  typedef basic_string<_CharT> string_type;
1650  typedef __numpunct_cache<_CharT> __cache_type;
1651 
1652  protected:
1653  __cache_type* _M_data;
1654 
1655  public:
1657  static locale::id id;
1658 
1664  explicit
1665  numpunct(size_t __refs = 0)
1666  : facet(__refs), _M_data(0)
1667  { _M_initialize_numpunct(); }
1668 
1678  explicit
1679  numpunct(__cache_type* __cache, size_t __refs = 0)
1680  : facet(__refs), _M_data(__cache)
1681  { _M_initialize_numpunct(); }
1682 
1692  explicit
1693  numpunct(__c_locale __cloc, size_t __refs = 0)
1694  : facet(__refs), _M_data(0)
1695  { _M_initialize_numpunct(__cloc); }
1696 
1706  char_type
1707  decimal_point() const
1708  { return this->do_decimal_point(); }
1709 
1719  char_type
1720  thousands_sep() const
1721  { return this->do_thousands_sep(); }
1722 
1750  string
1751  grouping() const
1752  { return this->do_grouping(); }
1753 
1763  string_type
1764  truename() const
1765  { return this->do_truename(); }
1766 
1776  string_type
1777  falsename() const
1778  { return this->do_falsename(); }
1779 
1780  protected:
1782  virtual
1783  ~numpunct();
1784 
1793  virtual char_type
1794  do_decimal_point() const
1795  { return _M_data->_M_decimal_point; }
1796 
1805  virtual char_type
1806  do_thousands_sep() const
1807  { return _M_data->_M_thousands_sep; }
1808 
1818  virtual string
1819  do_grouping() const
1820  { return _M_data->_M_grouping; }
1821 
1831  virtual string_type
1832  do_truename() const
1833  { return _M_data->_M_truename; }
1834 
1844  virtual string_type
1845  do_falsename() const
1846  { return _M_data->_M_falsename; }
1847 
1848  // For use at construction time only.
1849  void
1850  _M_initialize_numpunct(__c_locale __cloc = 0);
1851  };
1852 
1853  template<typename _CharT>
1855 
1856  template<>
1857  numpunct<char>::~numpunct();
1858 
1859  template<>
1860  void
1861  numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
1862 
1863 #ifdef _GLIBCXX_USE_WCHAR_T
1864  template<>
1865  numpunct<wchar_t>::~numpunct();
1866 
1867  template<>
1868  void
1869  numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
1870 #endif
1871 
1873  template<typename _CharT>
1874  class numpunct_byname : public numpunct<_CharT>
1875  {
1876  public:
1877  typedef _CharT char_type;
1878  typedef basic_string<_CharT> string_type;
1879 
1880  explicit
1881  numpunct_byname(const char* __s, size_t __refs = 0)
1882  : numpunct<_CharT>(__refs)
1883  {
1884  if (__builtin_strcmp(__s, "C") != 0
1885  && __builtin_strcmp(__s, "POSIX") != 0)
1886  {
1887  __c_locale __tmp;
1888  this->_S_create_c_locale(__tmp, __s);
1889  this->_M_initialize_numpunct(__tmp);
1890  this->_S_destroy_c_locale(__tmp);
1891  }
1892  }
1893 
1894  protected:
1895  virtual
1896  ~numpunct_byname() { }
1897  };
1898 
1899 _GLIBCXX_BEGIN_NAMESPACE_LDBL
1900 
1914  template<typename _CharT, typename _InIter>
1915  class num_get : public locale::facet
1916  {
1917  public:
1918  // Types:
1920  typedef _CharT char_type;
1922  typedef _InIter iter_type;
1924 
1926  static locale::id id;
1927 
1935  explicit
1936  num_get(size_t __refs = 0) : facet(__refs) { }
1937 
1961  iter_type
1962  get(iter_type __in, iter_type __end, ios_base& __io,
1963  ios_base::iostate& __err, bool& __v) const
1964  { return this->do_get(__in, __end, __io, __err, __v); }
1965 
1967 
1998  iter_type
1999  get(iter_type __in, iter_type __end, ios_base& __io,
2000  ios_base::iostate& __err, long& __v) const
2001  { return this->do_get(__in, __end, __io, __err, __v); }
2002 
2003  iter_type
2004  get(iter_type __in, iter_type __end, ios_base& __io,
2005  ios_base::iostate& __err, unsigned short& __v) const
2006  { return this->do_get(__in, __end, __io, __err, __v); }
2007 
2008  iter_type
2009  get(iter_type __in, iter_type __end, ios_base& __io,
2010  ios_base::iostate& __err, unsigned int& __v) const
2011  { return this->do_get(__in, __end, __io, __err, __v); }
2012 
2013  iter_type
2014  get(iter_type __in, iter_type __end, ios_base& __io,
2015  ios_base::iostate& __err, unsigned long& __v) const
2016  { return this->do_get(__in, __end, __io, __err, __v); }
2017 
2018 #ifdef _GLIBCXX_USE_LONG_LONG
2019  iter_type
2020  get(iter_type __in, iter_type __end, ios_base& __io,
2021  ios_base::iostate& __err, long long& __v) const
2022  { return this->do_get(__in, __end, __io, __err, __v); }
2023 
2024  iter_type
2025  get(iter_type __in, iter_type __end, ios_base& __io,
2026  ios_base::iostate& __err, unsigned long long& __v) const
2027  { return this->do_get(__in, __end, __io, __err, __v); }
2028 #endif
2029 
2030 
2032 
2058  iter_type
2059  get(iter_type __in, iter_type __end, ios_base& __io,
2060  ios_base::iostate& __err, float& __v) const
2061  { return this->do_get(__in, __end, __io, __err, __v); }
2062 
2063  iter_type
2064  get(iter_type __in, iter_type __end, ios_base& __io,
2065  ios_base::iostate& __err, double& __v) const
2066  { return this->do_get(__in, __end, __io, __err, __v); }
2067 
2068  iter_type
2069  get(iter_type __in, iter_type __end, ios_base& __io,
2070  ios_base::iostate& __err, long double& __v) const
2071  { return this->do_get(__in, __end, __io, __err, __v); }
2073 
2101  iter_type
2102  get(iter_type __in, iter_type __end, ios_base& __io,
2103  ios_base::iostate& __err, void*& __v) const
2104  { return this->do_get(__in, __end, __io, __err, __v); }
2105 
2106  protected:
2108  virtual ~num_get() { }
2109 
2110  iter_type
2111  _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
2112  string&) const;
2113 
2114  template<typename _ValueT>
2115  iter_type
2116  _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
2117  _ValueT&) const;
2118 
2119  template<typename _CharT2>
2120  typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, int>::__type
2121  _M_find(const _CharT2*, size_t __len, _CharT2 __c) const
2122  {
2123  int __ret = -1;
2124  if (__len <= 10)
2125  {
2126  if (__c >= _CharT2('0') && __c < _CharT2(_CharT2('0') + __len))
2127  __ret = __c - _CharT2('0');
2128  }
2129  else
2130  {
2131  if (__c >= _CharT2('0') && __c <= _CharT2('9'))
2132  __ret = __c - _CharT2('0');
2133  else if (__c >= _CharT2('a') && __c <= _CharT2('f'))
2134  __ret = 10 + (__c - _CharT2('a'));
2135  else if (__c >= _CharT2('A') && __c <= _CharT2('F'))
2136  __ret = 10 + (__c - _CharT2('A'));
2137  }
2138  return __ret;
2139  }
2140 
2141  template<typename _CharT2>
2142  typename __gnu_cxx::__enable_if<!__is_char<_CharT2>::__value,
2143  int>::__type
2144  _M_find(const _CharT2* __zero, size_t __len, _CharT2 __c) const
2145  {
2146  int __ret = -1;
2147  const char_type* __q = char_traits<_CharT2>::find(__zero, __len, __c);
2148  if (__q)
2149  {
2150  __ret = __q - __zero;
2151  if (__ret > 15)
2152  __ret -= 6;
2153  }
2154  return __ret;
2155  }
2156 
2158 
2172  virtual iter_type
2173  do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
2174 
2175  virtual iter_type
2176  do_get(iter_type __beg, iter_type __end, ios_base& __io,
2177  ios_base::iostate& __err, long& __v) const
2178  { return _M_extract_int(__beg, __end, __io, __err, __v); }
2179 
2180  virtual iter_type
2181  do_get(iter_type __beg, iter_type __end, ios_base& __io,
2182  ios_base::iostate& __err, unsigned short& __v) const
2183  { return _M_extract_int(__beg, __end, __io, __err, __v); }
2184 
2185  virtual iter_type
2186  do_get(iter_type __beg, iter_type __end, ios_base& __io,
2187  ios_base::iostate& __err, unsigned int& __v) const
2188  { return _M_extract_int(__beg, __end, __io, __err, __v); }
2189 
2190  virtual iter_type
2191  do_get(iter_type __beg, iter_type __end, ios_base& __io,
2192  ios_base::iostate& __err, unsigned long& __v) const
2193  { return _M_extract_int(__beg, __end, __io, __err, __v); }
2194 
2195 #ifdef _GLIBCXX_USE_LONG_LONG
2196  virtual iter_type
2197  do_get(iter_type __beg, iter_type __end, ios_base& __io,
2198  ios_base::iostate& __err, long long& __v) const
2199  { return _M_extract_int(__beg, __end, __io, __err, __v); }
2200 
2201  virtual iter_type
2202  do_get(iter_type __beg, iter_type __end, ios_base& __io,
2203  ios_base::iostate& __err, unsigned long long& __v) const
2204  { return _M_extract_int(__beg, __end, __io, __err, __v); }
2205 #endif
2206 
2207  virtual iter_type
2208  do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, float&) const;
2209 
2210  virtual iter_type
2211  do_get(iter_type, iter_type, ios_base&, ios_base::iostate&,
2212  double&) const;
2213 
2214  // XXX GLIBCXX_ABI Deprecated
2215 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2216  virtual iter_type
2217  __do_get(iter_type, iter_type, ios_base&, ios_base::iostate&,
2218  double&) const;
2219 #else
2220  virtual iter_type
2221  do_get(iter_type, iter_type, ios_base&, ios_base::iostate&,
2222  long double&) const;
2223 #endif
2224 
2225  virtual iter_type
2226  do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, void*&) const;
2227 
2228  // XXX GLIBCXX_ABI Deprecated
2229 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2230  virtual iter_type
2231  do_get(iter_type, iter_type, ios_base&, ios_base::iostate&,
2232  long double&) const;
2233 #endif
2234 
2235  };
2236 
2237  template<typename _CharT, typename _InIter>
2239 
2240 
2253  template<typename _CharT, typename _OutIter>
2254  class num_put : public locale::facet
2255  {
2256  public:
2257  // Types:
2259  typedef _CharT char_type;
2261  typedef _OutIter iter_type;
2263 
2265  static locale::id id;
2266 
2274  explicit
2275  num_put(size_t __refs = 0) : facet(__refs) { }
2276 
2292  iter_type
2293  put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const
2294  { return this->do_put(__s, __io, __fill, __v); }
2295 
2297 
2334  iter_type
2335  put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
2336  { return this->do_put(__s, __io, __fill, __v); }
2337 
2338  iter_type
2339  put(iter_type __s, ios_base& __io, char_type __fill,
2340  unsigned long __v) const
2341  { return this->do_put(__s, __io, __fill, __v); }
2342 
2343 #ifdef _GLIBCXX_USE_LONG_LONG
2344  iter_type
2345  put(iter_type __s, ios_base& __io, char_type __fill, long long __v) const
2346  { return this->do_put(__s, __io, __fill, __v); }
2347 
2348  iter_type
2349  put(iter_type __s, ios_base& __io, char_type __fill,
2350  unsigned long long __v) const
2351  { return this->do_put(__s, __io, __fill, __v); }
2352 #endif
2353 
2354 
2356 
2397  iter_type
2398  put(iter_type __s, ios_base& __io, char_type __fill, double __v) const
2399  { return this->do_put(__s, __io, __fill, __v); }
2400 
2401  iter_type
2402  put(iter_type __s, ios_base& __io, char_type __fill,
2403  long double __v) const
2404  { return this->do_put(__s, __io, __fill, __v); }
2406 
2422  iter_type
2423  put(iter_type __s, ios_base& __io, char_type __fill,
2424  const void* __v) const
2425  { return this->do_put(__s, __io, __fill, __v); }
2426 
2427  protected:
2428  template<typename _ValueT>
2429  iter_type
2430  _M_insert_float(iter_type, ios_base& __io, char_type __fill,
2431  char __mod, _ValueT __v) const;
2432 
2433  void
2434  _M_group_float(const char* __grouping, size_t __grouping_size,
2435  char_type __sep, const char_type* __p, char_type* __new,
2436  char_type* __cs, int& __len) const;
2437 
2438  template<typename _ValueT>
2439  iter_type
2440  _M_insert_int(iter_type, ios_base& __io, char_type __fill,
2441  _ValueT __v) const;
2442 
2443  void
2444  _M_group_int(const char* __grouping, size_t __grouping_size,
2445  char_type __sep, ios_base& __io, char_type* __new,
2446  char_type* __cs, int& __len) const;
2447 
2448  void
2449  _M_pad(char_type __fill, streamsize __w, ios_base& __io,
2450  char_type* __new, const char_type* __cs, int& __len) const;
2451 
2453  virtual
2454  ~num_put() { };
2455 
2457 
2470  virtual iter_type
2471  do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const;
2472 
2473  virtual iter_type
2474  do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
2475  { return _M_insert_int(__s, __io, __fill, __v); }
2476 
2477  virtual iter_type
2478  do_put(iter_type __s, ios_base& __io, char_type __fill,
2479  unsigned long __v) const
2480  { return _M_insert_int(__s, __io, __fill, __v); }
2481 
2482 #ifdef _GLIBCXX_USE_LONG_LONG
2483  virtual iter_type
2484  do_put(iter_type __s, ios_base& __io, char_type __fill,
2485  long long __v) const
2486  { return _M_insert_int(__s, __io, __fill, __v); }
2487 
2488  virtual iter_type
2489  do_put(iter_type __s, ios_base& __io, char_type __fill,
2490  unsigned long long __v) const
2491  { return _M_insert_int(__s, __io, __fill, __v); }
2492 #endif
2493 
2494  virtual iter_type
2495  do_put(iter_type, ios_base&, char_type, double) const;
2496 
2497  // XXX GLIBCXX_ABI Deprecated
2498 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2499  virtual iter_type
2500  __do_put(iter_type, ios_base&, char_type, double) const;
2501 #else
2502  virtual iter_type
2503  do_put(iter_type, ios_base&, char_type, long double) const;
2504 #endif
2505 
2506  virtual iter_type
2507  do_put(iter_type, ios_base&, char_type, const void*) const;
2508 
2509  // XXX GLIBCXX_ABI Deprecated
2510 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2511  virtual iter_type
2512  do_put(iter_type, ios_base&, char_type, long double) const;
2513 #endif
2514 
2515  };
2516 
2517  template <typename _CharT, typename _OutIter>
2519 
2520 _GLIBCXX_END_NAMESPACE_LDBL
2521 
2522  // Subclause convenience interfaces, inlines.
2523  // NB: These are inline because, when used in a loop, some compilers
2524  // can hoist the body out of the loop; then it's just as fast as the
2525  // C is*() function.
2526 
2528  template<typename _CharT>
2529  inline bool
2530  isspace(_CharT __c, const locale& __loc)
2531  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
2532 
2534  template<typename _CharT>
2535  inline bool
2536  isprint(_CharT __c, const locale& __loc)
2537  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
2538 
2540  template<typename _CharT>
2541  inline bool
2542  iscntrl(_CharT __c, const locale& __loc)
2543  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
2544 
2546  template<typename _CharT>
2547  inline bool
2548  isupper(_CharT __c, const locale& __loc)
2549  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
2550 
2552  template<typename _CharT>
2553  inline bool
2554  islower(_CharT __c, const locale& __loc)
2555  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
2556 
2558  template<typename _CharT>
2559  inline bool
2560  isalpha(_CharT __c, const locale& __loc)
2561  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
2562 
2564  template<typename _CharT>
2565  inline bool
2566  isdigit(_CharT __c, const locale& __loc)
2567  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
2568 
2570  template<typename _CharT>
2571  inline bool
2572  ispunct(_CharT __c, const locale& __loc)
2573  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
2574 
2576  template<typename _CharT>
2577  inline bool
2578  isxdigit(_CharT __c, const locale& __loc)
2579  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
2580 
2582  template<typename _CharT>
2583  inline bool
2584  isalnum(_CharT __c, const locale& __loc)
2585  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
2586 
2588  template<typename _CharT>
2589  inline bool
2590  isgraph(_CharT __c, const locale& __loc)
2591  { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
2592 
2594  template<typename _CharT>
2595  inline _CharT
2596  toupper(_CharT __c, const locale& __loc)
2597  { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
2598 
2600  template<typename _CharT>
2601  inline _CharT
2602  tolower(_CharT __c, const locale& __loc)
2603  { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
2604 
2605 _GLIBCXX_END_NAMESPACE_VERSION
2606 } // namespace std
2607 
2608 # include <bits/locale_facets.tcc>
2609 
2610 #endif
void __write(FILE *__f, __stack_t __stack)
Definition: profiler_node.h:78
#define false
Definition: stdbool.h:35
namespace std _GLIBCXX_VISIBILITY(default)
Definition: auto_ptr.h:36
__WCHAR_TYPE__ wchar_t
Definition: stddef.h:324
struct objc_object * id
Definition: basic_string.h:45