⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 locale_facets.h

📁 c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出版社的光盘
💻 H
📖 第 1 页 / 共 4 页
字号:
// Locale support -*- C++ -*-// Copyright (C) 1997-1999 Cygnus Solutions//// This file is part of the GNU ISO C++ Library.  This library is free// software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the// Free Software Foundation; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License along// with this library; see the file COPYING.  If not, write to the Free// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,// USA.// As a special exception, you may use this file as part of a free software// library without restriction.  Specifically, if other files instantiate// templates or use macros or inline functions from this file, or you compile// this file and link it with other files to produce an executable, this// file does not by itself cause the resulting executable to be covered by// the GNU General Public License.  This exception does not however// invalidate any other reasons why the executable file might be covered by// the GNU General Public License.//// ISO C++ 14882: 22.1  Locales//// Warning: this file is not meant for user inclusion.  Use <locale>.#ifndef _CPP_BITS_LOCFACETS_H#define _CPP_BITS_LOCFACETS_H	1#include <bits/std_ctime.h>	// For struct tm#include <bits/std_typeinfo.h> 	// For bad_cast, which shouldn't be here.#include <bits/std_ios.h>	// For ios_basenamespace std{  // XXX This function is to be specialized for the "required" facets to   // be constructed lazily.   The specializations must be declared after   // the definitions of the facets themselves; but they shouldn't be   // inline.  Corresponding new's in locale::classic() should then be   // eliminated.  Note that ctype<> should not get this treatment;   // see the use_facet<> specializations below.  //  struct _Bad_use_facet : public bad_cast   {    _Bad_use_facet() throw() {}    _Bad_use_facet(_Bad_use_facet const&  __b) throw()     : bad_cast(__b) { }    _Bad_use_facet&     operator=(_Bad_use_facet const& __b) throw()     {       static_cast<bad_cast*>(this)->operator=(__b);       return *this;     }    virtual char const*     what() const throw();    virtual     ~_Bad_use_facet() throw();  };  template<typename _Facet>    const _Facet&     _Use_facet_failure_handler(const locale&)    { throw _Bad_use_facet(); }  // 22.2.1  The ctype category  struct ctype_base  {    enum    {#ifdef _GLIBCPP_USE_CTYPE_ISBIT      space = _ISspace,      print = _ISprint,      cntrl = _IScntrl,      upper = _ISupper,      lower = _ISlower,      alpha = _ISalpha,      digit = _ISdigit,      punct = _ISpunct,      xdigit = _ISxdigit,      alnum = _ISalnum,      graph = _ISgraph#else      space = (1 << 5),	// Whitespace      print = (1 << 6),	// Printing      cntrl = (1 << 9),	// Control character      upper = (1 << 0),	// UPPERCASE      lower = (1 << 1),	// lowercase      alpha = (1 << 5),	// Alphabetic      digit = (1 << 2),	// Numeric      punct = (1 << 10),// Punctuation      xdigit = (1 << 4),// Hexadecimal numeric      alnum = (1 << 11),// Alphanumeric      graph = (1 << 7)	// Graphical#endif    };    typedef unsigned short mask;  };  // 22.2.1.1  Template class ctype  // _Ctype_nois is the common base for ctype<char>.  It lacks "do_is"  // and related virtuals.  These are filled in by _Ctype, below.  template<typename _CharT>    class _Ctype_nois : public locale::facet, public ctype_base    {      // Types:      typedef _CharT char_type;    public:      char_type       toupper(char_type __c) const      { return this->do_toupper(__c); }      const char_type*      toupper(char_type *__low, const char_type* __high) const      { return this->do_toupper(__low, __high); }      char_type       tolower(char_type __c) const      { return this->do_tolower(__c); }      const char_type*      tolower(char_type* __low, const char_type* __high) const      { return this->do_tolower(__low, __high); }      char_type       widen(char __c) const      { return this->do_widen(__c); }      const char*      widen(const char* __low, const char* __high, char_type* __to) const      { return this->do_widen(__low, __high, __to); }      char       narrow(char_type __c, char __dfault) const      { return this->do_narrow(__c, __dfault); }      const char_type*      narrow(const char_type* __low, const char_type* __high,	      char __dfault, char *__to) const      { return this->do_narrow(__low, __high, __dfault, __to); }    protected:      explicit       _Ctype_nois(size_t __refs = 0): locale::facet(__refs) { }      virtual       ~_Ctype_nois() { }            virtual char_type       do_toupper(char_type) const = 0;      virtual const char_type*      do_toupper(char_type* __low, const char_type* __high) const = 0;      virtual char_type       do_tolower(char_type) const = 0;      virtual const char_type*      do_tolower(char_type* __low, const char_type* __high) const = 0;            virtual char_type       do_widen(char) const = 0;      virtual const char*      do_widen(const char* __low, const char* __high,	       char_type* __dest) const = 0;      virtual char       do_narrow(char_type, char __dfault) const = 0;      virtual const char_type*      do_narrow(const char_type* __low, const char_type* __high,		 char __dfault, char* __dest) const = 0;    };  template<typename _CharT>    class _Ctype : public _Ctype_nois<_CharT>    {      // Types:      typedef _CharT char_type;    public:      bool       is(mask __m, char_type __c) const      { return this->do_is(__m, __c); }      const char_type*      is(const char_type *__lo, const char_type *__hi, mask *__vec) const         { return this->do_is(__lo, __hi, __vec); }      const char_type*      scan_is(mask __m, const char_type* __lo, const char_type* __hi) const      { return this->do_scan_is(__m, __lo, __hi); }      const char_type*      scan_not(mask __m, const char_type* __lo, const char_type* __hi) const      { return this->do_scan_not(__m, __lo, __hi); }    protected:      explicit       _Ctype(size_t __refs = 0) : _Ctype_nois<_CharT>(__refs) { }      virtual       ~_Ctype() { }      virtual bool       do_is(mask __m, char_type __c) const = 0;      virtual const char_type*      do_is(const char_type* __lo, const char_type* __hi, 	    mask* __vec) const = 0;      virtual const char_type*      do_scan_is(mask __m, const char_type* __lo, 		 const char_type* __hi) const = 0;      virtual const char_type*      do_scan_not(mask __m, const char_type* __lo, 		  const char_type* __hi) const = 0;    };  template<typename _CharT>    class ctype : public _Ctype<_CharT>    {      // Types:      typedef _CharT char_type;    public:      explicit       ctype(size_t __refs = 0) : _Ctype<_CharT>(__refs) { }      static locale::id id;   protected:      virtual       ~ctype() { }      virtual bool       do_is(mask __m, char_type __c) const      {	// XXX Need definitions for these abstract mf's.      }      virtual const char_type*      do_is(const char_type* __lo, const char_type* __hi, 	    mask* __vec) const      {	// XXX Need definitions for these abstract mf's.      }      virtual const char_type*      do_scan_is(mask __m, const char_type* __lo, 		 const char_type* __hi) const      {	// XXX Need definitions for these abstract mf's.      }      virtual const char_type*      do_scan_not(mask __m, const char_type* __lo, 		  const char_type* __hi) const      {	// XXX Need definitions for these abstract mf's.      }      virtual char_type       do_toupper(char_type) const      {	// XXX Need definitions for these abstract mf's.      }      virtual const char_type*      do_toupper(char_type* __low, const char_type* __high) const      {	// XXX Need definitions for these abstract mf's.      }      virtual char_type       do_tolower(char_type) const      {	// XXX Need definitions for these abstract mf's.      }      virtual const char_type*      do_tolower(char_type* __low, const char_type* __high) const      {	// XXX Need definitions for these abstract mf's.      }            virtual char_type       do_widen(char) const      {	// XXX Need definitions for these abstract mf's.      }      virtual const char*      do_widen(const char* __low, const char* __high,	       char_type* __dest) const      {	// XXX Need definitions for these abstract mf's.      }      virtual char       do_narrow(char_type, char __dfault) const      {	// XXX Need definitions for these abstract mf's.      }      virtual const char_type*      do_narrow(const char_type* __low, const char_type* __high,		 char __dfault, char* __dest) const      {	// XXX Need definitions for these abstract mf's.      }    };  // 22.2.1.3  ctype specializations  // NB: Can use _Ctype_nois to actually implement the is  // functionality in the non-virtual (thus inline-able) member  // fuctions.  template<>    class ctype<char> : public _Ctype_nois<char>    {      // Types:      typedef char char_type;    private:      // Data Members:      const mask* 		_M_table;      bool 			_M_del;      static const int* const& 	_S_toupper;      static const int* const& 	_S_tolower;      static const mask* const& _S_table;          public:      static locale::id 	id;      static const size_t      table_size = 1 + static_cast<unsigned char>(-1);      explicit       ctype(const mask* __table = 0, bool __del = false, 	    size_t __refs = 0) throw()      : _Ctype_nois<char>(__refs), _M_table(__table == 0 ? _S_table: __table), 	_M_del(__table != 0 && __del)      { }      bool       is(mask __m, char __c) const throw()      { return _M_table[(unsigned char)(__c)] & __m; }      const char*      is(const char* __low, const char* __high, mask* __vec) const throw()      {	while (__low < __high)	  *__vec++ = _M_table[(unsigned char)(*__low++)];	return __high;      }      const char*      scan_is(mask __m, const char* __low, const char* __high) const throw()      {	while (__low < __high && !(_M_table[(unsigned char)(*__low)] & __m))	  ++__low;	return __low;      }      const char*      scan_not(mask __m, const char* __low, const char* __high) const throw()      {	while (__low < __high 	       && (_M_table[(unsigned char)(*__low)] & __m) != 0)	  ++__low;	return __low;      }         protected:      virtual       ~ctype();      inline const mask*       table() const throw()      { return _M_table; }      inline static const mask*       classic_table() throw()      { return _S_table; }      virtual char_type       do_toupper(char_type) const;      virtual const char_type*      do_toupper(char_type* __low, const char_type* __high) const;      virtual char_type       do_tolower(char_type) const;      virtual const char_type*      do_tolower(char_type* __low, const char_type* __high) const;            virtual char_type       do_widen(char) const;      virtual const char*      do_widen(const char* __low, const char* __high,	       char_type* __dest) const;      virtual char       do_narrow(char_type, char __dfault) const;      virtual const char_type*      do_narrow(const char_type* __low, const char_type* __high,		 char __dfault, char* __dest) const;    };  template<>    inline const ctype<char>&    use_facet< const ctype<char> > (const locale& __loc);#ifdef _GLIBCPP_USE_WCHAR_T  // ctype<wchar_t> specialization  // XXX Not done, need missing member functions.  template<>    class ctype<wchar_t> : public _Ctype<wchar_t>    {      // Types:      typedef wchar_t char_type;    public:      explicit ctype(size_t __refs = 0);      static locale::id id;    private:      static const int* const& _S_toupper;      static const int* const& _S_tolower;      static const mask* const& _S_table;      static const int _S_table_size = ctype<char>::table_size;          protected:      virtual       ~ctype();      virtual bool       do_is(mask __m, char_type __c) const;      virtual const char_type*      do_is(const char_type* __lo, const char_type* __hi, 	    mask* __vec) const;      virtual const char_type*      do_scan_is(mask __m, const char_type* __lo, 		 const char_type* __hi) const;      virtual const char_type*      do_scan_not(mask __m, const char_type* __lo, 		  const char_type* __hi) const;      virtual char_type       do_toupper(char_type) const;      virtual const char_type*      do_toupper(char_type* __low, const char_type* __high) const;      virtual char_type       do_tolower(char_type) const;      virtual const char_type*      do_tolower(char_type* __low, const char_type* __high) const;            virtual char_type       do_widen(char) const;      virtual const char*      do_widen(const char* __low, const char* __high,	       char_type* __dest) const;      virtual char       do_narrow(char_type, char __dfault) const;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -