1 _ctype.h |
1 /* |
|
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. |
|
3 * |
|
4 * Copyright (c) 1999 |
|
5 * Silicon Graphics Computer Systems, Inc. |
|
6 * |
|
7 * Copyright (c) 1999 |
|
8 * Boris Fomitchev |
|
9 * |
|
10 * This material is provided "as is", with absolutely no warranty expressed |
|
11 * or implied. Any use is at your own risk. |
|
12 * |
|
13 * Permission to use or copy this software for any purpose is hereby granted |
|
14 * without fee, provided the above notices are retained on all copies. |
|
15 * Permission to modify the code and to distribute modified code is granted, |
|
16 * provided the above notices are retained, and a notice that the code was |
|
17 * modified is included with the above copyright notice. |
|
18 * |
|
19 */ |
|
20 // WARNING: This is an internal header file, included by other C++ |
|
21 // standard library headers. You should not attempt to use this header |
|
22 // file directly. |
|
23 |
|
24 #ifndef _STLP_INTERNAL_CTYPE_H |
|
25 #define _STLP_INTERNAL_CTYPE_H |
|
26 |
|
27 # ifndef _STLP_C_LOCALE_H |
|
28 # include <stl/c_locale.h> |
|
29 # endif |
|
30 # ifndef _STLP_INTERNAL_LOCALE_H |
|
31 # include <stl/_locale.h> |
|
32 # endif |
|
33 # ifndef _STLP_INTERNAL_ALGOBASE_H |
|
34 # include <stl/_algobase.h> |
|
35 # endif |
|
36 |
|
37 #ifdef __SYMBIAN32__ |
|
38 #include<typeinfo> |
|
39 #endif |
|
40 _STLP_BEGIN_NAMESPACE |
|
41 |
|
42 class _STLP_CLASS_DECLSPEC ctype_base { |
|
43 public: |
|
44 enum mask { |
|
45 space = _Locale_SPACE, |
|
46 print = _Locale_PRINT, |
|
47 cntrl = _Locale_CNTRL, |
|
48 upper = _Locale_UPPER, |
|
49 lower = _Locale_LOWER, |
|
50 alpha = _Locale_ALPHA, |
|
51 digit = _Locale_DIGIT, |
|
52 punct = _Locale_PUNCT, |
|
53 xdigit = _Locale_XDIGIT, |
|
54 alnum = alpha | digit, |
|
55 graph = alnum | punct |
|
56 }; |
|
57 }; |
|
58 |
|
59 // ctype<> template |
|
60 #ifdef __SYMBIAN32__ |
|
61 |
|
62 _STLP_DECLSPEC const ctype_base::mask* _get_classic_table(); |
|
63 _STLP_DECLSPEC const unsigned char* _get_S_upper_table(); |
|
64 _STLP_DECLSPEC const unsigned char* _get_S_lower_table(); |
|
65 extern locale::id& Ctype_charT_GetFacetLocaleId(const char* type); |
|
66 |
|
67 _STLP_DECLSPEC _Locale_ctype* __acquire_ctypeE(const char* ); |
|
68 _STLP_DECLSPEC void __release_ctypeE(_Locale_ctype* ); |
|
69 _STLP_DECLSPEC ctype_base::mask __Locale_ctypeE(_Locale_ctype* , wint_t c, ctype_base::mask); |
|
70 _STLP_DECLSPEC wint_t __Locale_toupperE(_Locale_ctype* , wint_t ); |
|
71 _STLP_DECLSPEC wint_t __Locale_tolowerE(_Locale_ctype* , wint_t ); |
|
72 |
|
73 |
|
74 template <class charT> |
|
75 class ctype: public locale::facet, public ctype_base { |
|
76 friend class _Locale; |
|
77 |
|
78 public: |
|
79 |
|
80 typedef charT char_type; |
|
81 |
|
82 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) |
|
83 static locale::id& GetFacetLocaleId(){return Ctype_charT_GetFacetLocaleId(typeid(charT).name()); } |
|
84 #else |
|
85 static locale::id id; |
|
86 #endif |
|
87 # if defined(_STLP_STATIC_CONST_INIT_BUG) |
|
88 enum __TableSize { table_size = 256 }; |
|
89 # else |
|
90 static const size_t table_size = 256; |
|
91 # endif |
|
92 |
|
93 |
|
94 explicit ctype(size_t __refs = 0) : _BaseFacet(__refs) { |
|
95 } |
|
96 bool is(mask __m, char_type __c) const |
|
97 { |
|
98 return do_is(__m ,__c); |
|
99 } |
|
100 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const |
|
101 { |
|
102 return do_is(__low, __high, __vec); |
|
103 } |
|
104 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const |
|
105 { |
|
106 return do_scan_is(__m, __low, __high); |
|
107 } |
|
108 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const |
|
109 { |
|
110 return do_scan_not(__m, __low, __high); |
|
111 |
|
112 } |
|
113 //need to function object like _Ctype_w_is_mask |
|
114 char_type toupper(char_type __c) const |
|
115 { |
|
116 return do_toupper(__c); |
|
117 } |
|
118 const char_type* toupper(char_type* __low, const char_type* __high) const |
|
119 { |
|
120 return do_toupper(__low, __high); |
|
121 } |
|
122 char_type tolower(char_type __c) const |
|
123 { |
|
124 return do_tolower(__c); |
|
125 } |
|
126 const char_type* tolower(char_type* __low, const char_type* __high) const |
|
127 { |
|
128 return do_tolower(__low, __high); |
|
129 } |
|
130 //use api's from c_locale_libc.cpp |
|
131 |
|
132 char_type widen(char __c) const |
|
133 { |
|
134 return do_widen(__c); |
|
135 } |
|
136 const char* widen(const char* __low, const char* __high, char_type* __to) const |
|
137 { |
|
138 return do_widen(__low, __high, __to); |
|
139 } |
|
140 char narrow(char_type __c, char __dfault) const |
|
141 { |
|
142 return do_narrow(__c, __dfault); |
|
143 } |
|
144 const char_type* narrow(const char_type* __low, const char_type* __high, |
|
145 char __dfault, char* __to) const |
|
146 { |
|
147 return do_narrow( __low, __high, __dfault, __to); |
|
148 } |
|
149 |
|
150 protected: |
|
151 ~ctype(); |
|
152 |
|
153 virtual bool do_is(mask __m, char_type __c) const; |
|
154 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; |
|
155 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; |
|
156 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; |
|
157 virtual char_type do_toupper(char_type __c) const; |
|
158 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; |
|
159 virtual char_type do_tolower(char_type __c) const; |
|
160 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; |
|
161 virtual char_type do_widen(char __c) const; |
|
162 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; |
|
163 virtual char do_narrow(char_type __c, char __dfault) const; |
|
164 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, |
|
165 char __dfault, char* __to) const; |
|
166 |
|
167 private: |
|
168 |
|
169 }; |
|
170 |
|
171 template <class charT> |
|
172 class ctype_byname: public ctype<charT> { |
|
173 public: |
|
174 explicit ctype_byname(const char* __name, size_t __refs = 0); |
|
175 |
|
176 protected: |
|
177 ~ctype_byname(); |
|
178 |
|
179 virtual bool do_is(ctype_base::mask __m, charT __c) const; |
|
180 virtual const charT* do_is(const charT*, const charT*, ctype_base::mask*) const; |
|
181 virtual const charT* do_scan_is(ctype_base::mask, |
|
182 const charT*, const charT*) const; |
|
183 virtual const charT* do_scan_not(ctype_base::mask, |
|
184 const charT*, const charT*) const; |
|
185 virtual charT do_toupper(charT c) const; |
|
186 virtual const charT* do_toupper(charT*, const charT*) const; |
|
187 virtual charT do_tolower(charT c) const; |
|
188 virtual const charT* do_tolower(charT*, const charT*) const; |
|
189 |
|
190 private: |
|
191 _Locale_ctype* _M_ctype; |
|
192 }; |
|
193 |
|
194 |
|
195 |
|
196 #else |
|
197 template <class charT> class ctype {}; |
|
198 template <class charT> class ctype_byname {}; |
|
199 #endif |
|
200 |
|
201 //ctype specializations |
|
202 |
|
203 _STLP_TEMPLATE_NULL |
|
204 #ifdef __SYMBIAN32__ |
|
205 class ctype <char> : public locale::facet, public ctype_base |
|
206 #else |
|
207 class _STLP_CLASS_DECLSPEC ctype<char> : public locale::facet, public ctype_base |
|
208 #endif |
|
209 { |
|
210 |
|
211 # ifndef _STLP_NO_WCHAR_T |
|
212 # ifdef _STLP_MSVC |
|
213 typedef ctype<wchar_t> _Wctype; |
|
214 friend _Wctype; |
|
215 # else |
|
216 friend class ctype<wchar_t>; |
|
217 # endif |
|
218 # endif |
|
219 friend class _Locale; |
|
220 public: |
|
221 |
|
222 typedef char char_type; |
|
223 |
|
224 _STLP_DECLSPEC explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0); |
|
225 bool is(mask __m, char __c) const |
|
226 { return ((*(_M_ctype_table+(unsigned char)__c)) & __m) != 0; } |
|
227 |
|
228 const char* is(const char* __low, const char* __high, mask* __vec) const { |
|
229 for (const char* __p = __low;__p != __high; ++__p, ++__vec) { |
|
230 *__vec = _M_ctype_table[(unsigned char)*__p]; |
|
231 } |
|
232 return __high; |
|
233 } |
|
234 |
|
235 _STLP_DECLSPEC const char* scan_is(mask __m, const char* __low, const char* __high) const; |
|
236 _STLP_DECLSPEC const char* scan_not(mask __m, const char* __low, const char* __high) const; |
|
237 |
|
238 char (toupper)(char __c) const { return do_toupper(__c); } |
|
239 const char* (toupper)(char* __low, const char* __high) const { |
|
240 return do_toupper(__low, __high); |
|
241 } |
|
242 |
|
243 char (tolower)(char __c) const { return do_tolower(__c); } |
|
244 const char* (tolower)(char* __low, const char* __high) const { |
|
245 return do_tolower(__low, __high); |
|
246 } |
|
247 |
|
248 char widen(char __c) const { return do_widen(__c); } |
|
249 const char* widen(const char* __low, const char* __high, char* __to) const { |
|
250 return do_widen(__low, __high, __to); |
|
251 } |
|
252 |
|
253 char narrow(char __c, char __dfault) const { |
|
254 return do_narrow(__c, __dfault); |
|
255 } |
|
256 const char* narrow(const char* __low, const char* __high, |
|
257 char __dfault, char* __to) const { |
|
258 return do_narrow(__low, __high, __dfault, __to); |
|
259 } |
|
260 |
|
261 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) |
|
262 _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(); |
|
263 #else |
|
264 _STLP_STATIC_MEMBER_DECLSPEC static locale::id id; |
|
265 #endif |
|
266 # if defined(_STLP_STATIC_CONST_INIT_BUG) |
|
267 enum __TableSize { table_size = 256 }; |
|
268 # else |
|
269 static const size_t table_size = 256; |
|
270 # endif |
|
271 |
|
272 protected: |
|
273 const mask* table() const _STLP_NOTHROW {return _M_ctype_table;} |
|
274 _STLP_DECLSPEC static const mask* classic_table() _STLP_NOTHROW;// { return & _S_classic_table [1]; } |
|
275 |
|
276 _STLP_DECLSPEC ~ctype(); |
|
277 |
|
278 _STLP_DECLSPEC virtual char do_toupper(char __c) const; |
|
279 _STLP_DECLSPEC virtual char do_tolower(char __c) const; |
|
280 _STLP_DECLSPEC virtual const char* do_toupper(char* __low, const char* __high) const; |
|
281 _STLP_DECLSPEC virtual const char* do_tolower(char* __low, const char* __high) const; |
|
282 _STLP_DECLSPEC virtual char do_widen(char __c) const; |
|
283 _STLP_DECLSPEC virtual const char* do_widen(const char* __low, const char* __high, |
|
284 char* __to) const; |
|
285 _STLP_DECLSPEC virtual char do_narrow(char __c, char /* dfault */ ) const; |
|
286 _STLP_DECLSPEC virtual const char* do_narrow(const char* __low, const char* __high, |
|
287 char /* dfault */, char* __to) const; |
|
288 private: |
|
289 struct _Is_mask { |
|
290 mask __m; |
|
291 _Is_mask(mask __x): __m(__x) {} |
|
292 bool operator()(char __c) {return (__m & (unsigned char) __c) != 0;} |
|
293 }; |
|
294 |
|
295 static const mask _S_classic_table[257 /* table_size + 1 */]; |
|
296 const mask* _M_ctype_table; |
|
297 bool _M_delete; |
|
298 |
|
299 static const unsigned char _S_upper[256 /* table_size */]; |
|
300 static const unsigned char _S_lower[256 /* table_size */]; |
|
301 }; |
|
302 |
|
303 _STLP_TEMPLATE_NULL |
|
304 class _STLP_CLASS_DECLSPEC ctype_byname<char>: public ctype<char> { |
|
305 public: |
|
306 explicit _STLP_DECLSPEC ctype_byname(const char*, size_t = 0); |
|
307 _STLP_DECLSPEC ~ctype_byname(); |
|
308 |
|
309 _STLP_DECLSPEC virtual char do_toupper(char __c) const; |
|
310 _STLP_DECLSPEC virtual char do_tolower(char __c) const; |
|
311 |
|
312 _STLP_DECLSPEC virtual const char* do_toupper(char*, const char*) const; |
|
313 _STLP_DECLSPEC virtual const char* do_tolower(char*, const char*) const; |
|
314 |
|
315 private: |
|
316 mask _M_byname_table[table_size + 1]; |
|
317 _Locale_ctype* _M_ctype; |
|
318 }; |
|
319 |
|
320 |
|
321 # ifndef _STLP_NO_WCHAR_T |
|
322 _STLP_TEMPLATE_NULL |
|
323 #ifdef __SYMBIAN32__ |
|
324 class ctype <wchar_t> : public locale::facet, public ctype_base |
|
325 #else |
|
326 class _STLP_CLASS_DECLSPEC ctype<wchar_t> : public locale::facet, public ctype_base |
|
327 #endif |
|
328 { |
|
329 friend class _Locale; |
|
330 public: |
|
331 typedef wchar_t char_type; |
|
332 |
|
333 explicit ctype(size_t __refs = 0) : _BaseFacet(__refs) {} |
|
334 |
|
335 bool is(mask __m, wchar_t __c) const |
|
336 { return do_is(__m, __c); } |
|
337 |
|
338 const wchar_t* is(const wchar_t* __low, const wchar_t* __high, |
|
339 mask* __vec) const |
|
340 { return do_is(__low, __high, __vec); } |
|
341 |
|
342 const wchar_t* scan_is(mask __m, |
|
343 const wchar_t* __low, const wchar_t* __high) const |
|
344 { return do_scan_is(__m, __low, __high); } |
|
345 |
|
346 const wchar_t* scan_not (mask __m, |
|
347 const wchar_t* __low, const wchar_t* __high) const |
|
348 { return do_scan_not(__m, __low, __high); } |
|
349 |
|
350 wchar_t (toupper)(wchar_t __c) const { return do_toupper(__c); } |
|
351 const wchar_t* (toupper)(wchar_t* __low, const wchar_t* __high) const |
|
352 { return do_toupper(__low, __high); } |
|
353 |
|
354 wchar_t (tolower)(wchar_t __c) const { return do_tolower(__c); } |
|
355 const wchar_t* (tolower)(wchar_t* __low, const wchar_t* __high) const |
|
356 { return do_tolower(__low, __high); } |
|
357 |
|
358 wchar_t widen(char __c) const { return do_widen(__c); } |
|
359 const char* widen(const char* __low, const char* __high, |
|
360 wchar_t* __to) const |
|
361 { return do_widen(__low, __high, __to); } |
|
362 |
|
363 char narrow(wchar_t __c, char __dfault) const |
|
364 { return do_narrow(__c, __dfault); } |
|
365 const wchar_t* narrow(const wchar_t* __low, const wchar_t* __high, |
|
366 char __dfault, char* __to) const |
|
367 { return do_narrow(__low, __high, __dfault, __to); } |
|
368 |
|
369 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) |
|
370 _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(); |
|
371 #else |
|
372 _STLP_STATIC_MEMBER_DECLSPEC static locale::id id; |
|
373 #endif |
|
374 |
|
375 protected: |
|
376 _STLP_DECLSPEC ~ctype(); |
|
377 |
|
378 _STLP_DECLSPEC virtual bool do_is(mask __m, wchar_t __c) const; |
|
379 _STLP_DECLSPEC virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const; |
|
380 _STLP_DECLSPEC virtual const wchar_t* do_scan_is(mask, |
|
381 const wchar_t*, const wchar_t*) const; |
|
382 _STLP_DECLSPEC virtual const wchar_t* do_scan_not(mask, |
|
383 const wchar_t*, const wchar_t*) const; |
|
384 _STLP_DECLSPEC virtual wchar_t do_toupper(wchar_t __c) const; |
|
385 _STLP_DECLSPEC virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const; |
|
386 _STLP_DECLSPEC virtual wchar_t do_tolower(wchar_t c) const; |
|
387 _STLP_DECLSPEC virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const; |
|
388 _STLP_DECLSPEC virtual wchar_t do_widen(char c) const; |
|
389 _STLP_DECLSPEC virtual const char* do_widen(const char*, const char*, wchar_t*) const; |
|
390 _STLP_DECLSPEC virtual char do_narrow(wchar_t __c, char __dfault) const; |
|
391 _STLP_DECLSPEC virtual const wchar_t* do_narrow(const wchar_t*, const wchar_t*, |
|
392 char, char*) const; |
|
393 }; |
|
394 |
|
395 _STLP_TEMPLATE_NULL |
|
396 class _STLP_CLASS_DECLSPEC ctype_byname<wchar_t>: public ctype<wchar_t> { |
|
397 public: |
|
398 explicit _STLP_DECLSPEC ctype_byname(const char* __name, size_t __refs = 0); |
|
399 |
|
400 protected: |
|
401 _STLP_DECLSPEC ~ctype_byname(); |
|
402 |
|
403 _STLP_DECLSPEC virtual bool do_is(mask __m, wchar_t __c) const; |
|
404 _STLP_DECLSPEC virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const; |
|
405 _STLP_DECLSPEC virtual const wchar_t* do_scan_is(mask, |
|
406 const wchar_t*, const wchar_t*) const; |
|
407 _STLP_DECLSPEC virtual const wchar_t* do_scan_not(mask, |
|
408 const wchar_t*, const wchar_t*) const; |
|
409 _STLP_DECLSPEC virtual wchar_t do_toupper(wchar_t __c) const; |
|
410 _STLP_DECLSPEC virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const; |
|
411 _STLP_DECLSPEC virtual wchar_t do_tolower(wchar_t c) const; |
|
412 _STLP_DECLSPEC virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const; |
|
413 |
|
414 private: |
|
415 _Locale_ctype* _M_ctype; |
|
416 }; |
|
417 |
|
418 # endif /* WCHAR_T */ |
|
419 #ifdef __SYMBIAN32__ |
|
420 #include <stl/_ctype.c> |
|
421 #endif |
|
422 |
|
423 _STLP_END_NAMESPACE |
|
424 |
|
425 #endif /* _STLP_INTERNAL_CTYPE_H */ |
|
426 |
|
427 // Local Variables: |
|
428 // mode:C++ |
|
429 // End: |
|
430 |