libstdc++
locale_facets.h
Go to the documentation of this file.
00001 // Locale support -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
00004 // 2006, 2007, 2008, 2009, 2010, 2011
00005 // Free Software Foundation, Inc.
00006 //
00007 // This file is part of the GNU ISO C++ Library.  This library is free
00008 // software; you can redistribute it and/or modify it under the
00009 // terms of the GNU General Public License as published by the
00010 // Free Software Foundation; either version 3, or (at your option)
00011 // any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 
00018 // Under Section 7 of GPL version 3, you are granted additional
00019 // permissions described in the GCC Runtime Library Exception, version
00020 // 3.1, as published by the Free Software Foundation.
00021 
00022 // You should have received a copy of the GNU General Public License and
00023 // a copy of the GCC Runtime Library Exception along with this program;
00024 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00025 // <http://www.gnu.org/licenses/>.
00026 
00027 /** @file bits/locale_facets.h
00028  *  This is an internal header file, included by other library headers.
00029  *  Do not attempt to use it directly. @headername{locale}
00030  */
00031 
00032 //
00033 // ISO C++ 14882: 22.1  Locales
00034 //
00035 
00036 #ifndef _LOCALE_FACETS_H
00037 #define _LOCALE_FACETS_H 1
00038 
00039 #pragma GCC system_header
00040 
00041 #include <cwctype>  // For wctype_t
00042 #include <cctype>
00043 #include <bits/ctype_base.h>    
00044 #include <iosfwd>
00045 #include <bits/ios_base.h>  // For ios_base, ios_base::iostate
00046 #include <streambuf>
00047 #include <bits/cpp_type_traits.h>
00048 #include <ext/type_traits.h>
00049 #include <ext/numeric_traits.h>
00050 #include <bits/streambuf_iterator.h>
00051 
00052 namespace std _GLIBCXX_VISIBILITY(default)
00053 {
00054 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00055 
00056   // NB: Don't instantiate required wchar_t facets if no wchar_t support.
00057 #ifdef _GLIBCXX_USE_WCHAR_T
00058 # define  _GLIBCXX_NUM_FACETS 28
00059 #else
00060 # define  _GLIBCXX_NUM_FACETS 14
00061 #endif
00062 
00063   // Convert string to numeric value of type _Tp and store results.
00064   // NB: This is specialized for all required types, there is no
00065   // generic definition.
00066   template<typename _Tp>
00067     void
00068     __convert_to_v(const char*, _Tp&, ios_base::iostate&,
00069            const __c_locale&) throw();
00070 
00071   // Explicit specializations for required types.
00072   template<>
00073     void
00074     __convert_to_v(const char*, float&, ios_base::iostate&,
00075            const __c_locale&) throw();
00076 
00077   template<>
00078     void
00079     __convert_to_v(const char*, double&, ios_base::iostate&,
00080            const __c_locale&) throw();
00081 
00082   template<>
00083     void
00084     __convert_to_v(const char*, long double&, ios_base::iostate&,
00085            const __c_locale&) throw();
00086 
00087   // NB: __pad is a struct, rather than a function, so it can be
00088   // partially-specialized.
00089   template<typename _CharT, typename _Traits>
00090     struct __pad
00091     {
00092       static void
00093       _S_pad(ios_base& __io, _CharT __fill, _CharT* __news,
00094          const _CharT* __olds, streamsize __newlen, streamsize __oldlen);
00095     };
00096 
00097   // Used by both numeric and monetary facets.
00098   // Inserts "group separator" characters into an array of characters.
00099   // It's recursive, one iteration per group.  It moves the characters
00100   // in the buffer this way: "xxxx12345" -> "12,345xxx".  Call this
00101   // only with __gsize != 0.
00102   template<typename _CharT>
00103     _CharT*
00104     __add_grouping(_CharT* __s, _CharT __sep,
00105            const char* __gbeg, size_t __gsize,
00106            const _CharT* __first, const _CharT* __last);
00107 
00108   // This template permits specializing facet output code for
00109   // ostreambuf_iterator.  For ostreambuf_iterator, sputn is
00110   // significantly more efficient than incrementing iterators.
00111   template<typename _CharT>
00112     inline
00113     ostreambuf_iterator<_CharT>
00114     __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len)
00115     {
00116       __s._M_put(__ws, __len);
00117       return __s;
00118     }
00119 
00120   // This is the unspecialized form of the template.
00121   template<typename _CharT, typename _OutIter>
00122     inline
00123     _OutIter
00124     __write(_OutIter __s, const _CharT* __ws, int __len)
00125     {
00126       for (int __j = 0; __j < __len; __j++, ++__s)
00127     *__s = __ws[__j];
00128       return __s;
00129     }
00130 
00131 
00132   // 22.2.1.1  Template class ctype
00133   // Include host and configuration specific ctype enums for ctype_base.
00134 
00135   /**
00136    *  @brief  Common base for ctype facet
00137    *
00138    *  This template class provides implementations of the public functions
00139    *  that forward to the protected virtual functions.
00140    *
00141    *  This template also provides abstract stubs for the protected virtual
00142    *  functions.
00143   */
00144   template<typename _CharT>
00145     class __ctype_abstract_base : public locale::facet, public ctype_base
00146     {
00147     public:
00148       // Types:
00149       /// Typedef for the template parameter
00150       typedef _CharT char_type;
00151 
00152       /**
00153        *  @brief  Test char_type classification.
00154        *
00155        *  This function finds a mask M for @a c and compares it to mask @a m.
00156        *  It does so by returning the value of ctype<char_type>::do_is().
00157        *
00158        *  @param c  The char_type to compare the mask of.
00159        *  @param m  The mask to compare against.
00160        *  @return  (M & m) != 0.
00161       */
00162       bool
00163       is(mask __m, char_type __c) const
00164       { return this->do_is(__m, __c); }
00165 
00166       /**
00167        *  @brief  Return a mask array.
00168        *
00169        *  This function finds the mask for each char_type in the range [lo,hi)
00170        *  and successively writes it to vec.  vec must have as many elements
00171        *  as the char array.  It does so by returning the value of
00172        *  ctype<char_type>::do_is().
00173        *
00174        *  @param lo  Pointer to start of range.
00175        *  @param hi  Pointer to end of range.
00176        *  @param vec  Pointer to an array of mask storage.
00177        *  @return  @a hi.
00178       */
00179       const char_type*
00180       is(const char_type *__lo, const char_type *__hi, mask *__vec) const
00181       { return this->do_is(__lo, __hi, __vec); }
00182 
00183       /**
00184        *  @brief  Find char_type matching a mask
00185        *
00186        *  This function searches for and returns the first char_type c in
00187        *  [lo,hi) for which is(m,c) is true.  It does so by returning
00188        *  ctype<char_type>::do_scan_is().
00189        *
00190        *  @param m  The mask to compare against.
00191        *  @param lo  Pointer to start of range.
00192        *  @param hi  Pointer to end of range.
00193        *  @return  Pointer to matching char_type if found, else @a hi.
00194       */
00195       const char_type*
00196       scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
00197       { return this->do_scan_is(__m, __lo, __hi); }
00198 
00199       /**
00200        *  @brief  Find char_type not matching a mask
00201        *
00202        *  This function searches for and returns the first char_type c in
00203        *  [lo,hi) for which is(m,c) is false.  It does so by returning
00204        *  ctype<char_type>::do_scan_not().
00205        *
00206        *  @param m  The mask to compare against.
00207        *  @param lo  Pointer to first char in range.
00208        *  @param hi  Pointer to end of range.
00209        *  @return  Pointer to non-matching char if found, else @a hi.
00210       */
00211       const char_type*
00212       scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
00213       { return this->do_scan_not(__m, __lo, __hi); }
00214 
00215       /**
00216        *  @brief  Convert to uppercase.
00217        *
00218        *  This function converts the argument to uppercase if possible.
00219        *  If not possible (for example, '2'), returns the argument.  It does
00220        *  so by returning ctype<char_type>::do_toupper().
00221        *
00222        *  @param c  The char_type to convert.
00223        *  @return  The uppercase char_type if convertible, else @a c.
00224       */
00225       char_type
00226       toupper(char_type __c) const
00227       { return this->do_toupper(__c); }
00228 
00229       /**
00230        *  @brief  Convert array to uppercase.
00231        *
00232        *  This function converts each char_type in the range [lo,hi) to
00233        *  uppercase if possible.  Other elements remain untouched.  It does so
00234        *  by returning ctype<char_type>:: do_toupper(lo, hi).
00235        *
00236        *  @param lo  Pointer to start of range.
00237        *  @param hi  Pointer to end of range.
00238        *  @return  @a hi.
00239       */
00240       const char_type*
00241       toupper(char_type *__lo, const char_type* __hi) const
00242       { return this->do_toupper(__lo, __hi); }
00243 
00244       /**
00245        *  @brief  Convert to lowercase.
00246        *
00247        *  This function converts the argument to lowercase if possible.  If
00248        *  not possible (for example, '2'), returns the argument.  It does so
00249        *  by returning ctype<char_type>::do_tolower(c).
00250        *
00251        *  @param c  The char_type to convert.
00252        *  @return  The lowercase char_type if convertible, else @a c.
00253       */
00254       char_type
00255       tolower(char_type __c) const
00256       { return this->do_tolower(__c); }
00257 
00258       /**
00259        *  @brief  Convert array to lowercase.
00260        *
00261        *  This function converts each char_type in the range [lo,hi) to
00262        *  lowercase if possible.  Other elements remain untouched.  It does so
00263        *  by returning ctype<char_type>:: do_tolower(lo, hi).
00264        *
00265        *  @param lo  Pointer to start of range.
00266        *  @param hi  Pointer to end of range.
00267        *  @return  @a hi.
00268       */
00269       const char_type*
00270       tolower(char_type* __lo, const char_type* __hi) const
00271       { return this->do_tolower(__lo, __hi); }
00272 
00273       /**
00274        *  @brief  Widen char to char_type
00275        *
00276        *  This function converts the char argument to char_type using the
00277        *  simplest reasonable transformation.  It does so by returning
00278        *  ctype<char_type>::do_widen(c).
00279        *
00280        *  Note: this is not what you want for codepage conversions.  See
00281        *  codecvt for that.
00282        *
00283        *  @param c  The char to convert.
00284        *  @return  The converted char_type.
00285       */
00286       char_type
00287       widen(char __c) const
00288       { return this->do_widen(__c); }
00289 
00290       /**
00291        *  @brief  Widen array to char_type
00292        *
00293        *  This function converts each char in the input to char_type using the
00294        *  simplest reasonable transformation.  It does so by returning
00295        *  ctype<char_type>::do_widen(c).
00296        *
00297        *  Note: this is not what you want for codepage conversions.  See
00298        *  codecvt for that.
00299        *
00300        *  @param lo  Pointer to start of range.
00301        *  @param hi  Pointer to end of range.
00302        *  @param to  Pointer to the destination array.
00303        *  @return  @a hi.
00304       */
00305       const char*
00306       widen(const char* __lo, const char* __hi, char_type* __to) const
00307       { return this->do_widen(__lo, __hi, __to); }
00308 
00309       /**
00310        *  @brief  Narrow char_type to char
00311        *
00312        *  This function converts the char_type to char using the simplest
00313        *  reasonable transformation.  If the conversion fails, dfault is
00314        *  returned instead.  It does so by returning
00315        *  ctype<char_type>::do_narrow(c).
00316        *
00317        *  Note: this is not what you want for codepage conversions.  See
00318        *  codecvt for that.
00319        *
00320        *  @param c  The char_type to convert.
00321        *  @param dfault  Char to return if conversion fails.
00322        *  @return  The converted char.
00323       */
00324       char
00325       narrow(char_type __c, char __dfault) const
00326       { return this->do_narrow(__c, __dfault); }
00327 
00328       /**
00329        *  @brief  Narrow array to char array
00330        *
00331        *  This function converts each char_type in the input to char using the
00332        *  simplest reasonable transformation and writes the results to the
00333        *  destination array.  For any char_type in the input that cannot be
00334        *  converted, @a dfault is used instead.  It does so by returning
00335        *  ctype<char_type>::do_narrow(lo, hi, dfault, to).
00336        *
00337        *  Note: this is not what you want for codepage conversions.  See
00338        *  codecvt for that.
00339        *
00340        *  @param lo  Pointer to start of range.
00341        *  @param hi  Pointer to end of range.
00342        *  @param dfault  Char to use if conversion fails.
00343        *  @param to  Pointer to the destination array.
00344        *  @return  @a hi.
00345       */
00346       const char_type*
00347       narrow(const char_type* __lo, const char_type* __hi,
00348           char __dfault, char *__to) const
00349       { return this->do_narrow(__lo, __hi, __dfault, __to); }
00350 
00351     protected:
00352       explicit
00353       __ctype_abstract_base(size_t __refs = 0): facet(__refs) { }
00354 
00355       virtual
00356       ~__ctype_abstract_base() { }
00357 
00358       /**
00359        *  @brief  Test char_type classification.
00360        *
00361        *  This function finds a mask M for @a c and compares it to mask @a m.
00362        *
00363        *  do_is() is a hook for a derived facet to change the behavior of
00364        *  classifying.  do_is() must always return the same result for the
00365        *  same input.
00366        *
00367        *  @param c  The char_type to find the mask of.
00368        *  @param m  The mask to compare against.
00369        *  @return  (M & m) != 0.
00370       */
00371       virtual bool
00372       do_is(mask __m, char_type __c) const = 0;
00373 
00374       /**
00375        *  @brief  Return a mask array.
00376        *
00377        *  This function finds the mask for each char_type in the range [lo,hi)
00378        *  and successively writes it to vec.  vec must have as many elements
00379        *  as the input.
00380        *
00381        *  do_is() is a hook for a derived facet to change the behavior of
00382        *  classifying.  do_is() must always return the same result for the
00383        *  same input.
00384        *
00385        *  @param lo  Pointer to start of range.
00386        *  @param hi  Pointer to end of range.
00387        *  @param vec  Pointer to an array of mask storage.
00388        *  @return  @a hi.
00389       */
00390       virtual const char_type*
00391       do_is(const char_type* __lo, const char_type* __hi,
00392         mask* __vec) const = 0;
00393 
00394       /**
00395        *  @brief  Find char_type matching mask
00396        *
00397        *  This function searches for and returns the first char_type c in
00398        *  [lo,hi) for which is(m,c) is true.
00399        *
00400        *  do_scan_is() is a hook for a derived facet to change the behavior of
00401        *  match searching.  do_is() must always return the same result for the
00402        *  same input.
00403        *
00404        *  @param m  The mask to compare against.
00405        *  @param lo  Pointer to start of range.
00406        *  @param hi  Pointer to end of range.
00407        *  @return  Pointer to a matching char_type if found, else @a hi.
00408       */
00409       virtual const char_type*
00410       do_scan_is(mask __m, const char_type* __lo,
00411          const char_type* __hi) const = 0;
00412 
00413       /**
00414        *  @brief  Find char_type not matching mask
00415        *
00416        *  This function searches for and returns a pointer to the first
00417        *  char_type c of [lo,hi) for which is(m,c) is false.
00418        *
00419        *  do_scan_is() is a hook for a derived facet to change the behavior of
00420        *  match searching.  do_is() must always return the same result for the
00421        *  same input.
00422        *
00423        *  @param m  The mask to compare against.
00424        *  @param lo  Pointer to start of range.
00425        *  @param hi  Pointer to end of range.
00426        *  @return  Pointer to a non-matching char_type if found, else @a hi.
00427       */
00428       virtual const char_type*
00429       do_scan_not(mask __m, const char_type* __lo,
00430           const char_type* __hi) const = 0;
00431 
00432       /**
00433        *  @brief  Convert to uppercase.
00434        *
00435        *  This virtual function converts the char_type argument to uppercase
00436        *  if possible.  If not possible (for example, '2'), returns the
00437        *  argument.
00438        *
00439        *  do_toupper() is a hook for a derived facet to change the behavior of
00440        *  uppercasing.  do_toupper() must always return the same result for
00441        *  the same input.
00442        *
00443        *  @param c  The char_type to convert.
00444        *  @return  The uppercase char_type if convertible, else @a c.
00445       */
00446       virtual char_type
00447       do_toupper(char_type) const = 0;
00448 
00449       /**
00450        *  @brief  Convert array to uppercase.
00451        *
00452        *  This virtual function converts each char_type in the range [lo,hi)
00453        *  to uppercase if possible.  Other elements remain untouched.
00454        *
00455        *  do_toupper() is a hook for a derived facet to change the behavior of
00456        *  uppercasing.  do_toupper() must always return the same result for
00457        *  the same input.
00458        *
00459        *  @param lo  Pointer to start of range.
00460        *  @param hi  Pointer to end of range.
00461        *  @return  @a hi.
00462       */
00463       virtual const char_type*
00464       do_toupper(char_type* __lo, const char_type* __hi) const = 0;
00465 
00466       /**
00467        *  @brief  Convert to lowercase.
00468        *
00469        *  This virtual function converts the argument to lowercase if
00470        *  possible.  If not possible (for example, '2'), returns the argument.
00471        *
00472        *  do_tolower() is a hook for a derived facet to change the behavior of
00473        *  lowercasing.  do_tolower() must always return the same result for
00474        *  the same input.
00475        *
00476        *  @param c  The char_type to convert.
00477        *  @return  The lowercase char_type if convertible, else @a c.
00478       */
00479       virtual char_type
00480       do_tolower(char_type) const = 0;
00481 
00482       /**
00483        *  @brief  Convert array to lowercase.
00484        *
00485        *  This virtual function converts each char_type in the range [lo,hi)
00486        *  to lowercase if possible.  Other elements remain untouched.
00487        *
00488        *  do_tolower() is a hook for a derived facet to change the behavior of
00489        *  lowercasing.  do_tolower() must always return the same result for
00490        *  the same input.
00491        *
00492        *  @param lo  Pointer to start of range.
00493        *  @param hi  Pointer to end of range.
00494        *  @return  @a hi.
00495       */
00496       virtual const char_type*
00497       do_tolower(char_type* __lo, const char_type* __hi) const = 0;
00498 
00499       /**
00500        *  @brief  Widen char
00501        *
00502        *  This virtual function converts the char to char_type using the
00503        *  simplest reasonable transformation.
00504        *
00505        *  do_widen() is a hook for a derived facet to change the behavior of
00506        *  widening.  do_widen() must always return the same result for the
00507        *  same input.
00508        *
00509        *  Note: this is not what you want for codepage conversions.  See
00510        *  codecvt for that.
00511        *
00512        *  @param c  The char to convert.
00513        *  @return  The converted char_type
00514       */
00515       virtual char_type
00516       do_widen(char) const = 0;
00517 
00518       /**
00519        *  @brief  Widen char array
00520        *
00521        *  This function converts each char in the input to char_type using the
00522        *  simplest reasonable transformation.
00523        *
00524        *  do_widen() is a hook for a derived facet to change the behavior of
00525        *  widening.  do_widen() must always return the same result for the
00526        *  same input.
00527        *
00528        *  Note: this is not what you want for codepage conversions.  See
00529        *  codecvt for that.
00530        *
00531        *  @param lo  Pointer to start range.
00532        *  @param hi  Pointer to end of range.
00533        *  @param to  Pointer to the destination array.
00534        *  @return  @a hi.
00535       */
00536       virtual const char*
00537       do_widen(const char* __lo, const char* __hi,
00538            char_type* __dest) const = 0;
00539 
00540       /**
00541        *  @brief  Narrow char_type to char
00542        *
00543        *  This virtual function converts the argument to char using the
00544        *  simplest reasonable transformation.  If the conversion fails, dfault
00545        *  is returned instead.
00546        *
00547        *  do_narrow() is a hook for a derived facet to change the behavior of
00548        *  narrowing.  do_narrow() must always return the same result for the
00549        *  same input.
00550        *
00551        *  Note: this is not what you want for codepage conversions.  See
00552        *  codecvt for that.
00553        *
00554        *  @param c  The char_type to convert.
00555        *  @param dfault  Char to return if conversion fails.
00556        *  @return  The converted char.
00557       */
00558       virtual char
00559       do_narrow(char_type, char __dfault) const = 0;
00560 
00561       /**
00562        *  @brief  Narrow char_type array to char
00563        *
00564        *  This virtual function converts each char_type in the range [lo,hi) to
00565        *  char using the simplest reasonable transformation and writes the
00566        *  results to the destination array.  For any element in the input that
00567        *  cannot be converted, @a dfault is used instead.
00568        *
00569        *  do_narrow() is a hook for a derived facet to change the behavior of
00570        *  narrowing.  do_narrow() must always return the same result for the
00571        *  same input.
00572        *
00573        *  Note: this is not what you want for codepage conversions.  See
00574        *  codecvt for that.
00575        *
00576        *  @param lo  Pointer to start of range.
00577        *  @param hi  Pointer to end of range.
00578        *  @param dfault  Char to use if conversion fails.
00579        *  @param to  Pointer to the destination array.
00580        *  @return  @a hi.
00581       */
00582       virtual const char_type*
00583       do_narrow(const char_type* __lo, const char_type* __hi,
00584         char __dfault, char* __dest) const = 0;
00585     };
00586 
00587   /**
00588    *  @brief  Primary class template ctype facet.
00589    *  @ingroup locales
00590    *
00591    *  This template class defines classification and conversion functions for
00592    *  character sets.  It wraps cctype functionality.  Ctype gets used by
00593    *  streams for many I/O operations.
00594    *
00595    *  This template provides the protected virtual functions the developer
00596    *  will have to replace in a derived class or specialization to make a
00597    *  working facet.  The public functions that access them are defined in
00598    *  __ctype_abstract_base, to allow for implementation flexibility.  See
00599    *  ctype<wchar_t> for an example.  The functions are documented in
00600    *  __ctype_abstract_base.
00601    *
00602    *  Note: implementations are provided for all the protected virtual
00603    *  functions, but will likely not be useful.
00604   */
00605   template<typename _CharT>
00606     class ctype : public __ctype_abstract_base<_CharT>
00607     {
00608     public:
00609       // Types:
00610       typedef _CharT            char_type;
00611       typedef typename __ctype_abstract_base<_CharT>::mask mask;
00612 
00613       /// The facet id for ctype<char_type>
00614       static locale::id         id;
00615 
00616       explicit
00617       ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
00618 
00619    protected:
00620       virtual
00621       ~ctype();
00622 
00623       virtual bool
00624       do_is(mask __m, char_type __c) const;
00625 
00626       virtual const char_type*
00627       do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
00628 
00629       virtual const char_type*
00630       do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
00631 
00632       virtual const char_type*
00633       do_scan_not(mask __m, const char_type* __lo,
00634           const char_type* __hi) const;
00635 
00636       virtual char_type
00637       do_toupper(char_type __c) const;
00638 
00639       virtual const char_type*
00640       do_toupper(char_type* __lo, const char_type* __hi) const;
00641 
00642       virtual char_type
00643       do_tolower(char_type __c) const;
00644 
00645       virtual const char_type*
00646       do_tolower(char_type* __lo, const char_type* __hi) const;
00647 
00648       virtual char_type
00649       do_widen(char __c) const;
00650 
00651       virtual const char*
00652       do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
00653 
00654       virtual char
00655       do_narrow(char_type, char __dfault) const;
00656 
00657       virtual const char_type*
00658       do_narrow(const char_type* __lo, const char_type* __hi,
00659         char __dfault, char* __dest) const;
00660     };
00661 
00662   template<typename _CharT>
00663     locale::id ctype<_CharT>::id;
00664 
00665   /**
00666    *  @brief  The ctype<char> specialization.
00667    *  @ingroup locales
00668    *
00669    *  This class defines classification and conversion functions for
00670    *  the char type.  It gets used by char streams for many I/O
00671    *  operations.  The char specialization provides a number of
00672    *  optimizations as well.
00673   */
00674   template<>
00675     class ctype<char> : public locale::facet, public ctype_base
00676     {
00677     public:
00678       // Types:
00679       /// Typedef for the template parameter char.
00680       typedef char      char_type;
00681 
00682     protected:
00683       // Data Members:
00684       __c_locale        _M_c_locale_ctype;
00685       bool          _M_del;
00686       __to_type         _M_toupper;
00687       __to_type         _M_tolower;
00688       const mask*       _M_table;
00689       mutable char      _M_widen_ok;
00690       mutable char      _M_widen[1 + static_cast<unsigned char>(-1)];
00691       mutable char      _M_narrow[1 + static_cast<unsigned char>(-1)];
00692       mutable char      _M_narrow_ok;   // 0 uninitialized, 1 init,
00693                         // 2 memcpy can't be used
00694 
00695     public:
00696       /// The facet id for ctype<char>
00697       static locale::id        id;
00698       /// The size of the mask table.  It is SCHAR_MAX + 1.
00699       static const size_t      table_size = 1 + static_cast<unsigned char>(-1);
00700 
00701       /**
00702        *  @brief  Constructor performs initialization.
00703        *
00704        *  This is the constructor provided by the standard.
00705        *
00706        *  @param table If non-zero, table is used as the per-char mask.
00707        *               Else classic_table() is used.
00708        *  @param del   If true, passes ownership of table to this facet.
00709        *  @param refs  Passed to the base facet class.
00710       */
00711       explicit
00712       ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
00713 
00714       /**
00715        *  @brief  Constructor performs static initialization.
00716        *
00717        *  This constructor is used to construct the initial C locale facet.
00718        *
00719        *  @param cloc  Handle to C locale data.
00720        *  @param table If non-zero, table is used as the per-char mask.
00721        *  @param del   If true, passes ownership of table to this facet.
00722        *  @param refs  Passed to the base facet class.
00723       */
00724       explicit
00725       ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
00726         size_t __refs = 0);
00727 
00728       /**
00729        *  @brief  Test char classification.
00730        *
00731        *  This function compares the mask table[c] to @a m.
00732        *
00733        *  @param c  The char to compare the mask of.
00734        *  @param m  The mask to compare against.
00735        *  @return  True if m & table[c] is true, false otherwise.
00736       */
00737       inline bool
00738       is(mask __m, char __c) const;
00739 
00740       /**
00741        *  @brief  Return a mask array.
00742        *
00743        *  This function finds the mask for each char in the range [lo, hi) and
00744        *  successively writes it to vec.  vec must have as many elements as
00745        *  the char array.
00746        *
00747        *  @param lo  Pointer to start of range.
00748        *  @param hi  Pointer to end of range.
00749        *  @param vec  Pointer to an array of mask storage.
00750        *  @return  @a hi.
00751       */
00752       inline const char*
00753       is(const char* __lo, const char* __hi, mask* __vec) const;
00754 
00755       /**
00756        *  @brief  Find char matching a mask
00757        *
00758        *  This function searches for and returns the first char in [lo,hi) for
00759        *  which is(m,char) is true.
00760        *
00761        *  @param m  The mask to compare against.
00762        *  @param lo  Pointer to start of range.
00763        *  @param hi  Pointer to end of range.
00764        *  @return  Pointer to a matching char if found, else @a hi.
00765       */
00766       inline const char*
00767       scan_is(mask __m, const char* __lo, const char* __hi) const;
00768 
00769       /**
00770        *  @brief  Find char not matching a mask
00771        *
00772        *  This function searches for and returns a pointer to the first char
00773        *  in [lo,hi) for which is(m,char) is false.
00774        *
00775        *  @param m  The mask to compare against.
00776        *  @param lo  Pointer to start of range.
00777        *  @param hi  Pointer to end of range.
00778        *  @return  Pointer to a non-matching char if found, else @a hi.
00779       */
00780       inline const char*
00781       scan_not(mask __m, const char* __lo, const char* __hi) const;
00782 
00783       /**
00784        *  @brief  Convert to uppercase.
00785        *
00786        *  This function converts the char argument to uppercase if possible.
00787        *  If not possible (for example, '2'), returns the argument.
00788        *
00789        *  toupper() acts as if it returns ctype<char>::do_toupper(c).
00790        *  do_toupper() must always return the same result for the same input.
00791        *
00792        *  @param c  The char to convert.
00793        *  @return  The uppercase char if convertible, else @a c.
00794       */
00795       char_type
00796       toupper(char_type __c) const
00797       { return this->do_toupper(__c); }
00798 
00799       /**
00800        *  @brief  Convert array to uppercase.
00801        *
00802        *  This function converts each char in the range [lo,hi) to uppercase
00803        *  if possible.  Other chars remain untouched.
00804        *
00805        *  toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi).
00806        *  do_toupper() must always return the same result for the same input.
00807        *
00808        *  @param lo  Pointer to first char in range.
00809        *  @param hi  Pointer to end of range.
00810        *  @return  @a hi.
00811       */
00812       const char_type*
00813       toupper(char_type *__lo, const char_type* __hi) const
00814       { return this->do_toupper(__lo, __hi); }
00815 
00816       /**
00817        *  @brief  Convert to lowercase.
00818        *
00819        *  This function converts the char argument to lowercase if possible.
00820        *  If not possible (for example, '2'), returns the argument.
00821        *
00822        *  tolower() acts as if it returns ctype<char>::do_tolower(c).
00823        *  do_tolower() must always return the same result for the same input.
00824        *
00825        *  @param c  The char to convert.
00826        *  @return  The lowercase char if convertible, else @a c.
00827       */
00828       char_type
00829       tolower(char_type __c) const
00830       { return this->do_tolower(__c); }
00831 
00832       /**
00833        *  @brief  Convert array to lowercase.
00834        *
00835        *  This function converts each char in the range [lo,hi) to lowercase
00836        *  if possible.  Other chars remain untouched.
00837        *
00838        *  tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi).
00839        *  do_tolower() must always return the same result for the same input.
00840        *
00841        *  @param lo  Pointer to first char in range.
00842        *  @param hi  Pointer to end of range.
00843        *  @return  @a hi.
00844       */
00845       const char_type*
00846       tolower(char_type* __lo, const char_type* __hi) const
00847       { return this->do_tolower(__lo, __hi); }
00848 
00849       /**
00850        *  @brief  Widen char
00851        *
00852        *  This function converts the char to char_type using the simplest
00853        *  reasonable transformation.  For an underived ctype<char> facet, the
00854        *  argument will be returned unchanged.
00855        *
00856        *  This function works as if it returns ctype<char>::do_widen(c).
00857        *  do_widen() must always return the same result for the same input.
00858        *
00859        *  Note: this is not what you want for codepage conversions.  See
00860        *  codecvt for that.
00861        *
00862        *  @param c  The char to convert.
00863        *  @return  The converted character.
00864       */
00865       char_type
00866       widen(char __c) const
00867       {
00868     if (_M_widen_ok)
00869       return _M_widen[static_cast<unsigned char>(__c)];
00870     this->_M_widen_init();
00871     return this->do_widen(__c);
00872       }
00873 
00874       /**
00875        *  @brief  Widen char array
00876        *
00877        *  This function converts each char in the input to char using the
00878        *  simplest reasonable transformation.  For an underived ctype<char>
00879        *  facet, the argument will be copied unchanged.
00880        *
00881        *  This function works as if it returns ctype<char>::do_widen(c).
00882        *  do_widen() must always return the same result for the same input.
00883        *
00884        *  Note: this is not what you want for codepage conversions.  See
00885        *  codecvt for that.
00886        *
00887        *  @param lo  Pointer to first char in range.
00888        *  @param hi  Pointer to end of range.
00889        *  @param to  Pointer to the destination array.
00890        *  @return  @a hi.
00891       */
00892       const char*
00893       widen(const char* __lo, const char* __hi, char_type* __to) const
00894       {
00895     if (_M_widen_ok == 1)
00896       {
00897         __builtin_memcpy(__to, __lo, __hi - __lo);
00898         return __hi;
00899       }
00900     if (!_M_widen_ok)
00901       _M_widen_init();
00902     return this->do_widen(__lo, __hi, __to);
00903       }
00904 
00905       /**
00906        *  @brief  Narrow char
00907        *
00908        *  This function converts the char to char using the simplest
00909        *  reasonable transformation.  If the conversion fails, dfault is
00910        *  returned instead.  For an underived ctype<char> facet, @a c
00911        *  will be returned unchanged.
00912        *
00913        *  This function works as if it returns ctype<char>::do_narrow(c).
00914        *  do_narrow() must always return the same result for the same input.
00915        *
00916        *  Note: this is not what you want for codepage conversions.  See
00917        *  codecvt for that.
00918        *
00919        *  @param c  The char to convert.
00920        *  @param dfault  Char to return if conversion fails.
00921        *  @return  The converted character.
00922       */
00923       char
00924       narrow(char_type __c, char __dfault) const
00925       {
00926     if (_M_narrow[static_cast<unsigned char>(__c)])
00927       return _M_narrow[static_cast<unsigned char>(__c)];
00928     const char __t = do_narrow(__c, __dfault);
00929     if (__t != __dfault)
00930       _M_narrow[static_cast<unsigned char>(__c)] = __t;
00931     return __t;
00932       }
00933 
00934       /**
00935        *  @brief  Narrow char array
00936        *
00937        *  This function converts each char in the input to char using the
00938        *  simplest reasonable transformation and writes the results to the
00939        *  destination array.  For any char in the input that cannot be
00940        *  converted, @a dfault is used instead.  For an underived ctype<char>
00941        *  facet, the argument will be copied unchanged.
00942        *
00943        *  This function works as if it returns ctype<char>::do_narrow(lo, hi,
00944        *  dfault, to).  do_narrow() must always return the same result for the
00945        *  same input.
00946        *
00947        *  Note: this is not what you want for codepage conversions.  See
00948        *  codecvt for that.
00949        *
00950        *  @param lo  Pointer to start of range.
00951        *  @param hi  Pointer to end of range.
00952        *  @param dfault  Char to use if conversion fails.
00953        *  @param to  Pointer to the destination array.
00954        *  @return  @a hi.
00955       */
00956       const char_type*
00957       narrow(const char_type* __lo, const char_type* __hi,
00958          char __dfault, char *__to) const
00959       {
00960     if (__builtin_expect(_M_narrow_ok == 1, true))
00961       {
00962         __builtin_memcpy(__to, __lo, __hi - __lo);
00963         return __hi;
00964       }
00965     if (!_M_narrow_ok)
00966       _M_narrow_init();
00967     return this->do_narrow(__lo, __hi, __dfault, __to);
00968       }
00969 
00970       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00971       // DR 695. ctype<char>::classic_table() not accessible.
00972       /// Returns a pointer to the mask table provided to the constructor, or
00973       /// the default from classic_table() if none was provided.
00974       const mask*
00975       table() const throw()
00976       { return _M_table; }
00977 
00978       /// Returns a pointer to the C locale mask table.
00979       static const mask*
00980       classic_table() throw();
00981     protected:
00982 
00983       /**
00984        *  @brief  Destructor.
00985        *
00986        *  This function deletes table() if @a del was true in the
00987        *  constructor.
00988       */
00989       virtual
00990       ~ctype();
00991 
00992       /**
00993        *  @brief  Convert to uppercase.
00994        *
00995        *  This virtual function converts the char argument to uppercase if
00996        *  possible.  If not possible (for example, '2'), returns the argument.
00997        *
00998        *  do_toupper() is a hook for a derived facet to change the behavior of
00999        *  uppercasing.  do_toupper() must always return the same result for
01000        *  the same input.
01001        *
01002        *  @param c  The char to convert.
01003        *  @return  The uppercase char if convertible, else @a c.
01004       */
01005       virtual char_type
01006       do_toupper(char_type) const;
01007 
01008       /**
01009        *  @brief  Convert array to uppercase.
01010        *
01011        *  This virtual function converts each char in the range [lo,hi) to
01012        *  uppercase if possible.  Other chars remain untouched.
01013        *
01014        *  do_toupper() is a hook for a derived facet to change the behavior of
01015        *  uppercasing.  do_toupper() must always return the same result for
01016        *  the same input.
01017        *
01018        *  @param lo  Pointer to start of range.
01019        *  @param hi  Pointer to end of range.
01020        *  @return  @a hi.
01021       */
01022       virtual const char_type*
01023       do_toupper(char_type* __lo, const char_type* __hi) const;
01024 
01025       /**
01026        *  @brief  Convert to lowercase.
01027        *
01028        *  This virtual function converts the char argument to lowercase if
01029        *  possible.  If not possible (for example, '2'), returns the argument.
01030        *
01031        *  do_tolower() is a hook for a derived facet to change the behavior of
01032        *  lowercasing.  do_tolower() must always return the same result for
01033        *  the same input.
01034        *
01035        *  @param c  The char to convert.
01036        *  @return  The lowercase char if convertible, else @a c.
01037       */
01038       virtual char_type
01039       do_tolower(char_type) const;
01040 
01041       /**
01042        *  @brief  Convert array to lowercase.
01043        *
01044        *  This virtual function converts each char in the range [lo,hi) to
01045        *  lowercase if possible.  Other chars remain untouched.
01046        *
01047        *  do_tolower() is a hook for a derived facet to change the behavior of
01048        *  lowercasing.  do_tolower() must always return the same result for
01049        *  the same input.
01050        *
01051        *  @param lo  Pointer to first char in range.
01052        *  @param hi  Pointer to end of range.
01053        *  @return  @a hi.
01054       */
01055       virtual const char_type*
01056       do_tolower(char_type* __lo, const char_type* __hi) const;
01057 
01058       /**
01059        *  @brief  Widen char
01060        *
01061        *  This virtual function converts the char to char using the simplest
01062        *  reasonable transformation.  For an underived ctype<char> facet, the
01063        *  argument will be returned unchanged.
01064        *
01065        *  do_widen() is a hook for a derived facet to change the behavior of
01066        *  widening.  do_widen() must always return the same result for the
01067        *  same input.
01068        *
01069        *  Note: this is not what you want for codepage conversions.  See
01070        *  codecvt for that.
01071        *
01072        *  @param c  The char to convert.
01073        *  @return  The converted character.
01074       */
01075       virtual char_type
01076       do_widen(char __c) const
01077       { return __c; }
01078 
01079       /**
01080        *  @brief  Widen char array
01081        *
01082        *  This function converts each char in the range [lo,hi) to char using
01083        *  the simplest reasonable transformation.  For an underived
01084        *  ctype<char> facet, the argument will be copied unchanged.
01085        *
01086        *  do_widen() is a hook for a derived facet to change the behavior of
01087        *  widening.  do_widen() must always return the same result for the
01088        *  same input.
01089        *
01090        *  Note: this is not what you want for codepage conversions.  See
01091        *  codecvt for that.
01092        *
01093        *  @param lo  Pointer to start of range.
01094        *  @param hi  Pointer to end of range.
01095        *  @param to  Pointer to the destination array.
01096        *  @return  @a hi.
01097       */
01098       virtual const char*
01099       do_widen(const char* __lo, const char* __hi, char_type* __dest) const
01100       {
01101     __builtin_memcpy(__dest, __lo, __hi - __lo);
01102     return __hi;
01103       }
01104 
01105       /**
01106        *  @brief  Narrow char
01107        *
01108        *  This virtual function converts the char to char using the simplest
01109        *  reasonable transformation.  If the conversion fails, dfault is
01110        *  returned instead.  For an underived ctype<char> facet, @a c will be
01111        *  returned unchanged.
01112        *
01113        *  do_narrow() is a hook for a derived facet to change the behavior of
01114        *  narrowing.  do_narrow() must always return the same result for the
01115        *  same input.
01116        *
01117        *  Note: this is not what you want for codepage conversions.  See
01118        *  codecvt for that.
01119        *
01120        *  @param c  The char to convert.
01121        *  @param dfault  Char to return if conversion fails.
01122        *  @return  The converted char.
01123       */
01124       virtual char
01125       do_narrow(char_type __c, char) const
01126       { return __c; }
01127 
01128       /**
01129        *  @brief  Narrow char array to char array
01130        *
01131        *  This virtual function converts each char in the range [lo,hi) to
01132        *  char using the simplest reasonable transformation and writes the
01133        *  results to the destination array.  For any char in the input that
01134        *  cannot be converted, @a dfault is used instead.  For an underived
01135        *  ctype<char> facet, the argument will be copied unchanged.
01136        *
01137        *  do_narrow() is a hook for a derived facet to change the behavior of
01138        *  narrowing.  do_narrow() must always return the same result for the
01139        *  same input.
01140        *
01141        *  Note: this is not what you want for codepage conversions.  See
01142        *  codecvt for that.
01143        *
01144        *  @param lo  Pointer to start of range.
01145        *  @param hi  Pointer to end of range.
01146        *  @param dfault  Char to use if conversion fails.
01147        *  @param to  Pointer to the destination array.
01148        *  @return  @a hi.
01149       */
01150       virtual const char_type*
01151       do_narrow(const char_type* __lo, const char_type* __hi,
01152         char, char* __dest) const
01153       {
01154     __builtin_memcpy(__dest, __lo, __hi - __lo);
01155     return __hi;
01156       }
01157 
01158     private:
01159       void _M_narrow_init() const;
01160       void _M_widen_init() const;
01161     };
01162 
01163 #ifdef _GLIBCXX_USE_WCHAR_T
01164   /**
01165    *  @brief  The ctype<wchar_t> specialization.
01166    *  @ingroup locales
01167    *
01168    *  This class defines classification and conversion functions for the
01169    *  wchar_t type.  It gets used by wchar_t streams for many I/O operations.
01170    *  The wchar_t specialization provides a number of optimizations as well.
01171    *
01172    *  ctype<wchar_t> inherits its public methods from
01173    *  __ctype_abstract_base<wchar_t>.
01174   */
01175   template<>
01176     class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
01177     {
01178     public:
01179       // Types:
01180       /// Typedef for the template parameter wchar_t.
01181       typedef wchar_t       char_type;
01182       typedef wctype_t      __wmask_type;
01183 
01184     protected:
01185       __c_locale        _M_c_locale_ctype;
01186 
01187       // Pre-computed narrowed and widened chars.
01188       bool                      _M_narrow_ok;
01189       char                      _M_narrow[128];
01190       wint_t                    _M_widen[1 + static_cast<unsigned char>(-1)];
01191 
01192       // Pre-computed elements for do_is.
01193       mask                      _M_bit[16];
01194       __wmask_type              _M_wmask[16];
01195 
01196     public:
01197       // Data Members:
01198       /// The facet id for ctype<wchar_t>
01199       static locale::id     id;
01200 
01201       /**
01202        *  @brief  Constructor performs initialization.
01203        *
01204        *  This is the constructor provided by the standard.
01205        *
01206        *  @param refs  Passed to the base facet class.
01207       */
01208       explicit
01209       ctype(size_t __refs = 0);
01210 
01211       /**
01212        *  @brief  Constructor performs static initialization.
01213        *
01214        *  This constructor is used to construct the initial C locale facet.
01215        *
01216        *  @param cloc  Handle to C locale data.
01217        *  @param refs  Passed to the base facet class.
01218       */
01219       explicit
01220       ctype(__c_locale __cloc, size_t __refs = 0);
01221 
01222     protected:
01223       __wmask_type
01224       _M_convert_to_wmask(const mask __m) const throw();
01225 
01226       /// Destructor
01227       virtual
01228       ~ctype();
01229 
01230       /**
01231        *  @brief  Test wchar_t classification.
01232        *
01233        *  This function finds a mask M for @a c and compares it to mask @a m.
01234        *
01235        *  do_is() is a hook for a derived facet to change the behavior of
01236        *  classifying.  do_is() must always return the same result for the
01237        *  same input.
01238        *
01239        *  @param c  The wchar_t to find the mask of.
01240        *  @param m  The mask to compare against.
01241        *  @return  (M & m) != 0.
01242       */
01243       virtual bool
01244       do_is(mask __m, char_type __c) const;
01245 
01246       /**
01247        *  @brief  Return a mask array.
01248        *
01249        *  This function finds the mask for each wchar_t in the range [lo,hi)
01250        *  and successively writes it to vec.  vec must have as many elements
01251        *  as the input.
01252        *
01253        *  do_is() is a hook for a derived facet to change the behavior of
01254        *  classifying.  do_is() must always return the same result for the
01255        *  same input.
01256        *
01257        *  @param lo  Pointer to start of range.
01258        *  @param hi  Pointer to end of range.
01259        *  @param vec  Pointer to an array of mask storage.
01260        *  @return  @a hi.
01261       */
01262       virtual const char_type*
01263       do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
01264 
01265       /**
01266        *  @brief  Find wchar_t matching mask
01267        *
01268        *  This function searches for and returns the first wchar_t c in
01269        *  [lo,hi) for which is(m,c) is true.
01270        *
01271        *  do_scan_is() is a hook for a derived facet to change the behavior of
01272        *  match searching.  do_is() must always return the same result for the
01273        *  same input.
01274        *
01275        *  @param m  The mask to compare against.
01276        *  @param lo  Pointer to start of range.
01277        *  @param hi  Pointer to end of range.
01278        *  @return  Pointer to a matching wchar_t if found, else @a hi.
01279       */
01280       virtual const char_type*
01281       do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
01282 
01283       /**
01284        *  @brief  Find wchar_t not matching mask
01285        *
01286        *  This function searches for and returns a pointer to the first
01287        *  wchar_t c of [lo,hi) for which is(m,c) is false.
01288        *
01289        *  do_scan_is() is a hook for a derived facet to change the behavior of
01290        *  match searching.  do_is() must always return the same result for the
01291        *  same input.
01292        *
01293        *  @param m  The mask to compare against.
01294        *  @param lo  Pointer to start of range.
01295        *  @param hi  Pointer to end of range.
01296        *  @return  Pointer to a non-matching wchar_t if found, else @a hi.
01297       */
01298       virtual const char_type*
01299       do_scan_not(mask __m, const char_type* __lo,
01300           const char_type* __hi) const;
01301 
01302       /**
01303        *  @brief  Convert to uppercase.
01304        *
01305        *  This virtual function converts the wchar_t argument to uppercase if
01306        *  possible.  If not possible (for example, '2'), returns the argument.
01307        *
01308        *  do_toupper() is a hook for a derived facet to change the behavior of
01309        *  uppercasing.  do_toupper() must always return the same result for
01310        *  the same input.
01311        *
01312        *  @param c  The wchar_t to convert.
01313        *  @return  The uppercase wchar_t if convertible, else @a c.
01314       */
01315       virtual char_type
01316       do_toupper(char_type) const;
01317 
01318       /**
01319        *  @brief  Convert array to uppercase.
01320        *
01321        *  This virtual function converts each wchar_t in the range [lo,hi) to
01322        *  uppercase if possible.  Other elements remain untouched.
01323        *
01324        *  do_toupper() is a hook for a derived facet to change the behavior of
01325        *  uppercasing.  do_toupper() must always return the same result for
01326        *  the same input.
01327        *
01328        *  @param lo  Pointer to start of range.
01329        *  @param hi  Pointer to end of range.
01330        *  @return  @a hi.
01331       */
01332       virtual const char_type*
01333       do_toupper(char_type* __lo, const char_type* __hi) const;
01334 
01335       /**
01336        *  @brief  Convert to lowercase.
01337        *
01338        *  This virtual function converts the argument to lowercase if
01339        *  possible.  If not possible (for example, '2'), returns the argument.
01340        *
01341        *  do_tolower() is a hook for a derived facet to change the behavior of
01342        *  lowercasing.  do_tolower() must always return the same result for
01343        *  the same input.
01344        *
01345        *  @param c  The wchar_t to convert.
01346        *  @return  The lowercase wchar_t if convertible, else @a c.
01347       */
01348       virtual char_type
01349       do_tolower(char_type) const;
01350 
01351       /**
01352        *  @brief  Convert array to lowercase.
01353        *
01354        *  This virtual function converts each wchar_t in the range [lo,hi) to
01355        *  lowercase if possible.  Other elements remain untouched.
01356        *
01357        *  do_tolower() is a hook for a derived facet to change the behavior of
01358        *  lowercasing.  do_tolower() must always return the same result for
01359        *  the same input.
01360        *
01361        *  @param lo  Pointer to start of range.
01362        *  @param hi  Pointer to end of range.
01363        *  @return  @a hi.
01364       */
01365       virtual const char_type*
01366       do_tolower(char_type* __lo, const char_type* __hi) const;
01367 
01368       /**
01369        *  @brief  Widen char to wchar_t
01370        *
01371        *  This virtual function converts the char to wchar_t using the
01372        *  simplest reasonable transformation.  For an underived ctype<wchar_t>
01373        *  facet, the argument will be cast to wchar_t.
01374        *
01375        *  do_widen() is a hook for a derived facet to change the behavior of
01376        *  widening.  do_widen() must always return the same result for the
01377        *  same input.
01378        *
01379        *  Note: this is not what you want for codepage conversions.  See
01380        *  codecvt for that.
01381        *
01382        *  @param c  The char to convert.
01383        *  @return  The converted wchar_t.
01384       */
01385       virtual char_type
01386       do_widen(char) const;
01387 
01388       /**
01389        *  @brief  Widen char array to wchar_t array
01390        *
01391        *  This function converts each char in the input to wchar_t using the
01392        *  simplest reasonable transformation.  For an underived ctype<wchar_t>
01393        *  facet, the argument will be copied, casting each element to wchar_t.
01394        *
01395        *  do_widen() is a hook for a derived facet to change the behavior of
01396        *  widening.  do_widen() must always return the same result for the
01397        *  same input.
01398        *
01399        *  Note: this is not what you want for codepage conversions.  See
01400        *  codecvt for that.
01401        *
01402        *  @param lo  Pointer to start range.
01403        *  @param hi  Pointer to end of range.
01404        *  @param to  Pointer to the destination array.
01405        *  @return  @a hi.
01406       */
01407       virtual const char*
01408       do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
01409 
01410       /**
01411        *  @brief  Narrow wchar_t to char
01412        *
01413        *  This virtual function converts the argument to char using
01414        *  the simplest reasonable transformation.  If the conversion
01415        *  fails, dfault is returned instead.  For an underived
01416        *  ctype<wchar_t> facet, @a c will be cast to char and
01417        *  returned.
01418        *
01419        *  do_narrow() is a hook for a derived facet to change the
01420        *  behavior of narrowing.  do_narrow() must always return the
01421        *  same result for the same input.
01422        *
01423        *  Note: this is not what you want for codepage conversions.  See
01424        *  codecvt for that.
01425        *
01426        *  @param c  The wchar_t to convert.
01427        *  @param dfault  Char to return if conversion fails.
01428        *  @return  The converted char.
01429       */
01430       virtual char
01431       do_narrow(char_type, char __dfault) const;
01432 
01433       /**
01434        *  @brief  Narrow wchar_t array to char array
01435        *
01436        *  This virtual function converts each wchar_t in the range [lo,hi) to
01437        *  char using the simplest reasonable transformation and writes the
01438        *  results to the destination array.  For any wchar_t in the input that
01439        *  cannot be converted, @a dfault is used instead.  For an underived
01440        *  ctype<wchar_t> facet, the argument will be copied, casting each
01441        *  element to char.
01442        *
01443        *  do_narrow() is a hook for a derived facet to change the behavior of
01444        *  narrowing.  do_narrow() must always return the same result for the
01445        *  same input.
01446        *
01447        *  Note: this is not what you want for codepage conversions.  See
01448        *  codecvt for that.
01449        *
01450        *  @param lo  Pointer to start of range.
01451        *  @param hi  Pointer to end of range.
01452        *  @param dfault  Char to use if conversion fails.
01453        *  @param to  Pointer to the destination array.
01454        *  @return  @a hi.
01455       */
01456       virtual const char_type*
01457       do_narrow(const char_type* __lo, const char_type* __hi,
01458         char __dfault, char* __dest) const;
01459 
01460       // For use at construction time only.
01461       void
01462       _M_initialize_ctype() throw();
01463     };
01464 #endif //_GLIBCXX_USE_WCHAR_T
01465 
01466   /// class ctype_byname [22.2.1.2].
01467   template<typename _CharT>
01468     class ctype_byname : public ctype<_CharT>
01469     {
01470     public:
01471       typedef typename ctype<_CharT>::mask  mask;
01472 
01473       explicit
01474       ctype_byname(const char* __s, size_t __refs = 0);
01475 
01476     protected:
01477       virtual
01478       ~ctype_byname() { };
01479     };
01480 
01481   /// 22.2.1.4  Class ctype_byname specializations.
01482   template<>
01483     class ctype_byname<char> : public ctype<char>
01484     {
01485     public:
01486       explicit
01487       ctype_byname(const char* __s, size_t __refs = 0);
01488 
01489     protected:
01490       virtual
01491       ~ctype_byname();
01492     };
01493 
01494 #ifdef _GLIBCXX_USE_WCHAR_T
01495   template<>
01496     class ctype_byname<wchar_t> : public ctype<wchar_t>
01497     {
01498     public:
01499       explicit
01500       ctype_byname(const char* __s, size_t __refs = 0);
01501 
01502     protected:
01503       virtual
01504       ~ctype_byname();
01505     };
01506 #endif
01507 
01508 _GLIBCXX_END_NAMESPACE_VERSION
01509 } // namespace
01510 
01511 // Include host and configuration specific ctype inlines.
01512 #include <bits/ctype_inline.h>
01513 
01514 namespace std _GLIBCXX_VISIBILITY(default)
01515 {
01516 _GLIBCXX_BEGIN_NAMESPACE_VERSION
01517 
01518   // 22.2.2  The numeric category.
01519   class __num_base
01520   {
01521   public:
01522     // NB: Code depends on the order of _S_atoms_out elements.
01523     // Below are the indices into _S_atoms_out.
01524     enum
01525       {
01526         _S_ominus,
01527         _S_oplus,
01528         _S_ox,
01529         _S_oX,
01530         _S_odigits,
01531         _S_odigits_end = _S_odigits + 16,
01532         _S_oudigits = _S_odigits_end,
01533         _S_oudigits_end = _S_oudigits + 16,
01534         _S_oe = _S_odigits + 14,  // For scientific notation, 'e'
01535         _S_oE = _S_oudigits + 14, // For scientific notation, 'E'
01536     _S_oend = _S_oudigits_end
01537       };
01538 
01539     // A list of valid numeric literals for output.  This array
01540     // contains chars that will be passed through the current locale's
01541     // ctype<_CharT>.widen() and then used to render numbers.
01542     // For the standard "C" locale, this is
01543     // "-+xX0123456789abcdef0123456789ABCDEF".
01544     static const char* _S_atoms_out;
01545 
01546     // String literal of acceptable (narrow) input, for num_get.
01547     // "-+xX0123456789abcdefABCDEF"
01548     static const char* _S_atoms_in;
01549 
01550     enum
01551     {
01552       _S_iminus,
01553       _S_iplus,
01554       _S_ix,
01555       _S_iX,
01556       _S_izero,
01557       _S_ie = _S_izero + 14,
01558       _S_iE = _S_izero + 20,
01559       _S_iend = 26
01560     };
01561 
01562     // num_put
01563     // Construct and return valid scanf format for floating point types.
01564     static void
01565     _S_format_float(const ios_base& __io, char* __fptr, char __mod) throw();
01566   };
01567 
01568   template<typename _CharT>
01569     struct __numpunct_cache : public locale::facet
01570     {
01571       const char*           _M_grouping;
01572       size_t                            _M_grouping_size;
01573       bool              _M_use_grouping;
01574       const _CharT*         _M_truename;
01575       size_t                            _M_truename_size;
01576       const _CharT*         _M_falsename;
01577       size_t                            _M_falsename_size;
01578       _CharT                _M_decimal_point;
01579       _CharT                _M_thousands_sep;
01580 
01581       // A list of valid numeric literals for output: in the standard
01582       // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
01583       // This array contains the chars after having been passed
01584       // through the current locale's ctype<_CharT>.widen().
01585       _CharT                _M_atoms_out[__num_base::_S_oend];
01586 
01587       // A list of valid numeric literals for input: in the standard
01588       // "C" locale, this is "-+xX0123456789abcdefABCDEF"
01589       // This array contains the chars after having been passed
01590       // through the current locale's ctype<_CharT>.widen().
01591       _CharT                _M_atoms_in[__num_base::_S_iend];
01592 
01593       bool              _M_allocated;
01594 
01595       __numpunct_cache(size_t __refs = 0)
01596       : facet(__refs), _M_grouping(0), _M_grouping_size(0),
01597     _M_use_grouping(false),
01598     _M_truename(0), _M_truename_size(0), _M_falsename(0),
01599     _M_falsename_size(0), _M_decimal_point(_CharT()),
01600     _M_thousands_sep(_CharT()), _M_allocated(false)
01601         { }
01602 
01603       ~__numpunct_cache();
01604 
01605       void
01606       _M_cache(const locale& __loc);
01607 
01608     private:
01609       __numpunct_cache&
01610       operator=(const __numpunct_cache&);
01611       
01612       explicit
01613       __numpunct_cache(const __numpunct_cache&);
01614     };
01615 
01616   template<typename _CharT>
01617     __numpunct_cache<_CharT>::~__numpunct_cache()
01618     {
01619       if (_M_allocated)
01620     {
01621       delete [] _M_grouping;
01622       delete [] _M_truename;
01623       delete [] _M_falsename;
01624     }
01625     }
01626 
01627   /**
01628    *  @brief  Primary class template numpunct.
01629    *  @ingroup locales
01630    *
01631    *  This facet stores several pieces of information related to printing and
01632    *  scanning numbers, such as the decimal point character.  It takes a
01633    *  template parameter specifying the char type.  The numpunct facet is
01634    *  used by streams for many I/O operations involving numbers.
01635    *
01636    *  The numpunct template uses protected virtual functions to provide the
01637    *  actual results.  The public accessors forward the call to the virtual
01638    *  functions.  These virtual functions are hooks for developers to
01639    *  implement the behavior they require from a numpunct facet.
01640   */
01641   template<typename _CharT>
01642     class numpunct : public locale::facet
01643     {
01644     public:
01645       // Types:
01646       //@{
01647       /// Public typedefs
01648       typedef _CharT            char_type;
01649       typedef basic_string<_CharT>  string_type;
01650       //@}
01651       typedef __numpunct_cache<_CharT>  __cache_type;
01652 
01653     protected:
01654       __cache_type*         _M_data;
01655 
01656     public:
01657       /// Numpunct facet id.
01658       static locale::id         id;
01659 
01660       /**
01661        *  @brief  Numpunct constructor.
01662        *
01663        *  @param  refs  Refcount to pass to the base class.
01664        */
01665       explicit
01666       numpunct(size_t __refs = 0)
01667       : facet(__refs), _M_data(0)
01668       { _M_initialize_numpunct(); }
01669 
01670       /**
01671        *  @brief  Internal constructor.  Not for general use.
01672        *
01673        *  This is a constructor for use by the library itself to set up the
01674        *  predefined locale facets.
01675        *
01676        *  @param  cache  __numpunct_cache object.
01677        *  @param  refs  Refcount to pass to the base class.
01678        */
01679       explicit
01680       numpunct(__cache_type* __cache, size_t __refs = 0)
01681       : facet(__refs), _M_data(__cache)
01682       { _M_initialize_numpunct(); }
01683 
01684       /**
01685        *  @brief  Internal constructor.  Not for general use.
01686        *
01687        *  This is a constructor for use by the library itself to set up new
01688        *  locales.
01689        *
01690        *  @param  cloc  The C locale.
01691        *  @param  refs  Refcount to pass to the base class.
01692        */
01693       explicit
01694       numpunct(__c_locale __cloc, size_t __refs = 0)
01695       : facet(__refs), _M_data(0)
01696       { _M_initialize_numpunct(__cloc); }
01697 
01698       /**
01699        *  @brief  Return decimal point character.
01700        *
01701        *  This function returns a char_type to use as a decimal point.  It
01702        *  does so by returning returning
01703        *  numpunct<char_type>::do_decimal_point().
01704        *
01705        *  @return  @a char_type representing a decimal point.
01706       */
01707       char_type
01708       decimal_point() const
01709       { return this->do_decimal_point(); }
01710 
01711       /**
01712        *  @brief  Return thousands separator character.
01713        *
01714        *  This function returns a char_type to use as a thousands
01715        *  separator.  It does so by returning returning
01716        *  numpunct<char_type>::do_thousands_sep().
01717        *
01718        *  @return  char_type representing a thousands separator.
01719       */
01720       char_type
01721       thousands_sep() const
01722       { return this->do_thousands_sep(); }
01723 
01724       /**
01725        *  @brief  Return grouping specification.
01726        *
01727        *  This function returns a string representing groupings for the
01728        *  integer part of a number.  Groupings indicate where thousands
01729        *  separators should be inserted in the integer part of a number.
01730        *
01731        *  Each char in the return string is interpret as an integer
01732        *  rather than a character.  These numbers represent the number
01733        *  of digits in a group.  The first char in the string
01734        *  represents the number of digits in the least significant
01735        *  group.  If a char is negative, it indicates an unlimited
01736        *  number of digits for the group.  If more chars from the
01737        *  string are required to group a number, the last char is used
01738        *  repeatedly.
01739        *
01740        *  For example, if the grouping() returns "\003\002" and is
01741        *  applied to the number 123456789, this corresponds to
01742        *  12,34,56,789.  Note that if the string was "32", this would
01743        *  put more than 50 digits into the least significant group if
01744        *  the character set is ASCII.
01745        *
01746        *  The string is returned by calling
01747        *  numpunct<char_type>::do_grouping().
01748        *
01749        *  @return  string representing grouping specification.
01750       */
01751       string
01752       grouping() const
01753       { return this->do_grouping(); }
01754 
01755       /**
01756        *  @brief  Return string representation of bool true.
01757        *
01758        *  This function returns a string_type containing the text
01759        *  representation for true bool variables.  It does so by calling
01760        *  numpunct<char_type>::do_truename().
01761        *
01762        *  @return  string_type representing printed form of true.
01763       */
01764       string_type
01765       truename() const
01766       { return this->do_truename(); }
01767 
01768       /**
01769        *  @brief  Return string representation of bool false.
01770        *
01771        *  This function returns a string_type containing the text
01772        *  representation for false bool variables.  It does so by calling
01773        *  numpunct<char_type>::do_falsename().
01774        *
01775        *  @return  string_type representing printed form of false.
01776       */
01777       string_type
01778       falsename() const
01779       { return this->do_falsename(); }
01780 
01781     protected:
01782       /// Destructor.
01783       virtual
01784       ~numpunct();
01785 
01786       /**
01787        *  @brief  Return decimal point character.
01788        *
01789        *  Returns a char_type to use as a decimal point.  This function is a
01790        *  hook for derived classes to change the value returned.
01791        *
01792        *  @return  @a char_type representing a decimal point.
01793       */
01794       virtual char_type
01795       do_decimal_point() const
01796       { return _M_data->_M_decimal_point; }
01797 
01798       /**
01799        *  @brief  Return thousands separator character.
01800        *
01801        *  Returns a char_type to use as a thousands separator.  This function
01802        *  is a hook for derived classes to change the value returned.
01803        *
01804        *  @return  @a char_type representing a thousands separator.
01805       */
01806       virtual char_type
01807       do_thousands_sep() const
01808       { return _M_data->_M_thousands_sep; }
01809 
01810       /**
01811        *  @brief  Return grouping specification.
01812        *
01813        *  Returns a string representing groupings for the integer part of a
01814        *  number.  This function is a hook for derived classes to change the
01815        *  value returned.  @see grouping() for details.
01816        *
01817        *  @return  String representing grouping specification.
01818       */
01819       virtual string
01820       do_grouping() const
01821       { return _M_data->_M_grouping; }
01822 
01823       /**
01824        *  @brief  Return string representation of bool true.
01825        *
01826        *  Returns a string_type containing the text representation for true
01827        *  bool variables.  This function is a hook for derived classes to
01828        *  change the value returned.
01829        *
01830        *  @return  string_type representing printed form of true.
01831       */
01832       virtual string_type
01833       do_truename() const
01834       { return _M_data->_M_truename; }
01835 
01836       /**
01837        *  @brief  Return string representation of bool false.
01838        *
01839        *  Returns a string_type containing the text representation for false
01840        *  bool variables.  This function is a hook for derived classes to
01841        *  change the value returned.
01842        *
01843        *  @return  string_type representing printed form of false.
01844       */
01845       virtual string_type
01846       do_falsename() const
01847       { return _M_data->_M_falsename; }
01848 
01849       // For use at construction time only.
01850       void
01851       _M_initialize_numpunct(__c_locale __cloc = 0);
01852     };
01853 
01854   template<typename _CharT>
01855     locale::id numpunct<_CharT>::id;
01856 
01857   template<>
01858     numpunct<char>::~numpunct();
01859 
01860   template<>
01861     void
01862     numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
01863 
01864 #ifdef _GLIBCXX_USE_WCHAR_T
01865   template<>
01866     numpunct<wchar_t>::~numpunct();
01867 
01868   template<>
01869     void
01870     numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
01871 #endif
01872 
01873   /// class numpunct_byname [22.2.3.2].
01874   template<typename _CharT>
01875     class numpunct_byname : public numpunct<_CharT>
01876     {
01877     public:
01878       typedef _CharT            char_type;
01879       typedef basic_string<_CharT>  string_type;
01880 
01881       explicit
01882       numpunct_byname(const char* __s, size_t __refs = 0)
01883       : numpunct<_CharT>(__refs)
01884       {
01885     if (__builtin_strcmp(__s, "C") != 0
01886         && __builtin_strcmp(__s, "POSIX") != 0)
01887       {
01888         __c_locale __tmp;
01889         this->_S_create_c_locale(__tmp, __s);
01890         this->_M_initialize_numpunct(__tmp);
01891         this->_S_destroy_c_locale(__tmp);
01892       }
01893       }
01894 
01895     protected:
01896       virtual
01897       ~numpunct_byname() { }
01898     };
01899 
01900 _GLIBCXX_BEGIN_NAMESPACE_LDBL
01901 
01902   /**
01903    *  @brief  Primary class template num_get.
01904    *  @ingroup locales
01905    *
01906    *  This facet encapsulates the code to parse and return a number
01907    *  from a string.  It is used by the istream numeric extraction
01908    *  operators.
01909    *
01910    *  The num_get template uses protected virtual functions to provide the
01911    *  actual results.  The public accessors forward the call to the virtual
01912    *  functions.  These virtual functions are hooks for developers to
01913    *  implement the behavior they require from the num_get facet.
01914   */
01915   template<typename _CharT, typename _InIter>
01916     class num_get : public locale::facet
01917     {
01918     public:
01919       // Types:
01920       //@{
01921       /// Public typedefs
01922       typedef _CharT            char_type;
01923       typedef _InIter           iter_type;
01924       //@}
01925 
01926       /// Numpunct facet id.
01927       static locale::id         id;
01928 
01929       /**
01930        *  @brief  Constructor performs initialization.
01931        *
01932        *  This is the constructor provided by the standard.
01933        *
01934        *  @param refs  Passed to the base facet class.
01935       */
01936       explicit
01937       num_get(size_t __refs = 0) : facet(__refs) { }
01938 
01939       /**
01940        *  @brief  Numeric parsing.
01941        *
01942        *  Parses the input stream into the bool @a v.  It does so by calling
01943        *  num_get::do_get().
01944        *
01945        *  If ios_base::boolalpha is set, attempts to read
01946        *  ctype<CharT>::truename() or ctype<CharT>::falsename().  Sets
01947        *  @a v to true or false if successful.  Sets err to
01948        *  ios_base::failbit if reading the string fails.  Sets err to
01949        *  ios_base::eofbit if the stream is emptied.
01950        *
01951        *  If ios_base::boolalpha is not set, proceeds as with reading a long,
01952        *  except if the value is 1, sets @a v to true, if the value is 0, sets
01953        *  @a v to false, and otherwise set err to ios_base::failbit.
01954        *
01955        *  @param  in  Start of input stream.
01956        *  @param  end  End of input stream.
01957        *  @param  io  Source of locale and flags.
01958        *  @param  err  Error flags to set.
01959        *  @param  v  Value to format and insert.
01960        *  @return  Iterator after reading.
01961       */
01962       iter_type
01963       get(iter_type __in, iter_type __end, ios_base& __io,
01964       ios_base::iostate& __err, bool& __v) const
01965       { return this->do_get(__in, __end, __io, __err, __v); }
01966 
01967       //@{
01968       /**
01969        *  @brief  Numeric parsing.
01970        *
01971        *  Parses the input stream into the integral variable @a v.  It does so
01972        *  by calling num_get::do_get().
01973        *
01974        *  Parsing is affected by the flag settings in @a io.
01975        *
01976        *  The basic parse is affected by the value of io.flags() &
01977        *  ios_base::basefield.  If equal to ios_base::oct, parses like the
01978        *  scanf %o specifier.  Else if equal to ios_base::hex, parses like %X
01979        *  specifier.  Else if basefield equal to 0, parses like the %i
01980        *  specifier.  Otherwise, parses like %d for signed and %u for unsigned
01981        *  types.  The matching type length modifier is also used.
01982        *
01983        *  Digit grouping is interpreted according to numpunct::grouping() and
01984        *  numpunct::thousands_sep().  If the pattern of digit groups isn't
01985        *  consistent, sets err to ios_base::failbit.
01986        *
01987        *  If parsing the string yields a valid value for @a v, @a v is set.
01988        *  Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
01989        *  Sets err to ios_base::eofbit if the stream is emptied.
01990        *
01991        *  @param  in  Start of input stream.
01992        *  @param  end  End of input stream.
01993        *  @param  io  Source of locale and flags.
01994        *  @param  err  Error flags to set.
01995        *  @param  v  Value to format and insert.
01996        *  @return  Iterator after reading.
01997       */
01998       iter_type
01999       get(iter_type __in, iter_type __end, ios_base& __io,
02000       ios_base::iostate& __err, long& __v) const
02001       { return this->do_get(__in, __end, __io, __err, __v); }
02002 
02003       iter_type
02004       get(iter_type __in, iter_type __end, ios_base& __io,
02005       ios_base::iostate& __err, unsigned short& __v) const
02006       { return this->do_get(__in, __end, __io, __err, __v); }
02007 
02008       iter_type
02009       get(iter_type __in, iter_type __end, ios_base& __io,
02010       ios_base::iostate& __err, unsigned int& __v)   const
02011       { return this->do_get(__in, __end, __io, __err, __v); }
02012 
02013       iter_type
02014       get(iter_type __in, iter_type __end, ios_base& __io,
02015       ios_base::iostate& __err, unsigned long& __v)  const
02016       { return this->do_get(__in, __end, __io, __err, __v); }
02017 
02018 #ifdef _GLIBCXX_USE_LONG_LONG
02019       iter_type
02020       get(iter_type __in, iter_type __end, ios_base& __io,
02021       ios_base::iostate& __err, long long& __v) const
02022       { return this->do_get(__in, __end, __io, __err, __v); }
02023 
02024       iter_type
02025       get(iter_type __in, iter_type __end, ios_base& __io,
02026       ios_base::iostate& __err, unsigned long long& __v)  const
02027       { return this->do_get(__in, __end, __io, __err, __v); }
02028 #endif
02029       //@}
02030 
02031       //@{
02032       /**
02033        *  @brief  Numeric parsing.
02034        *
02035        *  Parses the input stream into the integral variable @a v.  It does so
02036        *  by calling num_get::do_get().
02037        *
02038        *  The input characters are parsed like the scanf %g specifier.  The
02039        *  matching type length modifier is also used.
02040        *
02041        *  The decimal point character used is numpunct::decimal_point().
02042        *  Digit grouping is interpreted according to numpunct::grouping() and
02043        *  numpunct::thousands_sep().  If the pattern of digit groups isn't
02044        *  consistent, sets err to ios_base::failbit.
02045        *
02046        *  If parsing the string yields a valid value for @a v, @a v is set.
02047        *  Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
02048        *  Sets err to ios_base::eofbit if the stream is emptied.
02049        *
02050        *  @param  in  Start of input stream.
02051        *  @param  end  End of input stream.
02052        *  @param  io  Source of locale and flags.
02053        *  @param  err  Error flags to set.
02054        *  @param  v  Value to format and insert.
02055        *  @return  Iterator after reading.
02056       */
02057       iter_type
02058       get(iter_type __in, iter_type __end, ios_base& __io,
02059       ios_base::iostate& __err, float& __v) const
02060       { return this->do_get(__in, __end, __io, __err, __v); }
02061 
02062       iter_type
02063       get(iter_type __in, iter_type __end, ios_base& __io,
02064       ios_base::iostate& __err, double& __v) const
02065       { return this->do_get(__in, __end, __io, __err, __v); }
02066 
02067       iter_type
02068       get(iter_type __in, iter_type __end, ios_base& __io,
02069       ios_base::iostate& __err, long double& __v) const
02070       { return this->do_get(__in, __end, __io, __err, __v); }
02071       //@}
02072 
02073       /**
02074        *  @brief  Numeric parsing.
02075        *
02076        *  Parses the input stream into the pointer variable @a v.  It does so
02077        *  by calling num_get::do_get().
02078        *
02079        *  The input characters are parsed like the scanf %p specifier.
02080        *
02081        *  Digit grouping is interpreted according to numpunct::grouping() and
02082        *  numpunct::thousands_sep().  If the pattern of digit groups isn't
02083        *  consistent, sets err to ios_base::failbit.
02084        *
02085        *  Note that the digit grouping effect for pointers is a bit ambiguous
02086        *  in the standard and shouldn't be relied on.  See DR 344.
02087        *
02088        *  If parsing the string yields a valid value for @a v, @a v is set.
02089        *  Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
02090        *  Sets err to ios_base::eofbit if the stream is emptied.
02091        *
02092        *  @param  in  Start of input stream.
02093        *  @param  end  End of input stream.
02094        *  @param  io  Source of locale and flags.
02095        *  @param  err  Error flags to set.
02096        *  @param  v  Value to format and insert.
02097        *  @return  Iterator after reading.
02098       */
02099       iter_type
02100       get(iter_type __in, iter_type __end, ios_base& __io,
02101       ios_base::iostate& __err, void*& __v) const
02102       { return this->do_get(__in, __end, __io, __err, __v); }
02103 
02104     protected:
02105       /// Destructor.
02106       virtual ~num_get() { }
02107 
02108       iter_type
02109       _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
02110                string&) const;
02111 
02112       template<typename _ValueT>
02113         iter_type
02114         _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
02115                _ValueT&) const;
02116 
02117       template<typename _CharT2>
02118       typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, int>::__type
02119         _M_find(const _CharT2*, size_t __len, _CharT2 __c) const
02120         {
02121       int __ret = -1;
02122       if (__len <= 10)
02123         {
02124           if (__c >= _CharT2('0') && __c < _CharT2(_CharT2('0') + __len))
02125         __ret = __c - _CharT2('0');
02126         }
02127       else
02128         {
02129           if (__c >= _CharT2('0') && __c <= _CharT2('9'))
02130         __ret = __c - _CharT2('0');
02131           else if (__c >= _CharT2('a') && __c <= _CharT2('f'))
02132         __ret = 10 + (__c - _CharT2('a'));
02133           else if (__c >= _CharT2('A') && __c <= _CharT2('F'))
02134         __ret = 10 + (__c - _CharT2('A'));
02135         }
02136       return __ret;
02137     }
02138 
02139       template<typename _CharT2>
02140       typename __gnu_cxx::__enable_if<!__is_char<_CharT2>::__value, 
02141                       int>::__type
02142         _M_find(const _CharT2* __zero, size_t __len, _CharT2 __c) const
02143         {
02144       int __ret = -1;
02145       const char_type* __q = char_traits<_CharT2>::find(__zero, __len, __c);
02146       if (__q)
02147         {
02148           __ret = __q - __zero;
02149           if (__ret > 15)
02150         __ret -= 6;
02151         }
02152       return __ret;
02153     }
02154 
02155       //@{
02156       /**
02157        *  @brief  Numeric parsing.
02158        *
02159        *  Parses the input stream into the variable @a v.  This function is a
02160        *  hook for derived classes to change the value returned.  @see get()
02161        *  for more details.
02162        *
02163        *  @param  in  Start of input stream.
02164        *  @param  end  End of input stream.
02165        *  @param  io  Source of locale and flags.
02166        *  @param  err  Error flags to set.
02167        *  @param  v  Value to format and insert.
02168        *  @return  Iterator after reading.
02169       */
02170       virtual iter_type
02171       do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
02172 
02173       virtual iter_type
02174       do_get(iter_type __beg, iter_type __end, ios_base& __io,
02175          ios_base::iostate& __err, long& __v) const
02176       { return _M_extract_int(__beg, __end, __io, __err, __v); }
02177 
02178       virtual iter_type
02179       do_get(iter_type __beg, iter_type __end, ios_base& __io,
02180          ios_base::iostate& __err, unsigned short& __v) const
02181       { return _M_extract_int(__beg, __end, __io, __err, __v); }
02182 
02183       virtual iter_type
02184       do_get(iter_type __beg, iter_type __end, ios_base& __io,
02185          ios_base::iostate& __err, unsigned int& __v) const
02186       { return _M_extract_int(__beg, __end, __io, __err, __v); }
02187 
02188       virtual iter_type
02189       do_get(iter_type __beg, iter_type __end, ios_base& __io,
02190          ios_base::iostate& __err, unsigned long& __v) const
02191       { return _M_extract_int(__beg, __end, __io, __err, __v); }
02192 
02193 #ifdef _GLIBCXX_USE_LONG_LONG
02194       virtual iter_type
02195       do_get(iter_type __beg, iter_type __end, ios_base& __io,
02196          ios_base::iostate& __err, long long& __v) const
02197       { return _M_extract_int(__beg, __end, __io, __err, __v); }    
02198 
02199       virtual iter_type
02200       do_get(iter_type __beg, iter_type __end, ios_base& __io,
02201          ios_base::iostate& __err, unsigned long long& __v) const
02202       { return _M_extract_int(__beg, __end, __io, __err, __v); }
02203 #endif
02204 
02205       virtual iter_type
02206       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
02207          float&) const;
02208 
02209       virtual iter_type
02210       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
02211          double&) const;
02212 
02213       // XXX GLIBCXX_ABI Deprecated
02214 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
02215       virtual iter_type
02216       __do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
02217            double&) const;
02218 #else
02219       virtual iter_type
02220       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
02221          long double&) const;
02222 #endif
02223 
02224       virtual iter_type
02225       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
02226          void*&) const;
02227 
02228       // XXX GLIBCXX_ABI Deprecated
02229 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
02230       virtual iter_type
02231       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
02232          long double&) const;
02233 #endif
02234       //@}
02235     };
02236 
02237   template<typename _CharT, typename _InIter>
02238     locale::id num_get<_CharT, _InIter>::id;
02239 
02240 
02241   /**
02242    *  @brief  Primary class template num_put.
02243    *  @ingroup locales
02244    *
02245    *  This facet encapsulates the code to convert a number to a string.  It is
02246    *  used by the ostream numeric insertion operators.
02247    *
02248    *  The num_put template uses protected virtual functions to provide the
02249    *  actual results.  The public accessors forward the call to the virtual
02250    *  functions.  These virtual functions are hooks for developers to
02251    *  implement the behavior they require from the num_put facet.
02252   */
02253   template<typename _CharT, typename _OutIter>
02254     class num_put : public locale::facet
02255     {
02256     public:
02257       // Types:
02258       //@{
02259       /// Public typedefs
02260       typedef _CharT        char_type;
02261       typedef _OutIter      iter_type;
02262       //@}
02263 
02264       /// Numpunct facet id.
02265       static locale::id     id;
02266 
02267       /**
02268        *  @brief  Constructor performs initialization.
02269        *
02270        *  This is the constructor provided by the standard.
02271        *
02272        *  @param refs  Passed to the base facet class.
02273       */
02274       explicit
02275       num_put(size_t __refs = 0) : facet(__refs) { }
02276 
02277       /**
02278        *  @brief  Numeric formatting.
02279        *
02280        *  Formats the boolean @a v and inserts it into a stream.  It does so
02281        *  by calling num_put::do_put().
02282        *
02283        *  If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
02284        *  ctype<CharT>::falsename().  Otherwise formats @a v as an int.
02285        *
02286        *  @param  s  Stream to write to.
02287        *  @param  io  Source of locale and flags.
02288        *  @param  fill  Char_type to use for filling.
02289        *  @param  v  Value to format and insert.
02290        *  @return  Iterator after writing.
02291       */
02292       iter_type
02293       put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
02294       { return this->do_put(__s, __f, __fill, __v); }
02295 
02296       //@{
02297       /**
02298        *  @brief  Numeric formatting.
02299        *
02300        *  Formats the integral value @a v and inserts it into a
02301        *  stream.  It does so by calling num_put::do_put().
02302        *
02303        *  Formatting is affected by the flag settings in @a io.
02304        *
02305        *  The basic format is affected by the value of io.flags() &
02306        *  ios_base::basefield.  If equal to ios_base::oct, formats like the
02307        *  printf %o specifier.  Else if equal to ios_base::hex, formats like
02308        *  %x or %X with ios_base::uppercase unset or set respectively.
02309        *  Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
02310        *  for unsigned values.  Note that if both oct and hex are set, neither
02311        *  will take effect.
02312        *
02313        *  If ios_base::showpos is set, '+' is output before positive values.
02314        *  If ios_base::showbase is set, '0' precedes octal values (except 0)
02315        *  and '0[xX]' precedes hex values.
02316        *
02317        *  Thousands separators are inserted according to numpunct::grouping()
02318        *  and numpunct::thousands_sep().  The decimal point character used is
02319        *  numpunct::decimal_point().
02320        *
02321        *  If io.width() is non-zero, enough @a fill characters are inserted to
02322        *  make the result at least that wide.  If
02323        *  (io.flags() & ios_base::adjustfield) == ios_base::left, result is
02324        *  padded at the end.  If ios_base::internal, then padding occurs
02325        *  immediately after either a '+' or '-' or after '0x' or '0X'.
02326        *  Otherwise, padding occurs at the beginning.
02327        *
02328        *  @param  s  Stream to write to.
02329        *  @param  io  Source of locale and flags.
02330        *  @param  fill  Char_type to use for filling.
02331        *  @param  v  Value to format and insert.
02332        *  @return  Iterator after writing.
02333       */
02334       iter_type
02335       put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
02336       { return this->do_put(__s, __f, __fill, __v); }
02337 
02338       iter_type
02339       put(iter_type __s, ios_base& __f, char_type __fill,
02340       unsigned long __v) const
02341       { return this->do_put(__s, __f, __fill, __v); }
02342 
02343 #ifdef _GLIBCXX_USE_LONG_LONG
02344       iter_type
02345       put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
02346       { return this->do_put(__s, __f, __fill, __v); }
02347 
02348       iter_type
02349       put(iter_type __s, ios_base& __f, char_type __fill,
02350       unsigned long long __v) const
02351       { return this->do_put(__s, __f, __fill, __v); }
02352 #endif
02353       //@}
02354 
02355       //@{
02356       /**
02357        *  @brief  Numeric formatting.
02358        *
02359        *  Formats the floating point value @a v and inserts it into a stream.
02360        *  It does so by calling num_put::do_put().
02361        *
02362        *  Formatting is affected by the flag settings in @a io.
02363        *
02364        *  The basic format is affected by the value of io.flags() &
02365        *  ios_base::floatfield.  If equal to ios_base::fixed, formats like the
02366        *  printf %f specifier.  Else if equal to ios_base::scientific, formats
02367        *  like %e or %E with ios_base::uppercase unset or set respectively.
02368        *  Otherwise, formats like %g or %G depending on uppercase.  Note that
02369        *  if both fixed and scientific are set, the effect will also be like
02370        *  %g or %G.
02371        *
02372        *  The output precision is given by io.precision().  This precision is
02373        *  capped at numeric_limits::digits10 + 2 (different for double and
02374        *  long double).  The default precision is 6.
02375        *
02376        *  If ios_base::showpos is set, '+' is output before positive values.
02377        *  If ios_base::showpoint is set, a decimal point will always be
02378        *  output.
02379        *
02380        *  Thousands separators are inserted according to numpunct::grouping()
02381        *  and numpunct::thousands_sep().  The decimal point character used is
02382        *  numpunct::decimal_point().
02383        *
02384        *  If io.width() is non-zero, enough @a fill characters are inserted to
02385        *  make the result at least that wide.  If
02386        *  (io.flags() & ios_base::adjustfield) == ios_base::left, result is
02387        *  padded at the end.  If ios_base::internal, then padding occurs
02388        *  immediately after either a '+' or '-' or after '0x' or '0X'.
02389        *  Otherwise, padding occurs at the beginning.
02390        *
02391        *  @param  s  Stream to write to.
02392        *  @param  io  Source of locale and flags.
02393        *  @param  fill  Char_type to use for filling.
02394        *  @param  v  Value to format and insert.
02395        *  @return  Iterator after writing.
02396       */
02397       iter_type
02398       put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
02399       { return this->do_put(__s, __f, __fill, __v); }
02400 
02401       iter_type
02402       put(iter_type __s, ios_base& __f, char_type __fill,
02403       long double __v) const
02404       { return this->do_put(__s, __f, __fill, __v); }
02405       //@}
02406 
02407       /**
02408        *  @brief  Numeric formatting.
02409        *
02410        *  Formats the pointer value @a v and inserts it into a stream.  It
02411        *  does so by calling num_put::do_put().
02412        *
02413        *  This function formats @a v as an unsigned long with ios_base::hex
02414        *  and ios_base::showbase set.
02415        *
02416        *  @param  s  Stream to write to.
02417        *  @param  io  Source of locale and flags.
02418        *  @param  fill  Char_type to use for filling.
02419        *  @param  v  Value to format and insert.
02420        *  @return  Iterator after writing.
02421       */
02422       iter_type
02423       put(iter_type __s, ios_base& __f, char_type __fill,
02424       const void* __v) const
02425       { return this->do_put(__s, __f, __fill, __v); }
02426 
02427     protected:
02428       template<typename _ValueT>
02429         iter_type
02430         _M_insert_float(iter_type, ios_base& __io, char_type __fill,
02431             char __mod, _ValueT __v) const;
02432 
02433       void
02434       _M_group_float(const char* __grouping, size_t __grouping_size,
02435              char_type __sep, const char_type* __p, char_type* __new,
02436              char_type* __cs, int& __len) const;
02437 
02438       template<typename _ValueT>
02439         iter_type
02440         _M_insert_int(iter_type, ios_base& __io, char_type __fill,
02441               _ValueT __v) const;
02442 
02443       void
02444       _M_group_int(const char* __grouping, size_t __grouping_size,
02445            char_type __sep, ios_base& __io, char_type* __new,
02446            char_type* __cs, int& __len) const;
02447 
02448       void
02449       _M_pad(char_type __fill, streamsize __w, ios_base& __io,
02450          char_type* __new, const char_type* __cs, int& __len) const;
02451 
02452       /// Destructor.
02453       virtual
02454       ~num_put() { };
02455 
02456       //@{
02457       /**
02458        *  @brief  Numeric formatting.
02459        *
02460        *  These functions do the work of formatting numeric values and
02461        *  inserting them into a stream. This function is a hook for derived
02462        *  classes to change the value returned.
02463        *
02464        *  @param  s  Stream to write to.
02465        *  @param  io  Source of locale and flags.
02466        *  @param  fill  Char_type to use for filling.
02467        *  @param  v  Value to format and insert.
02468        *  @return  Iterator after writing.
02469       */
02470       virtual iter_type
02471       do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
02472 
02473       virtual iter_type
02474       do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
02475       { return _M_insert_int(__s, __io, __fill, __v); } 
02476 
02477       virtual iter_type
02478       do_put(iter_type __s, ios_base& __io, char_type __fill,
02479          unsigned long __v) const
02480       { return _M_insert_int(__s, __io, __fill, __v); }
02481 
02482 #ifdef _GLIBCXX_USE_LONG_LONG
02483       virtual iter_type
02484       do_put(iter_type __s, ios_base& __io, char_type __fill,
02485          long long __v) const
02486       { return _M_insert_int(__s, __io, __fill, __v); }
02487 
02488       virtual iter_type
02489       do_put(iter_type __s, ios_base& __io, char_type __fill,
02490          unsigned long long __v) const
02491       { return _M_insert_int(__s, __io, __fill, __v); }
02492 #endif
02493 
02494       virtual iter_type
02495       do_put(iter_type, ios_base&, char_type __fill, double __v) const;
02496 
02497       // XXX GLIBCXX_ABI Deprecated
02498 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
02499       virtual iter_type
02500       __do_put(iter_type, ios_base&, char_type __fill, double __v) const;
02501 #else
02502       virtual iter_type
02503       do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
02504 #endif
02505 
02506       virtual iter_type
02507       do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
02508 
02509       // XXX GLIBCXX_ABI Deprecated
02510 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
02511       virtual iter_type
02512       do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
02513 #endif
02514       //@}
02515     };
02516 
02517   template <typename _CharT, typename _OutIter>
02518     locale::id num_put<_CharT, _OutIter>::id;
02519 
02520 _GLIBCXX_END_NAMESPACE_LDBL
02521 
02522   // Subclause convenience interfaces, inlines.
02523   // NB: These are inline because, when used in a loop, some compilers
02524   // can hoist the body out of the loop; then it's just as fast as the
02525   // C is*() function.
02526 
02527   /// Convenience interface to ctype.is(ctype_base::space, __c).
02528   template<typename _CharT>
02529     inline bool
02530     isspace(_CharT __c, const locale& __loc)
02531     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
02532 
02533   /// Convenience interface to ctype.is(ctype_base::print, __c).
02534   template<typename _CharT>
02535     inline bool
02536     isprint(_CharT __c, const locale& __loc)
02537     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
02538 
02539   /// Convenience interface to ctype.is(ctype_base::cntrl, __c).
02540   template<typename _CharT>
02541     inline bool
02542     iscntrl(_CharT __c, const locale& __loc)
02543     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
02544 
02545   /// Convenience interface to ctype.is(ctype_base::upper, __c).
02546   template<typename _CharT>
02547     inline bool
02548     isupper(_CharT __c, const locale& __loc)
02549     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
02550 
02551   /// Convenience interface to ctype.is(ctype_base::lower, __c).
02552   template<typename _CharT>
02553     inline bool 
02554     islower(_CharT __c, const locale& __loc)
02555     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
02556 
02557   /// Convenience interface to ctype.is(ctype_base::alpha, __c).
02558   template<typename _CharT>
02559     inline bool
02560     isalpha(_CharT __c, const locale& __loc)
02561     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
02562 
02563   /// Convenience interface to ctype.is(ctype_base::digit, __c).
02564   template<typename _CharT>
02565     inline bool
02566     isdigit(_CharT __c, const locale& __loc)
02567     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
02568 
02569   /// Convenience interface to ctype.is(ctype_base::punct, __c).
02570   template<typename _CharT>
02571     inline bool
02572     ispunct(_CharT __c, const locale& __loc)
02573     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
02574 
02575   /// Convenience interface to ctype.is(ctype_base::xdigit, __c).
02576   template<typename _CharT>
02577     inline bool
02578     isxdigit(_CharT __c, const locale& __loc)
02579     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
02580 
02581   /// Convenience interface to ctype.is(ctype_base::alnum, __c).
02582   template<typename _CharT>
02583     inline bool
02584     isalnum(_CharT __c, const locale& __loc)
02585     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
02586 
02587   /// Convenience interface to ctype.is(ctype_base::graph, __c).
02588   template<typename _CharT>
02589     inline bool
02590     isgraph(_CharT __c, const locale& __loc)
02591     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
02592 
02593   /// Convenience interface to ctype.toupper(__c).
02594   template<typename _CharT>
02595     inline _CharT
02596     toupper(_CharT __c, const locale& __loc)
02597     { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
02598 
02599   /// Convenience interface to ctype.tolower(__c).
02600   template<typename _CharT>
02601     inline _CharT
02602     tolower(_CharT __c, const locale& __loc)
02603     { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
02604 
02605 _GLIBCXX_END_NAMESPACE_VERSION
02606 } // namespace
02607 
02608 # include <bits/locale_facets.tcc>
02609 
02610 #endif