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>;
75 typedef char char_type
;
77 explicit ctype(const mask
* __tab
= 0, bool __del
= false, size_t __refs
= 0);
78 bool is(mask __m
, char __c
) const
79 { return ((*(_M_ctype_table
+(unsigned char)__c
)) & __m
) != 0; }
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
];
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;
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
);
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
);
101 char widen(char __c
) const { return do_widen(__c
); }
102 const char* widen(const char* __low
, const char* __high
, char* __to
) const {
103 return do_widen(__low
, __high
, __to
);
106 char narrow(char __c
, char __dfault
) const {
107 return do_narrow(__c
, __dfault
);
109 const char* narrow(const char* __low
, const char* __high
,
110 char __dfault
, char* __to
) const {
111 return do_narrow(__low
, __high
, __dfault
, __to
);
114 static _STLP_STATIC_DECLSPEC
locale::id id
;
115 _STLP_STATIC_CONSTANT(size_t, table_size
= 256);
118 const mask
* table() const _STLP_NOTHROW
{ return _M_ctype_table
; }
119 static const mask
* _STLP_CALL
classic_table() _STLP_NOTHROW
;
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
,
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;
136 _Is_mask(mask __x
): __m(__x
) {}
137 bool operator()(char __c
) {return (__m
& (unsigned char) __c
) != 0;}
141 const mask
* _M_ctype_table
;
147 class _STLP_CLASS_DECLSPEC ctype_byname
<char>: public ctype
<char> {
148 friend class _Locale_impl
;
150 explicit ctype_byname(const char*, size_t = 0);
153 virtual char do_toupper(char __c
) const;
154 virtual char do_tolower(char __c
) const;
156 virtual const char* do_toupper(char*, const char*) const;
157 virtual const char* do_tolower(char*, const char*) const;
160 ctype_byname(_Locale_ctype
* __ctype
)
166 //explicitely defined as private to avoid warnings:
167 typedef ctype_byname
<char> _Self
;
168 ctype_byname(_Self
const&);
169 _Self
& operator = (_Self
const&);
171 mask _M_byname_table
[table_size
];
172 _Locale_ctype
* _M_ctype
;
175 # ifndef _STLP_NO_WCHAR_T
177 class _STLP_CLASS_DECLSPEC ctype
<wchar_t> : public locale::facet
, public ctype_base
{
179 typedef wchar_t char_type
;
181 explicit ctype(size_t __refs
= 0) : locale::facet(__refs
) {}
183 bool is(mask __m
, wchar_t __c
) const
184 { return do_is(__m
, __c
); }
186 const wchar_t* is(const wchar_t* __low
, const wchar_t* __high
,
188 { return do_is(__low
, __high
, __vec
); }
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
); }
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
); }
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
); }
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
); }
206 wchar_t widen(char __c
) const { return do_widen(__c
); }
207 const char* widen(const char* __low
, const char* __high
,
209 { return do_widen(__low
, __high
, __to
); }
211 char narrow(wchar_t __c
, char __dfault
) const
212 { return do_narrow(__c
, __dfault
); }
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
); }
217 static _STLP_STATIC_DECLSPEC
locale::id id
;
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*,
240 class _STLP_CLASS_DECLSPEC ctype_byname
<wchar_t>: public ctype
<wchar_t> {
241 friend class _Locale_impl
;
243 explicit ctype_byname(const char* __name
, size_t __refs
= 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 ctype_byname(_Locale_ctype
* __ctype
)
261 : _M_ctype(__ctype
) {}
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&);
268 _Locale_ctype
* _M_ctype
;
271 # endif /* WCHAR_T */
275 #endif /* _STLP_INTERNAL_CTYPE_H */