3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
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.
18 // WARNING: This is an internal header file, included by other C++
19 // standard library headers. You should not attempt to use this header
22 #ifndef _STLP_INTERNAL_CTYPE_H
23 #define _STLP_INTERNAL_CTYPE_H
25 #ifndef _STLP_C_LOCALE_H
26 # include <stl/c_locale.h>
29 #ifndef _STLP_INTERNAL_LOCALE_H
30 # include <stl/_locale.h>
33 #ifndef _STLP_INTERNAL_ALGOBASE_H
34 # include <stl/_algobase.h>
39 class _STLP_CLASS_DECLSPEC ctype_base {
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,
58 template <class charT> class ctype {};
59 template <class charT> class ctype_byname {};
61 //ctype specializations
64 class _STLP_CLASS_DECLSPEC ctype<char> : public locale::facet, public ctype_base {
65 #ifndef _STLP_NO_WCHAR_T
67 typedef ctype<wchar_t> _Wctype;
70 friend class ctype<wchar_t>;
73 friend class _Locale_impl;
76 typedef char char_type;
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; }
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];
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;
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);
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);
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);
107 char narrow(char __c, char __dfault) const {
108 return do_narrow(__c, __dfault);
110 const char* narrow(const char* __low, const char* __high,
111 char __dfault, char* __to) const {
112 return do_narrow(__low, __high, __dfault, __to);
115 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
116 # if defined(_STLP_STATIC_CONST_INIT_BUG)
117 enum __TableSize { table_size = 256 };
119 static const size_t table_size = 256;
123 const mask* table() const _STLP_NOTHROW { return _M_ctype_table; }
124 static const mask* _STLP_CALL classic_table() _STLP_NOTHROW;
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,
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;
141 _Is_mask(mask __x): __m(__x) {}
142 bool operator()(char __c) {return (__m & (unsigned char) __c) != 0;}
146 const mask* _M_ctype_table;
152 class _STLP_CLASS_DECLSPEC ctype_byname<char>: public ctype<char> {
154 explicit ctype_byname(const char*, size_t = 0, _Locale_name_hint* __hint = 0);
157 virtual char do_toupper(char __c) const;
158 virtual char do_tolower(char __c) const;
160 virtual const char* do_toupper(char*, const char*) const;
161 virtual const char* do_tolower(char*, const char*) const;
164 mask _M_byname_table[table_size];
165 _Locale_ctype* _M_ctype;
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>*);
174 # ifndef _STLP_NO_WCHAR_T
176 class _STLP_CLASS_DECLSPEC ctype<wchar_t> : public locale::facet, public ctype_base
178 friend class _Locale_impl;
180 typedef wchar_t char_type;
182 explicit ctype(size_t __refs = 0) : locale::facet(__refs) {}
184 bool is(mask __m, wchar_t __c) const
185 { return do_is(__m, __c); }
187 const wchar_t* is(const wchar_t* __low, const wchar_t* __high,
189 { return do_is(__low, __high, __vec); }
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); }
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); }
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); }
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); }
207 wchar_t widen(char __c) const { return do_widen(__c); }
208 const char* widen(const char* __low, const char* __high,
210 { return do_widen(__low, __high, __to); }
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); }
218 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
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*,
241 class _STLP_CLASS_DECLSPEC ctype_byname<wchar_t>: public ctype<wchar_t> {
243 explicit ctype_byname(const char* __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
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;
260 _Locale_ctype* _M_ctype;
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&);
268 # endif /* WCHAR_T */
272 #endif /* _STLP_INTERNAL_CTYPE_H */