]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c++/stl/stl/_ctype.h
Add STLport 5.1.4
[polintos/scott/priv.git] / include / c++ / stl / stl / _ctype.h
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
29 #ifndef _STLP_INTERNAL_LOCALE_H
30 #  include <stl/_locale.h>
31 #endif
32
33 #ifndef _STLP_INTERNAL_ALGOBASE_H
34 #  include <stl/_algobase.h>
35 #endif
36
37 _STLP_BEGIN_NAMESPACE
38
39 class _STLP_CLASS_DECLSPEC ctype_base {
40 public:
41   enum mask {
42     space   = _Locale_SPACE,
43     print   = _Locale_PRINT,
44     cntrl   = _Locale_CNTRL,
45     upper   = _Locale_UPPER,
46     lower   = _Locale_LOWER,
47     alpha   = _Locale_ALPHA,
48     digit   = _Locale_DIGIT,
49     punct   = _Locale_PUNCT,
50     xdigit  = _Locale_XDIGIT,
51     alnum   = alpha | digit,
52     graph   = alnum | punct
53   };
54 };
55
56 // ctype<> template
57
58 template <class charT> class ctype {};
59 template <class charT> class ctype_byname {};
60
61 //ctype specializations
62
63 _STLP_TEMPLATE_NULL
64 class _STLP_CLASS_DECLSPEC ctype<char> : public locale::facet, public ctype_base {
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_impl;
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   static _STLP_STATIC_MEMBER_DECLSPEC 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;
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 protected:
146   const mask* _M_ctype_table;
147 private:
148   bool _M_delete;
149 };
150
151 _STLP_TEMPLATE_NULL
152 class _STLP_CLASS_DECLSPEC ctype_byname<char>: public ctype<char> {
153 public:
154   explicit ctype_byname(const char*, size_t = 0, _Locale_name_hint* __hint = 0);
155   ~ctype_byname();
156
157   virtual char        do_toupper(char __c) const;
158   virtual char        do_tolower(char __c) const;
159
160   virtual const char* do_toupper(char*, const char*) const;
161   virtual const char* do_tolower(char*, const char*) const;
162
163 private:
164   mask _M_byname_table[table_size];
165   _Locale_ctype* _M_ctype;
166
167   //explicitely defined as private to avoid warnings:
168   typedef ctype_byname<char> _Self;
169   ctype_byname(_Self const&);
170   _Self& operator = (_Self const&);
171   friend _Locale_name_hint* _Locale_extract_hint(ctype_byname<char>*);
172 };
173
174 #  ifndef _STLP_NO_WCHAR_T
175 _STLP_TEMPLATE_NULL
176 class _STLP_CLASS_DECLSPEC ctype<wchar_t> : public locale::facet, public ctype_base
177 {
178   friend class _Locale_impl;
179 public:
180   typedef wchar_t char_type;
181
182   explicit ctype(size_t __refs = 0) : locale::facet(__refs) {}
183
184   bool is(mask __m, wchar_t __c) const
185     { return do_is(__m, __c); }
186
187   const wchar_t* is(const wchar_t* __low, const wchar_t* __high,
188                     mask* __vec) const
189     { return do_is(__low, __high, __vec); }
190
191   const wchar_t* scan_is(mask __m,
192                          const wchar_t* __low, const wchar_t* __high) const
193     { return do_scan_is(__m, __low, __high); }
194
195   const wchar_t* scan_not (mask __m,
196                            const wchar_t* __low, const wchar_t* __high) const
197     { return do_scan_not(__m, __low, __high); }
198
199   wchar_t (toupper)(wchar_t __c) const { return do_toupper(__c); }
200   const wchar_t* (toupper)(wchar_t* __low, const wchar_t* __high) const
201     { return do_toupper(__low, __high); }
202
203   wchar_t (tolower)(wchar_t __c) const { return do_tolower(__c); }
204   const wchar_t* (tolower)(wchar_t* __low, const wchar_t* __high) const
205     { return do_tolower(__low, __high); }
206
207   wchar_t widen(char __c) const { return do_widen(__c); }
208   const char* widen(const char* __low, const char* __high,
209                     wchar_t* __to) const
210     { return do_widen(__low, __high, __to); }
211
212   char narrow(wchar_t __c, char __dfault) const
213     { return do_narrow(__c, __dfault); }
214   const wchar_t* narrow(const wchar_t* __low, const wchar_t* __high,
215                         char __dfault, char* __to) const
216     { return do_narrow(__low, __high, __dfault, __to); }
217
218   static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
219
220 protected:
221   ~ctype();
222
223   virtual bool           do_is(mask __m, wchar_t __c) const;
224   virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const;
225   virtual const wchar_t* do_scan_is(mask,
226                                     const wchar_t*, const wchar_t*) const;
227   virtual const wchar_t* do_scan_not(mask,
228                                      const wchar_t*, const wchar_t*) const;
229   virtual wchar_t do_toupper(wchar_t __c) const;
230   virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const;
231   virtual wchar_t do_tolower(wchar_t c) const;
232   virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const;
233   virtual wchar_t do_widen(char c) const;
234   virtual const char* do_widen(const char*, const char*, wchar_t*) const;
235   virtual char  do_narrow(wchar_t __c, char __dfault) const;
236   virtual const wchar_t* do_narrow(const wchar_t*, const wchar_t*,
237                                    char, char*) const;
238 };
239
240 _STLP_TEMPLATE_NULL
241 class _STLP_CLASS_DECLSPEC ctype_byname<wchar_t>: public ctype<wchar_t> {
242 public:
243   explicit ctype_byname(const char* __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
244
245 protected:
246   ~ctype_byname();
247
248   virtual bool           do_is(mask __m, wchar_t __c) const;
249   virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const;
250   virtual const wchar_t* do_scan_is(mask,
251                                     const wchar_t*, const wchar_t*) const;
252   virtual const wchar_t* do_scan_not(mask,
253                                      const wchar_t*, const wchar_t*) const;
254   virtual wchar_t do_toupper(wchar_t __c) const;
255   virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const;
256   virtual wchar_t do_tolower(wchar_t c) const;
257   virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const;
258
259 private:
260   _Locale_ctype* _M_ctype;
261
262   //explicitely defined as private to avoid warnings:
263   typedef ctype_byname<wchar_t> _Self;
264   ctype_byname(_Self const&);
265   _Self& operator = (_Self const&);
266 };
267
268 #  endif /* WCHAR_T */
269
270 _STLP_END_NAMESPACE
271
272 #endif /* _STLP_INTERNAL_CTYPE_H */
273
274 // Local Variables:
275 // mode:C++
276 // End:
277