• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 public:
74 
75   typedef char char_type;
76 
77   explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
is(mask __m,char __c)78   bool is(mask __m, char __c) const
79   { return ((*(_M_ctype_table+(unsigned char)__c)) & __m) != 0; }
80 
is(const char * __low,const char * __high,mask * __vec)81   const char* is(const char* __low, const char* __high, mask* __vec) const {
82     for (const char* __p = __low;__p != __high; ++__p, ++__vec) {
83       *__vec = _M_ctype_table[(unsigned char)*__p];
84     }
85     return __high;
86   }
87 
88   const char* scan_is(mask __m, const char* __low, const char* __high) const;
89   const char* scan_not(mask __m, const char* __low, const char* __high) const;
90 
91   char        (toupper)(char __c) const { return do_toupper(__c); }
92   const char* (toupper)(char* __low, const char* __high) const {
93     return do_toupper(__low, __high);
94   }
95 
96   char        (tolower)(char __c) const { return do_tolower(__c); }
97   const char* (tolower)(char* __low, const char* __high) const {
98     return do_tolower(__low, __high);
99   }
100 
widen(char __c)101   char        widen(char __c) const { return do_widen(__c); }
widen(const char * __low,const char * __high,char * __to)102   const char* widen(const char* __low, const char* __high, char* __to) const {
103     return do_widen(__low, __high, __to);
104   }
105 
narrow(char __c,char __dfault)106   char        narrow(char __c, char __dfault) const {
107     return do_narrow(__c, __dfault);
108   }
narrow(const char * __low,const char * __high,char __dfault,char * __to)109   const char* narrow(const char* __low, const char* __high,
110                      char __dfault, char* __to) const {
111     return do_narrow(__low, __high, __dfault, __to);
112   }
113 
114   static _STLP_STATIC_DECLSPEC locale::id id;
115   _STLP_STATIC_CONSTANT(size_t, table_size = 256);
116 
117 protected:
table()118   const mask* table() const _STLP_NOTHROW { return _M_ctype_table; }
119   static const mask* _STLP_CALL classic_table() _STLP_NOTHROW;
120 
121   ~ctype();
122 
123   virtual char        do_toupper(char __c) const;
124   virtual char        do_tolower(char __c) const;
125   virtual const char* do_toupper(char* __low, const char* __high) const;
126   virtual const char* do_tolower(char* __low, const char* __high) const;
127   virtual char        do_widen(char __c) const;
128   virtual const char* do_widen(const char* __low, const char* __high,
129                                char* __to) const;
130   virtual char        do_narrow(char __c, char /* dfault */ ) const;
131   virtual const char* do_narrow(const char* __low, const char* __high,
132                                 char /* dfault */, char* __to) const;
133 private:
134   struct _Is_mask {
135     mask __m;
_Is_mask_Is_mask136     _Is_mask(mask __x): __m(__x) {}
operator_Is_mask137    bool operator()(char __c) {return (__m & (unsigned char) __c) != 0;}
138   };
139 
140 protected:
141   const mask* _M_ctype_table;
142 private:
143   bool _M_delete;
144 };
145 
146 _STLP_TEMPLATE_NULL
147 class _STLP_CLASS_DECLSPEC ctype_byname<char>: public ctype<char> {
148   friend class _Locale_impl;
149 public:
150   explicit ctype_byname(const char*, size_t = 0);
151   ~ctype_byname();
152 
153   virtual char        do_toupper(char __c) const;
154   virtual char        do_tolower(char __c) const;
155 
156   virtual const char* do_toupper(char*, const char*) const;
157   virtual const char* do_tolower(char*, const char*) const;
158 
159 private:
ctype_byname(_Locale_ctype * __ctype)160   ctype_byname(_Locale_ctype* __ctype)
161     : _M_ctype(__ctype)
162   { _M_init(); }
163 
164   void _M_init();
165 
166   //explicitely defined as private to avoid warnings:
167   typedef ctype_byname<char> _Self;
168   ctype_byname(_Self const&);
169   _Self& operator = (_Self const&);
170 
171   mask _M_byname_table[table_size];
172   _Locale_ctype* _M_ctype;
173 };
174 
175 #  ifndef _STLP_NO_WCHAR_T
176 _STLP_TEMPLATE_NULL
177 class _STLP_CLASS_DECLSPEC ctype<wchar_t> : public locale::facet, public ctype_base {
178 public:
179   typedef wchar_t char_type;
180 
facet(__refs)181   explicit ctype(size_t __refs = 0) : locale::facet(__refs) {}
182 
is(mask __m,wchar_t __c)183   bool is(mask __m, wchar_t __c) const
184     { return do_is(__m, __c); }
185 
is(const wchar_t * __low,const wchar_t * __high,mask * __vec)186   const wchar_t* is(const wchar_t* __low, const wchar_t* __high,
187                     mask* __vec) const
188     { return do_is(__low, __high, __vec); }
189 
scan_is(mask __m,const wchar_t * __low,const wchar_t * __high)190   const wchar_t* scan_is(mask __m,
191                          const wchar_t* __low, const wchar_t* __high) const
192     { return do_scan_is(__m, __low, __high); }
193 
scan_not(mask __m,const wchar_t * __low,const wchar_t * __high)194   const wchar_t* scan_not (mask __m,
195                            const wchar_t* __low, const wchar_t* __high) const
196     { return do_scan_not(__m, __low, __high); }
197 
wchar_t(toupper)198   wchar_t (toupper)(wchar_t __c) const { return do_toupper(__c); }
199   const wchar_t* (toupper)(wchar_t* __low, const wchar_t* __high) const
200     { return do_toupper(__low, __high); }
201 
wchar_t(tolower)202   wchar_t (tolower)(wchar_t __c) const { return do_tolower(__c); }
203   const wchar_t* (tolower)(wchar_t* __low, const wchar_t* __high) const
204     { return do_tolower(__low, __high); }
205 
widen(char __c)206   wchar_t widen(char __c) const { return do_widen(__c); }
widen(const char * __low,const char * __high,wchar_t * __to)207   const char* widen(const char* __low, const char* __high,
208                     wchar_t* __to) const
209     { return do_widen(__low, __high, __to); }
210 
narrow(wchar_t __c,char __dfault)211   char narrow(wchar_t __c, char __dfault) const
212     { return do_narrow(__c, __dfault); }
narrow(const wchar_t * __low,const wchar_t * __high,char __dfault,char * __to)213   const wchar_t* narrow(const wchar_t* __low, const wchar_t* __high,
214                         char __dfault, char* __to) const
215     { return do_narrow(__low, __high, __dfault, __to); }
216 
217   static _STLP_STATIC_DECLSPEC locale::id id;
218 
219 protected:
220   ~ctype();
221 
222   virtual bool           do_is(mask __m, wchar_t __c) const;
223   virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const;
224   virtual const wchar_t* do_scan_is(mask,
225                                     const wchar_t*, const wchar_t*) const;
226   virtual const wchar_t* do_scan_not(mask,
227                                      const wchar_t*, const wchar_t*) const;
228   virtual wchar_t do_toupper(wchar_t __c) const;
229   virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const;
230   virtual wchar_t do_tolower(wchar_t c) const;
231   virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const;
232   virtual wchar_t do_widen(char c) const;
233   virtual const char* do_widen(const char*, const char*, wchar_t*) const;
234   virtual char  do_narrow(wchar_t __c, char __dfault) const;
235   virtual const wchar_t* do_narrow(const wchar_t*, const wchar_t*,
236                                    char, char*) const;
237 };
238 
239 _STLP_TEMPLATE_NULL
240 class _STLP_CLASS_DECLSPEC ctype_byname<wchar_t>: public ctype<wchar_t> {
241   friend class _Locale_impl;
242 public:
243   explicit ctype_byname(const char* __name, size_t __refs = 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:
ctype_byname(_Locale_ctype * __ctype)260   ctype_byname(_Locale_ctype* __ctype)
261     : _M_ctype(__ctype) {}
262 
263   //explicitely defined as private to avoid warnings:
264   typedef ctype_byname<wchar_t> _Self;
265   ctype_byname(_Self const&);
266   _Self& operator = (_Self const&);
267 
268   _Locale_ctype* _M_ctype;
269 };
270 
271 #  endif /* WCHAR_T */
272 
273 _STLP_END_NAMESPACE
274 
275 #endif /* _STLP_INTERNAL_CTYPE_H */
276 
277 // Local Variables:
278 // mode:C++
279 // End:
280 
281