Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_ctype.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_LOC_CTYPE_H_INCLUDED
33#define _RWSTD_LOC_CTYPE_H_INCLUDED
34
35
36#include <loc/_facet.h>
37#include <rw/_bitmask.h>
38#include <rw/_defs.h>
39
41
42struct __rw_ctype_t;
43
44enum __rw_ctype_mask {
45 __rw_none = 0,
46 __rw_space = 0x0001,
47 __rw_print = 0x0002,
48 __rw_cntrl = 0x0004,
49 __rw_upper = 0x0008,
50 __rw_lower = 0x0010,
51 __rw_alpha = 0x0020,
52 __rw_digit = 0x0040,
53 __rw_punct = 0x0080,
54 __rw_xdigit = 0x0100,
55 __rw_alnum = __rw_alpha | __rw_digit,
56 __rw_graph = 0x0200,
57 __rw_all = 0x03ff
58};
59
60_RWSTD_DEFINE_BITMASK_OPERATORS (__rw_ctype_mask);
61
62} // namespace __rw
63
64
66
67struct _RWSTD_CLASS_EXPORT locale;
68
69// 22.2.1
70struct _RWSTD_EXPORT ctype_base
71{
72 // 22.2.1, p1 - mask is a bitmask type (see 17.3.3.1.2)
73 typedef _RWSTD_BITMASK_ENUM (_RW::__rw_ctype_mask) mask;
74
75 _RWSTD_STATIC_CONST (mask, space = _RW::__rw_space);
76 _RWSTD_STATIC_CONST (mask, print = _RW::__rw_print);
77 _RWSTD_STATIC_CONST (mask, cntrl = _RW::__rw_cntrl);
78 _RWSTD_STATIC_CONST (mask, upper = _RW::__rw_upper);
79 _RWSTD_STATIC_CONST (mask, lower = _RW::__rw_lower);
80 _RWSTD_STATIC_CONST (mask, alpha = _RW::__rw_alpha);
81 _RWSTD_STATIC_CONST (mask, digit = _RW::__rw_digit);
82 _RWSTD_STATIC_CONST (mask, punct = _RW::__rw_punct);
83 _RWSTD_STATIC_CONST (mask, xdigit = _RW::__rw_xdigit);
84 _RWSTD_STATIC_CONST (mask, alnum = _RW::__rw_alnum);
85 _RWSTD_STATIC_CONST (mask, graph = _RW::__rw_graph);
86};
87
88
89// 22.2.1.1
91template <class _CharT>
92class ctype;
93
94
95#ifndef _RWSTD_NO_EXT_CTYPE_PRIMARY
96
98template <class _CharT>
99class ctype: public _RW::__rw_facet, public ctype_base
100{
101public:
102
103 typedef _CharT char_type;
104
105 explicit ctype (_RWSTD_SIZE_T __ref = 0)
106 : _RW::__rw_facet (__ref) { }
107
108
109 // 22.2.1.1.1, p1
110 bool is (mask __m, char_type __c) const {
111 return do_is ( __m, __c);
112 }
113
114 const char_type*
115 is (const char_type* __lo, const char_type *__hi, mask *__vec) const {
116 return do_is (__lo, __hi, __vec);
117 }
118
119 // 22.2.1.1.1, p2
120 const char_type*
121 scan_is (mask __m, const char_type *__lo, const char_type *__hi) const {
122 return do_scan_is ( __m, __lo, __hi);
123 }
124
125 // 22.2.1.1.1, p3
126 const char_type*
127 scan_not (mask __m, const char_type *__lo, const char_type *__hi) const {
128 return do_scan_not ( __m, __lo, __hi);
129 }
130
131 // 22.2.1.1.1, p4
132 char_type (toupper)(char_type __c) const {
133 return do_toupper (__c);
134 }
135
136 const char_type* (toupper)(char_type *__lo, const char_type *__hi) const {
137 return do_toupper (__lo, __hi);
138 }
139
140 // 22.2.1.1.1, p5
141 char_type (tolower)(char_type __c) const {
142 return do_tolower (__c);
143 }
144
145 const char_type* (tolower)(char_type *__lo, const char_type *__hi) const {
146 return do_tolower (__lo, __hi);
147 }
148
149 // 22.2.1.1.1, p6
150 char_type widen (char __c) const {
151 return do_widen (__c);
152 }
153
154 const char*
155 widen (const char *__lo, const char *__hi, char_type *__to) const {
156 return do_widen (__lo, __hi, __to);
157 }
158
159 // 22.2.1.1.1, p7
160 char narrow (char_type __c, char __dfault) const {
161 return do_narrow (__c, __dfault);
162 }
163
164 const char_type*
165 narrow (const char_type *__lo, const char_type *__hi,
166 char __dfault, char *__to) const {
167 return do_narrow (__lo, __hi, __dfault, __to);
168 }
169
170 static _RW::__rw_facet_id id;
171
172protected:
173
174 // 22.2.1.1.2, p1
175 virtual bool do_is (mask, char_type) const {
176 return false;
177 }
178
179 virtual const char_type*
180 do_is (const char_type*, const char_type*, mask*) const;
181
182 // 22.2.1.1.2, p3
183 virtual const char_type*
184 do_scan_is (mask, const char_type*, const char_type*) const;
185
186 // 22.2.1.1.2, p5
187 virtual const char_type*
188 do_scan_not (mask, const char_type*, const char_type*) const;
189
190 // 22.2.1.1.2, p7
191 virtual char_type do_toupper (char_type __c) const {
192 return __c;
193 }
194
195 virtual const char_type*
196 do_toupper (char_type*, const char_type*) const;
197
198 // 22.2.1.1.2, p9
199 virtual char_type do_tolower (char_type __c) const {
200 return __c;
201 }
202
203 virtual const char_type*
204 do_tolower (char_type*, const char_type*) const;
205
206 // 22.2.1.1.2, p11
207 virtual char_type do_widen (char) const {
208 return char_type ();
209 }
210
211 virtual const char*
212 do_widen (const char*, const char*, char_type*) const;
213
214 // 22.2.1.1.2, p13
215 virtual char do_narrow (char_type, char __dfault) const {
216 return __dfault;
217 }
218
219 virtual const char_type*
220 do_narrow (const char_type*, const char_type*, char, char*) const;
221};
222
223#endif // _RWSTD_NO_EXT_CTYPE_PRIMARY
224
225
227class _RWSTD_EXPORT ctype<char>: public _RW::__rw_facet, public ctype_base
228{
229 typedef unsigned char _UChar;
230
231public:
232
233 typedef char char_type;
234
235 bool is (mask __m, char_type __c) const {
236#if _RWSTD_UCHAR_MAX <= 255
237 return (_C_mask_tab [_UChar (__c)] & __m) != 0;
238#else
239 return __c < table_size && (_C_mask_tab [_UChar (__c)] & __m) != 0;
240#endif
241 }
242
243 _RWSTD_STATIC_CONST (_RWSTD_SIZE_T, table_size = 256);
244
245 explicit ctype (const mask* = 0, bool = false, _RWSTD_SIZE_T = 0);
246
247 const char_type* is (const char_type*, const char_type*, mask*) const;
248
249 const char_type* scan_is (mask, const char_type*, const char_type*) const;
250
251 const char_type* scan_not (mask, const char_type*, const char_type*) const;
252
253 char_type (toupper)(char_type __c) const {
254 return do_toupper (__c);
255 }
256
257 char_type (tolower)(char_type __c) const {
258 return do_tolower (__c);
259 }
260
261 // 22.2.1.1.1, p6
262 char_type widen (char) const;
263
264 char narrow (char_type, char) const;
265
266 const char_type* (toupper)(char_type *__lo, const char_type *__hi) const {
267 return do_toupper (__lo, __hi);
268 }
269
270 const char_type* (tolower)(char_type *__lo, const char_type *__hi) const {
271 return do_tolower (__lo, __hi);
272 }
273
274 const char_type*
275 widen (const char *__lo, const char *__hi, char_type *__to) const {
276 return do_widen (__lo, __hi, __to);
277 }
278
279 const char_type*
280 narrow (const char_type *__lo, const char_type *__hi,
281 char_type __dfault, char_type *__to) const {
282 return do_narrow (__lo, __hi, __dfault, __to);
283 }
284
285 static _RW::__rw_facet_id id;
286
287protected:
288
289 const mask* table () const _THROWS (()) {
290 return _C_mask_tab;
291 }
292
293 static const mask* classic_table () _THROWS (());
294
295 virtual ~ctype ();
296
297 virtual const char_type*
298 do_toupper (char_type*, const char_type*) const;
299
300 virtual const char_type*
301 do_tolower (char_type*, const char_type*) const;
302
303 virtual char_type do_toupper (char_type) const;
304
305 virtual char_type do_tolower (char_type) const;
306
307 virtual char_type do_widen (char) const;
308
309 virtual const char_type*
310 do_widen (const char_type*, const char_type*, char_type*) const;
311
312 virtual char_type do_narrow (char_type, char_type) const;
313
314 virtual const char_type*
315 do_narrow (const char_type*, const char_type*, char_type, char_type*)const;
316
317protected:
318
319 const mask *_C_mask_tab; // mask for each character
320 unsigned char *_C_upper_tab; // uppercase version of each character
321 unsigned char *_C_lower_tab; // lowercase version of each character
322 char _C_narrow_tab [256]; // cached results of do_narrow()
323 char _C_wide_tab [256]; // cached results of do_widen()
324 int _C_delete_it; // delete tables above?
325};
326
327
328inline ctype<char>::char_type
329ctype<char>::narrow (char_type __c, char __dfault) const
330{
331 const _RWSTD_SIZE_T __inx = _RWSTD_STATIC_CAST (unsigned char, __c);
332
333 // optimize away all but the first call to the virtual do_widen()
334
335 if (
336
337#if _RWSTD_CHAR_BIT > 8
338
339 __inx < sizeof _C_narrow_tab / sizeof *_C_narrow_tab &&
340
341#endif // _RWSTD_CHAR_BIT > 8
342
343 _C_narrow_tab [__inx])
344 return _C_narrow_tab [__inx];
345
346 // template argument provided to work around an HP aCC bug (PR #27087)
347 ctype<char>* const __self = _RWSTD_CONST_CAST (ctype<char>*, this);
348
349 __c = do_narrow (__c, __dfault);
350
351 if (__c != __dfault)
352 __self->_C_narrow_tab [__inx] = __c;
353
354 return __c;
355}
356
357
358inline ctype<char>::char_type
359ctype<char>::widen (char __ch) const
360{
361 const _RWSTD_SIZE_T __inx = _RWSTD_STATIC_CAST (unsigned char, __ch);
362
363 // optimize away all but the first call to the virtual do_widen()
364
365#if _RWSTD_CHAR_BIT <= 8
366 const bool __fits = true;
367#else
368 const bool __fits = __inx < sizeof _C_wide_tab / sizeof *_C_wide_tab;
369#endif
370
371 if (__fits) {
372 if (_C_wide_tab [__inx])
373 return _C_wide_tab [__inx];
374
375 // template argument provided to work around an HP aCC bug (PR #27087)
376 ctype<char>* const __self = _RWSTD_CONST_CAST (ctype<char>*, this);
377
378 return __self->_C_wide_tab [__inx] = do_widen (__ch);
379 }
380 else
381 return do_widen (__ch);
382}
383
384
385// 22.2.1.2
386template <class _CharT>
387class ctype_byname: public ctype<_CharT>
388{
389 char _C_namebuf [32];
390
391public:
392
393 explicit ctype_byname (const char *__name, _RWSTD_SIZE_T __ref = 0)
394 : ctype<_CharT>(__ref) {
395 this->_C_set_name (__name, _C_namebuf, sizeof _C_namebuf);
396 }
397};
398
399
401class _RWSTD_EXPORT ctype_byname<char>: public ctype<char>
402{
403 char _C_namebuf [32];
404
405public:
406
407 explicit ctype_byname (const char*, _RWSTD_SIZE_T = 0);
408};
409
410
411#ifndef _RWSTD_NO_WCHAR_T
412
414class _RWSTD_EXPORT ctype<wchar_t>: public _RW::__rw_facet, public ctype_base
415{
416 typedef unsigned char _UChar;
417
418 enum { _C_tab_size = 256 };
419
420public:
421
422 typedef wchar_t char_type;
423
424 explicit ctype (_RWSTD_SIZE_T = 0);
425
426 // 22.2.1.1.1, p1
427 bool is (mask __m, char_type __c) const {
428 return do_is ( __m, __c);
429 }
430
431 const char_type*
432 is (const char_type *__lo, const char_type *__hi, mask *__vec) const {
433 return do_is (__lo, __hi, __vec);
434 }
435
436 // 22.2.1.1.1, p2
437 const char_type*
438 scan_is (mask __m, const char_type *__lo, const char_type *__hi) const {
439 return do_scan_is ( __m, __lo, __hi);
440 }
441
442 // 22.2.1.1.1, p3
443 const char_type*
444 scan_not (mask __m, const char_type *__lo, const char_type *__hi) const {
445 return do_scan_not ( __m, __lo, __hi);
446 }
447
448 // 22.2.1.1.1, p4
449 char_type (toupper)(char_type __c) const {
450 return do_toupper (__c);
451 }
452
453 const char_type* (toupper)(char_type *__lo, const char_type *__hi) const {
454 return do_toupper (__lo, __hi);
455 }
456
457 // 22.2.1.1.1, p5
458 char_type (tolower)(char_type __c) const {
459 return do_tolower (__c);
460 }
461
462 const char_type* (tolower)(char_type *__lo, const char_type *__hi) const {
463 return do_tolower (__lo, __hi);
464 }
465
466 // 22.2.1.1.1, p6
467 char_type widen (char) const;
468
469 const char*
470 widen (const char* __lo, const char *__hi, char_type *__to) const {
471 return do_widen (__lo, __hi, __to);
472 }
473
474 // 22.2.1.1.1, p7
475 char narrow (char_type, char) const;
476
477 const char_type*
478 narrow (const char_type *__lo, const char_type *__hi,
479 char __dfault, char *__to) const {
480 return do_narrow (__lo, __hi, __dfault, __to);
481 }
482
483 static _RW::__rw_facet_id id;
484
485protected:
486
487 virtual ~ctype ();
488
489 // 22.2.1.1.2, p1
490 virtual bool do_is (mask, char_type) const;
491
492 virtual const char_type*
493 do_is (const char_type*, const char_type*, mask*) const;
494
495 // 22.2.1.1.2, p7
496 virtual char_type do_toupper (char_type) const;
497
498 // 22.2.1.1.2, p9
499 virtual char_type do_tolower (char_type) const;
500
501 // 22.2.1.1.2, p11
502 virtual char_type do_widen (char) const;
503
504 virtual const char*
505 do_widen (const char*, const char*, char_type*) const;
506
507 // 22.2.1.1.2, p13
508 virtual char
509 do_narrow (char_type, char) const;
510
511 virtual const char_type*
512 do_toupper (char_type*, const char_type*) const;
513
514 virtual const char_type*
515 do_tolower (char_type*, const char_type*) const;
516
517 // 22.2.1.1.2, p3
518 virtual const char_type*
519 do_scan_is (mask, const char_type*, const char_type*) const;
520
521 // 22.2.1.1.2, p5
522 virtual const char_type*
523 do_scan_not (mask, const char_type*, const char_type*) const;
524
525 virtual const char_type*
526 do_narrow (const char_type*, const char_type*, char, char*) const;
527
528private:
529
530 friend class ctype_byname<wchar_t>;
531
532 const mask *_C_mask_tab; // mask for each character
533 unsigned char *_C_upper_tab; // uppercase version of each character
534 unsigned char *_C_lower_tab; // lowercase version of each character
535 char _C_narrow_tab [256]; // cached results of do_narrow()
536 char_type _C_wide_tab [256]; // cached results of do_widen()
537 int _C_delete_it; // delete tables above?
538};
539
540
541inline char
542ctype<wchar_t>::narrow (char_type __c, char __dfault) const
543{
544 // carefully convert wchar_t to the unsigned form of its
545 // underlying integer type, avoiding sign extension and
546 // similar issues
547 const _RWSTD_UWCHAR_INT_T __inx =
549
550 // optimize away all but the first call to the virtual do_widen()
551 if ( __inx < sizeof _C_narrow_tab / sizeof *_C_narrow_tab
552 && _C_narrow_tab [__inx])
553 return _C_narrow_tab [__inx];
554
555 // template argument provided to work around an HP aCC bug (PR #27087)
556 ctype<wchar_t>* const __self = _RWSTD_CONST_CAST (ctype<wchar_t>*, this);
557
558 const char __ch = do_narrow (__c, __dfault);
559
560 if (__inx < sizeof _C_narrow_tab / sizeof *_C_narrow_tab && __ch != __dfault)
561 __self->_C_narrow_tab [__inx] = __ch;
562
563 return __ch;
564}
565
566
567inline ctype<wchar_t>::char_type
568ctype<wchar_t>::widen (char __ch) const
569{
570 const _RWSTD_SIZE_T __inx = _RWSTD_STATIC_CAST (unsigned char, __ch);
571
572 // optimize away all but the first call to the virtual do_widen()
573
574#if _RWSTD_CHAR_BIT <= 8
575 const bool __fits = true;
576#else
577 const bool __fits = __inx < sizeof _C_wide_tab / sizeof *_C_wide_tab;
578#endif
579
580 if (__fits) {
581 if (_C_wide_tab [__inx])
582 return _C_wide_tab [__inx];
583
584 // template argument provided to work around an HP aCC bug (PR #27087)
585 ctype<wchar_t>* const __self = _RWSTD_CONST_CAST (ctype<wchar_t>*, this);
586
587 return __self->_C_wide_tab [__inx] = do_widen (__ch);
588 }
589 else
590 return do_widen (__ch);
591}
592
593
594
596class _RWSTD_EXPORT ctype_byname<wchar_t>: public ctype<wchar_t>
597{
598public:
599
600 explicit ctype_byname (const char*, _RWSTD_SIZE_T = 0);
601
602protected:
603
604 virtual ~ctype_byname ();
605
606 virtual bool
607 do_is (mask, char_type) const;
608
609 virtual const char_type*
610 do_is (const char_type*, const char_type*, mask*) const;
611
612 virtual char_type
613 do_toupper (char_type) const;
614
615 virtual const char_type*
616 do_toupper (char_type*, const char_type*) const;
617
618 virtual char_type
619 do_tolower (char_type) const;
620
621 virtual const char_type*
622 do_tolower (char_type*, const char_type*) const;
623
624 virtual const char_type*
625 do_scan_is (mask, const char_type*, const char_type*) const;
626
627 virtual const char_type*
628 do_scan_not (mask, const char_type*, const char_type*) const;
629
630 virtual char
631 do_narrow(char_type, char) const;
632
633 virtual const char_type*
634 do_narrow (const char_type*, const char_type*, char, char*) const;
635
636 virtual char_type do_widen (char) const;
637
638 virtual const char*
639 do_widen (const char*, const char*, char_type*) const;
640
641private:
642
643 char _C_namebuf [32];
644 const void *_C_cvtimpl; // codecvt database mapped by ctype facet
645 _RWSTD_SIZE_T _C_cvtsize; // size of the above mapping
646};
647
648#endif // _RWSTD_NO_WCHAR_T
649
650
651} // namespace std
652
653
654#if _RWSTD_DEFINE_TEMPLATE (CTYPE)
655# include <loc/_ctype.cc>
656#endif // _RWSTD_DEFINE_TEMPLATE (CTYPE)
657
658
659#endif // _RWSTD_LOC_CTYPE_H_INCLUDED
const char lower[]
const char graph[]
const char upper[]
const char cntrl[]
const char print[]
const char punct[]
const char * widen(char *dst, const char *src)
const char * narrow(char *dst, const char *src)
#define _RWSTD_SPECIALIZED_CLASS
#define _THROWS()
#define _RWSTD_BITMASK_ENUM(Bitmask)
Definition _bitmask.h:41
#define _RWSTD_DEFINE_BITMASK_OPERATORS(Bitmask)
Definition _bitmask.h:43
unsigned short wchar_t
#define _RWSTD_CLASS_EXPORT
Definition _defs.h:486
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_UWCHAR_INT_T
Definition _defs.h:1287
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_STATIC_CONST(type, init)
Definition _defs.h:989
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
A TOML table.
Definition table.hpp:190
Definition json.h:5363