home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _ctype.h < prev    next >
C/C++ Source or Header  |  2001-01-26  |  9KB  |  270 lines

  1. /*
  2.  * Copyright (c) 1999
  3.  * Silicon Graphics Computer Systems, Inc.
  4.  *
  5.  * Copyright (c) 1999 
  6.  * Boris Fomitchev
  7.  *
  8.  * This material is provided "as is", with absolutely no warranty expressed
  9.  * or implied. Any use is at your own risk.
  10.  *
  11.  * Permission to use or copy this software for any purpose is hereby granted 
  12.  * without fee, provided the above notices are retained on all copies.
  13.  * Permission to modify the code and to distribute modified code is granted,
  14.  * provided the above notices are retained, and a notice that the code was
  15.  * modified is included with the above copyright notice.
  16.  *
  17.  */ 
  18. // WARNING: This is an internal header file, included by other C++
  19. // standard library headers.  You should not attempt to use this header
  20. // file directly.
  21.  
  22. #ifndef _STLP_INTERNAL_CTYPE_H
  23. #define _STLP_INTERNAL_CTYPE_H
  24.  
  25. # ifndef _STLP_C_LOCALE_H
  26. #  include <stl/c_locale.h>
  27. # endif
  28. # ifndef _STLP_INTERNAL_LOCALE_H
  29. #  include <stl/_locale.h>
  30. # endif
  31. # ifndef _STLP_INTERNAL_ALGOBASE_H
  32. #  include <stl/_algobase.h>
  33. # endif
  34.  
  35. _STLP_BEGIN_NAMESPACE
  36.  
  37. class _STLP_CLASS_DECLSPEC ctype_base {
  38. public:
  39.   enum mask {
  40.     space   = _Locale_SPACE,
  41.     print   = _Locale_PRINT,
  42.     cntrl   = _Locale_CNTRL,
  43.     upper   = _Locale_UPPER,
  44.     lower   = _Locale_LOWER,
  45.     alpha   = _Locale_ALPHA,
  46.     digit   = _Locale_DIGIT,
  47.     punct   = _Locale_PUNCT,
  48.     xdigit  = _Locale_XDIGIT,
  49.     alnum   = alpha | digit,
  50.     graph   = alnum | punct
  51.   };
  52. };
  53.  
  54. // ctype<> template
  55.  
  56. template <class charT> class ctype {};
  57. template <class charT> class ctype_byname {};
  58.  
  59. //ctype specializations
  60.  
  61. _STLP_TEMPLATE_NULL
  62. class _STLP_CLASS_DECLSPEC ctype<char> :   public locale::facet, public ctype_base 
  63. {
  64.  
  65. # ifndef _STLP_NO_WCHAR_T
  66. #  ifdef _STLP_MSVC
  67.     typedef ctype<wchar_t> _Wctype;
  68.     friend _Wctype;
  69. #  else
  70.     friend class ctype<wchar_t>;
  71. #  endif
  72. # endif
  73.   friend class _Locale;
  74. public:
  75.  
  76.   typedef char char_type;
  77.  
  78.   explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
  79.   bool is(mask __m, char __c) const
  80.     { return ((*(_M_ctype_table+(unsigned char)__c)) & __m) != 0; }
  81.  
  82.   const char* is(const char* __low, const char* __high, mask* __vec) const {
  83.     for (const char* __p = __low;__p != __high; ++__p, ++__vec) {
  84.       *__vec = _M_ctype_table[(unsigned char)*__p];
  85.     }
  86.     return __high;
  87.   }
  88.  
  89.   const char* scan_is(mask __m, const char* __low, const char* __high) const;
  90.   const char* scan_not(mask __m, const char* __low, const char* __high) const;
  91.  
  92.   char        (toupper)(char __c) const { return do_toupper(__c); }
  93.   const char* (toupper)(char* __low, const char* __high) const { 
  94.     return do_toupper(__low, __high); 
  95.   }
  96.  
  97.   char        (tolower)(char __c) const { return do_tolower(__c); }
  98.   const char* (tolower)(char* __low, const char* __high) const { 
  99.     return do_tolower(__low, __high); 
  100.   }
  101.   
  102.   char        widen(char __c) const { return do_widen(__c); }
  103.   const char* widen(const char* __low, const char* __high, char* __to) const { 
  104.     return do_widen(__low, __high, __to); 
  105.   }
  106.  
  107.   char        narrow(char __c, char __dfault) const { 
  108.     return do_narrow(__c, __dfault); 
  109.   }
  110.   const char* narrow(const char* __low, const char* __high,
  111.                      char __dfault, char* __to) const { 
  112.     return do_narrow(__low, __high, __dfault, __to); 
  113.   }
  114.  
  115.   _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
  116. # if defined(_STLP_STATIC_CONST_INIT_BUG)
  117.   enum __TableSize { table_size = 256 };
  118. # else
  119.   static const size_t table_size = 256;
  120. # endif
  121.  
  122. protected:
  123.   const mask* table() const _STLP_NOTHROW {return _M_ctype_table;}
  124.   static const mask* _STLP_CALL classic_table() _STLP_NOTHROW { return & _S_classic_table [1]; }
  125.  
  126.   ~ctype();
  127.  
  128.   virtual char        do_toupper(char __c) const;
  129.   virtual char        do_tolower(char __c) const;
  130.   virtual const char* do_toupper(char* __low, const char* __high) const;
  131.   virtual const char* do_tolower(char* __low, const char* __high) const;
  132.   virtual char        do_widen(char __c) const;
  133.   virtual const char* do_widen(const char* __low, const char* __high,
  134.                                char* __to) const;
  135.   virtual char        do_narrow(char __c, char /* dfault */ ) const;
  136.   virtual const char* do_narrow(const char* __low, const char* __high,
  137.                                 char /* dfault */, char* __to) const;
  138. private:
  139.   struct _Is_mask {
  140.     mask __m;
  141.     _Is_mask(mask __x): __m(__x) {}
  142.    bool operator()(char __c) {return (__m & (unsigned char) __c) != 0;}
  143.   };
  144.  
  145.   static const mask _S_classic_table[257 /* table_size + 1 */];
  146.   const mask* _M_ctype_table;
  147.   bool _M_delete;
  148.  
  149.   static const unsigned char _S_upper[256 /* table_size */];
  150.   static const unsigned char _S_lower[256 /* table_size */];
  151. };
  152.  
  153. _STLP_TEMPLATE_NULL
  154. class _STLP_CLASS_DECLSPEC ctype_byname<char>: public ctype<char> {
  155. public:
  156.   explicit ctype_byname(const char*, size_t = 0);
  157.   ~ctype_byname();
  158.  
  159.   virtual char        do_toupper(char __c) const;
  160.   virtual char        do_tolower(char __c) const;
  161.  
  162.   virtual const char* do_toupper(char*, const char*) const;
  163.   virtual const char* do_tolower(char*, const char*) const;
  164.  
  165. private:
  166.   mask _M_byname_table[table_size + 1];
  167.   _Locale_ctype* _M_ctype;
  168. };
  169.  
  170.  
  171. # ifndef _STLP_NO_WCHAR_T
  172. _STLP_TEMPLATE_NULL
  173. class _STLP_CLASS_DECLSPEC ctype<wchar_t> : public locale::facet, public ctype_base 
  174. {
  175.   friend class _Locale;
  176. public:
  177.   typedef wchar_t char_type;
  178.  
  179.   explicit ctype(size_t __refs = 0) : _BaseFacet(__refs) {}
  180.  
  181.   bool is(mask __m, wchar_t __c) const
  182.     { return do_is(__m, __c); }
  183.  
  184.   const wchar_t* is(const wchar_t* __low, const wchar_t* __high,
  185.                     mask* __vec) const
  186.     { return do_is(__low, __high, __vec); }
  187.  
  188.   const wchar_t* scan_is(mask __m, 
  189.                          const wchar_t* __low, const wchar_t* __high) const
  190.     { return do_scan_is(__m, __low, __high); }
  191.  
  192.   const wchar_t* scan_not (mask __m, 
  193.                            const wchar_t* __low, const wchar_t* __high) const
  194.     { return do_scan_not(__m, __low, __high); }
  195.  
  196.   wchar_t (toupper)(wchar_t __c) const { return do_toupper(__c); }
  197.   const wchar_t* (toupper)(wchar_t* __low, wchar_t* __high) const
  198.     { return do_toupper(__low, __high); }
  199.  
  200.   wchar_t (tolower)(wchar_t __c) const { return do_tolower(__c); }
  201.   const wchar_t* (tolower)(wchar_t* __low, wchar_t* __high) const
  202.     { return do_tolower(__low, __high); }
  203.  
  204.   wchar_t widen(char __c) const { return do_widen(__c); }
  205.   const char* widen(const char* __low, const char* __high,
  206.                     wchar_t* __to) const
  207.     { return do_widen(__low, __high, __to); }
  208.  
  209.   char narrow(wchar_t __c, char __dfault) const
  210.     { return do_narrow(__c, __dfault); }
  211.   const wchar_t* narrow(const wchar_t* __low, const wchar_t* __high,
  212.                         char __dfault, char* __to) const
  213.     { return do_narrow(__low, __high, __dfault, __to); }
  214.  
  215.   _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
  216.  
  217. protected:
  218.   ~ctype();
  219.  
  220.   virtual bool           do_is(mask __m, wchar_t __c) const;
  221.   virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const;
  222.   virtual const wchar_t* do_scan_is(mask,
  223.                                     const wchar_t*, const wchar_t*) const;
  224.   virtual const wchar_t* do_scan_not(mask,
  225.                                      const wchar_t*, const wchar_t*) const;
  226.   virtual wchar_t do_toupper(wchar_t __c) const;
  227.   virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const;
  228.   virtual wchar_t do_tolower(wchar_t c) const;
  229.   virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const;
  230.   virtual wchar_t do_widen(char c) const;
  231.   virtual const char* do_widen(const char*, const char*, wchar_t*) const;
  232.   virtual char  do_narrow(wchar_t __c, char __dfault) const;
  233.   virtual const wchar_t* do_narrow(const wchar_t*, const wchar_t*,
  234.                                    char, char*) const;
  235. };
  236.  
  237. _STLP_TEMPLATE_NULL
  238. class _STLP_CLASS_DECLSPEC ctype_byname<wchar_t>: public ctype<wchar_t> {
  239. public:
  240.   explicit ctype_byname(const char* __name, size_t __refs = 0);
  241.  
  242. protected:
  243.   ~ctype_byname();
  244.  
  245.   virtual bool           do_is(mask __m, wchar_t __c) const;
  246.   virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const;
  247.   virtual const wchar_t* do_scan_is(mask,
  248.                                     const wchar_t*, const wchar_t*) const;
  249.   virtual const wchar_t* do_scan_not(mask,
  250.                                      const wchar_t*, const wchar_t*) const;
  251.   virtual wchar_t do_toupper(wchar_t __c) const;
  252.   virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const;
  253.   virtual wchar_t do_tolower(wchar_t c) const;
  254.   virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const;
  255.  
  256. private:
  257.   _Locale_ctype* _M_ctype;
  258. };
  259.  
  260. # endif /* WCHAR_T */
  261.  
  262. _STLP_END_NAMESPACE
  263.  
  264. #endif /* _STLP_INTERNAL_CTYPE_H */
  265.  
  266. // Local Variables:
  267. // mode:C++
  268. // End:
  269.  
  270.