_ctype.h

00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999 
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted 
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */ 
00018 // WARNING: This is an internal header file, included by other C++
00019 // standard library headers.  You should not attempt to use this header
00020 // file directly.
00021 
00022 #ifndef _STLP_INTERNAL_CTYPE_H
00023 #define _STLP_INTERNAL_CTYPE_H
00024 
00025 # ifndef _STLP_C_LOCALE_H
00026 #  include <stl/c_locale.h>
00027 # endif
00028 # ifndef _STLP_INTERNAL_LOCALE_H
00029 #  include <stl/_locale.h>
00030 # endif
00031 # ifndef _STLP_INTERNAL_ALGOBASE_H
00032 #  include <stl/_algobase.h>
00033 # endif
00034 
00035 _STLP_BEGIN_NAMESPACE
00036 
00037 class _STLP_CLASS_DECLSPEC ctype_base {
00038 public:
00039   enum mask {
00040     space   = _Locale_SPACE,
00041     print   = _Locale_PRINT,
00042     cntrl   = _Locale_CNTRL,
00043     upper   = _Locale_UPPER,
00044     lower   = _Locale_LOWER,
00045     alpha   = _Locale_ALPHA,
00046     digit   = _Locale_DIGIT,
00047     punct   = _Locale_PUNCT,
00048     xdigit  = _Locale_XDIGIT,
00049     alnum   = alpha | digit,
00050     graph   = alnum | punct
00051   };
00052 };
00053 
00054 // ctype<> template
00055 
00056 template <class charT> class ctype {};
00057 template <class charT> class ctype_byname {};
00058 
00059 //ctype specializations
00060 
00061 _STLP_TEMPLATE_NULL
00062 class _STLP_CLASS_DECLSPEC ctype<char> :   public locale::facet, public ctype_base 
00063 {
00064 
00065 # ifndef _STLP_NO_WCHAR_T
00066 #  ifdef _STLP_MSVC
00067     typedef ctype<wchar_t> _Wctype;
00068     friend _Wctype;
00069 #  else
00070     friend class ctype<wchar_t>;
00071 #  endif
00072 # endif
00073   friend class _Locale;
00074 public:
00075 
00076   typedef char char_type;
00077 
00078   explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
00079   bool is(mask __m, char __c) const
00080     { return ((*(_M_ctype_table+(unsigned char)__c)) & __m) != 0; }
00081 
00082   const char* is(const char* __low, const char* __high, mask* __vec) const {
00083     for (const char* __p = __low;__p != __high; ++__p, ++__vec) {
00084       *__vec = _M_ctype_table[(unsigned char)*__p];
00085     }
00086     return __high;
00087   }
00088 
00089   const char* scan_is(mask __m, const char* __low, const char* __high) const;
00090   const char* scan_not(mask __m, const char* __low, const char* __high) const;
00091 
00092   char        (toupper)(char __c) const { return do_toupper(__c); }
00093   const char* (toupper)(char* __low, const char* __high) const { 
00094     return do_toupper(__low, __high); 
00095   }
00096 
00097   char        (tolower)(char __c) const { return do_tolower(__c); }
00098   const char* (tolower)(char* __low, const char* __high) const { 
00099     return do_tolower(__low, __high); 
00100   }
00101   
00102   char        widen(char __c) const { return do_widen(__c); }
00103   const char* widen(const char* __low, const char* __high, char* __to) const { 
00104     return do_widen(__low, __high, __to); 
00105   }
00106 
00107   char        narrow(char __c, char __dfault) const { 
00108     return do_narrow(__c, __dfault); 
00109   }
00110   const char* narrow(const char* __low, const char* __high,
00111                      char __dfault, char* __to) const { 
00112     return do_narrow(__low, __high, __dfault, __to); 
00113   }
00114 
00115   _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
00116 # if defined(_STLP_STATIC_CONST_INIT_BUG)
00117   enum __TableSize { table_size = 256 };
00118 # else
00119   static const size_t table_size = 256;
00120 # endif
00121 
00122 protected:
00123   const mask* table() const _STLP_NOTHROW {return _M_ctype_table;}
00124   static const mask* _STLP_CALL classic_table() _STLP_NOTHROW { return & _S_classic_table [1]; }
00125 
00126   ~ctype();
00127 
00128   virtual char        do_toupper(char __c) const;
00129   virtual char        do_tolower(char __c) const;
00130   virtual const char* do_toupper(char* __low, const char* __high) const;
00131   virtual const char* do_tolower(char* __low, const char* __high) const;
00132   virtual char        do_widen(char __c) const;
00133   virtual const char* do_widen(const char* __low, const char* __high,
00134                                char* __to) const;
00135   virtual char        do_narrow(char __c, char /* dfault */ ) const;
00136   virtual const char* do_narrow(const char* __low, const char* __high,
00137                                 char /* dfault */, char* __to) const;
00138 private:
00139   struct _Is_mask {
00140     mask __m;
00141     _Is_mask(mask __x): __m(__x) {}
00142    bool operator()(char __c) {return (__m & (unsigned char) __c) != 0;}
00143   };
00144 
00145   static const mask _S_classic_table[257 /* table_size + 1 */];
00146   const mask* _M_ctype_table;
00147   bool _M_delete;
00148 
00149   static const unsigned char _S_upper[256 /* table_size */];
00150   static const unsigned char _S_lower[256 /* table_size */];
00151 };
00152 
00153 _STLP_TEMPLATE_NULL
00154 class _STLP_CLASS_DECLSPEC ctype_byname<char>: public ctype<char> {
00155 public:
00156   explicit ctype_byname(const char*, size_t = 0);
00157   ~ctype_byname();
00158 
00159   virtual char        do_toupper(char __c) const;
00160   virtual char        do_tolower(char __c) const;
00161 
00162   virtual const char* do_toupper(char*, const char*) const;
00163   virtual const char* do_tolower(char*, const char*) const;
00164 
00165 private:
00166   mask _M_byname_table[table_size + 1];
00167   _Locale_ctype* _M_ctype;
00168 };
00169 
00170 
00171 # ifndef _STLP_NO_WCHAR_T
00172 _STLP_TEMPLATE_NULL
00173 class _STLP_CLASS_DECLSPEC ctype<wchar_t> : public locale::facet, public ctype_base 
00174 {
00175   friend class _Locale;
00176 public:
00177   typedef wchar_t char_type;
00178 
00179   explicit ctype(size_t __refs = 0) : _BaseFacet(__refs) {}
00180 
00181   bool is(mask __m, wchar_t __c) const
00182     { return do_is(__m, __c); }
00183 
00184   const wchar_t* is(const wchar_t* __low, const wchar_t* __high,
00185                     mask* __vec) const
00186     { return do_is(__low, __high, __vec); }
00187 
00188   const wchar_t* scan_is(mask __m, 
00189                          const wchar_t* __low, const wchar_t* __high) const
00190     { return do_scan_is(__m, __low, __high); }
00191 
00192   const wchar_t* scan_not (mask __m, 
00193                            const wchar_t* __low, const wchar_t* __high) const
00194     { return do_scan_not(__m, __low, __high); }
00195 
00196   wchar_t (toupper)(wchar_t __c) const { return do_toupper(__c); }
00197   const wchar_t* (toupper)(wchar_t* __low, wchar_t* __high) const
00198     { return do_toupper(__low, __high); }
00199 
00200   wchar_t (tolower)(wchar_t __c) const { return do_tolower(__c); }
00201   const wchar_t* (tolower)(wchar_t* __low, wchar_t* __high) const
00202     { return do_tolower(__low, __high); }
00203 
00204   wchar_t widen(char __c) const { return do_widen(__c); }
00205   const char* widen(const char* __low, const char* __high,
00206                     wchar_t* __to) const
00207     { return do_widen(__low, __high, __to); }
00208 
00209   char narrow(wchar_t __c, char __dfault) const
00210     { return do_narrow(__c, __dfault); }
00211   const wchar_t* narrow(const wchar_t* __low, const wchar_t* __high,
00212                         char __dfault, char* __to) const
00213     { return do_narrow(__low, __high, __dfault, __to); }
00214 
00215   _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
00216 
00217 protected:
00218   ~ctype();
00219 
00220   virtual bool           do_is(mask __m, wchar_t __c) const;
00221   virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const;
00222   virtual const wchar_t* do_scan_is(mask,
00223                                     const wchar_t*, const wchar_t*) const;
00224   virtual const wchar_t* do_scan_not(mask,
00225                                      const wchar_t*, const wchar_t*) const;
00226   virtual wchar_t do_toupper(wchar_t __c) const;
00227   virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const;
00228   virtual wchar_t do_tolower(wchar_t c) const;
00229   virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const;
00230   virtual wchar_t do_widen(char c) const;
00231   virtual const char* do_widen(const char*, const char*, wchar_t*) const;
00232   virtual char  do_narrow(wchar_t __c, char __dfault) const;
00233   virtual const wchar_t* do_narrow(const wchar_t*, const wchar_t*,
00234                                    char, char*) const;
00235 };
00236 
00237 _STLP_TEMPLATE_NULL
00238 class _STLP_CLASS_DECLSPEC ctype_byname<wchar_t>: public ctype<wchar_t> {
00239 public:
00240   explicit ctype_byname(const char* __name, size_t __refs = 0);
00241 
00242 protected:
00243   ~ctype_byname();
00244 
00245   virtual bool           do_is(mask __m, wchar_t __c) const;
00246   virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const;
00247   virtual const wchar_t* do_scan_is(mask,
00248                                     const wchar_t*, const wchar_t*) const;
00249   virtual const wchar_t* do_scan_not(mask,
00250                                      const wchar_t*, const wchar_t*) const;
00251   virtual wchar_t do_toupper(wchar_t __c) const;
00252   virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const;
00253   virtual wchar_t do_tolower(wchar_t c) const;
00254   virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const;
00255 
00256 private:
00257   _Locale_ctype* _M_ctype;
00258 };
00259 
00260 # endif /* WCHAR_T */
00261 
00262 _STLP_END_NAMESPACE
00263 
00264 #endif /* _STLP_INTERNAL_CTYPE_H */
00265 
00266 // Local Variables:
00267 // mode:C++
00268 // End:
00269 

Generated on Mon Jun 5 10:20:45 2006 for Intelligence.kdevelop by  doxygen 1.4.6