33#ifndef _RWSTD_NO_WCHAR_T
39#ifndef _RWSTD_NO_WCHAR_H
54#ifdef _RWSTD_NO_EQUAL_CTYPE_MASK
59#undef _UTF8_MB_CUR_MAX
60#define _UTF8_MB_CUR_MAX 6
65typedef _STD::ctype_base::mask MaskT;
67extern const MaskT __rw_classic_tab [];
68extern const unsigned char __rw_upper_tab [];
69extern const unsigned char __rw_lower_tab [];
73__rw_get_mask (__rw_ctype_t *impl,
84 if (use_libstd && impl != 0) {
86 for (; beg !=
end; ++beg) {
89 _RWSTD_SIZE_T low = 0;
90 _RWSTD_SIZE_T high = (_RWSTD_SIZE_T)impl->wmask_s;
97 const _RWSTD_SIZE_T
cur = (low + high) / 2;
98 const __rw_mask_elm next_elm = impl->wmask_tab (
cur);
100 if (next_elm.ch == *beg) {
109 *vec = MaskT (next_elm.mask & mask);
110 else if ( scan_is && next_elm.mask & mask
111 || !scan_is && !(next_elm.mask & mask))
133 const __rw_setlocale clocale (locname,
LC_CTYPE);
135 for (; beg !=
end; ++beg) {
140 const bool fits_char =
147 if (mask & __rw_space) {
148#ifndef _RWSTD_NO_ISWSPACE
149 if ((::iswspace)(*beg))
151 if (fits_char && (::isspace)(*beg))
156 if (mask & __rw_print) {
157#ifndef _RWSTD_NO_ISWPRINT
158 if ((::iswprint)(*beg))
160 if (fits_char && (::isprint)(*beg))
165 if (mask & __rw_cntrl) {
166#ifndef _RWSTD_NO_ISWCNTRL
167 if ((::iswcntrl)(*beg))
169 if (fits_char && (::iscntrl)(*beg))
174 if (mask & __rw_upper) {
175#ifndef _RWSTD_NO_ISWUPPER
176 if ((::iswupper)(*beg))
178 if (fits_char && (::isupper)(*beg))
183 if (mask & __rw_lower) {
184#ifndef _RWSTD_NO_ISWLOWER
185 if ((::iswlower)(*beg))
187 if (fits_char && (::islower)(*beg))
192 if (mask & __rw_alpha) {
193#ifndef _RWSTD_NO_ISWALPHA
194 if ((::iswalpha)(*beg))
196 if (fits_char && (::isalpha)(*beg))
201 if (mask & __rw_digit) {
202#ifndef _RWSTD_NO_ISWDIGIT
203 if ((::iswdigit)(*beg))
205 if (fits_char && (::isdigit)(*beg))
210 if (mask & __rw_punct) {
211#ifndef _RWSTD_NO_ISWPUNCT
212 if ((::iswpunct)(*beg))
214 if (fits_char && (::ispunct)(*beg))
219 if (mask & __rw_xdigit) {
220#ifndef _RWSTD_NO_ISWXDIGIT
221 if ((::iswxdigit)(*beg))
223 if (fits_char && (::isxdigit) (*beg))
228 if (mask & __rw_graph) {
229#ifndef _RWSTD_NO_ISWGRAPH
230 if ((::iswgraph)(*beg))
232 if (fits_char && (::isgraph)(*beg))
239 else if (scan_is &&
m & mask || !scan_is && !(
m & mask))
247static _STD::ctype_byname<wchar_t>::char_type
248__rw_toupper (__rw_ctype_t* impl,
249 wchar_t c,
bool use_libstd,
252 if (use_libstd && impl != 0) {
254 _RWSTD_SIZE_T low = 0;
255 _RWSTD_SIZE_T high = (_RWSTD_SIZE_T)impl->wtoupper_s();
258 __rw_upper_elm next_elm;
260 while (low <= high) {
261 cur = (low + high) / 2;
262 next_elm = impl->wtoupper_tab(
cur);
263 if (next_elm.lower ==
c) {
279#ifndef _RWSTD_NO_TOWUPPER
281 const __rw_setlocale clocale (locname,
LC_CTYPE);
289 const __rw_setlocale clocale (locname,
LC_CTYPE);
302static _STD::ctype_byname<wchar_t>::char_type
303__rw_tolower (__rw_ctype_t* impl,
304 wchar_t c,
bool use_libstd,
307 if (use_libstd && impl != 0) {
309 _RWSTD_SIZE_T low = 0;
310 _RWSTD_SIZE_T high = (_RWSTD_SIZE_T)impl->wtolower_s ();
313 __rw_lower_elm next_elm;
315 while (low <= high) {
316 cur = (low + high) / 2;
317 next_elm = impl->wtolower_tab(
cur);
318 if (next_elm.upper ==
c) {
334#ifndef _RWSTD_NO_TOWLOWER
336 const __rw_setlocale clocale (locname,
LC_CTYPE);
344 const __rw_setlocale clocale (locname,
LC_CTYPE);
360__rw_narrow (
const __rw_codecvt_t *
cvt,
bool use_libstd,
361 const wchar_t *lo,
const wchar_t *hi,
char dfault,
char *dst)
367__rw_widen (
const __rw_codecvt_t *
cvt,
bool use_libstd,
368 const char *lo,
const char *hi,
wchar_t *dst)
374#ifdef _RWSTD_NO_EQUAL_CTYPE_MASK
377static _STD::ctype_base::mask
378__rw_classic_wide_tab [_STD::ctype<char>::table_size];
388__rw_init_classic_wide_tab ()
402 wchar_t wc_array [_STD::ctype<char>::table_size];
404 for (
wchar_t wc = 0; wc < _STD::ctype<char>::table_size; ++wc)
407 __rw_get_mask (0, wc_array, wc_array + _STD::ctype<char>::table_size,
408 __rw_all, __rw_classic_wide_tab,
false,
false,
"C");
421_RW::__rw_facet_id ctype<wchar_t>::id;
424ctype<wchar_t>::ctype (_RWSTD_SIZE_T ref)
425 : _RW::__rw_facet (ref)
427#ifndef _RWSTD_NO_EQUAL_CTYPE_MASK
428 _C_mask_tab = _RW::__rw_classic_tab;
431 _RW::__rw_once (&_RW::__rw_classic_wide_tab_once_init,
432 _RW::__rw_init_classic_wide_tab);
434 _C_mask_tab = _RW::__rw_classic_wide_tab;
438 _C_delete_it =
false;
440 memset (_C_narrow_tab, 0,
sizeof _C_narrow_tab);
441 memset (_C_wide_tab, 0,
sizeof _C_wide_tab);
445ctype<wchar_t>::~ctype ()
450 if (_C_upper_tab != _RW::__rw_upper_tab) {
453 delete[] _C_upper_tab;
460do_is (mask
m, char_type
c)
const
463 && (_C_mask_tab [_UChar (
c)] &
m);
467const ctype<wchar_t>::char_type*
469do_is (
const char_type *lo,
const char_type *hi, mask *mvec)
const
473 for ( ; lo != hi; ++lo, ++mvec) {
475 _C_mask_tab [_UChar (*lo)] : mask (0);
483ctype<wchar_t>::char_type
485do_widen (
char c)
const
490 _C_wide_tab [_UChar (
c)] = char_type (_UChar (
c));
496do_widen (
const char *lo,
const char *hi, char_type *dest)
const
502 *dest++ =
widen (*lo++);
508ctype<wchar_t>::char_type
510do_toupper (char_type
c)
const
513 _C_upper_tab [_UChar (
c)] :
c;
517ctype<wchar_t>::char_type
519do_tolower (char_type
c)
const
522 _C_lower_tab [_UChar (
c)] :
c;
526const ctype<wchar_t>::char_type*
528do_toupper (char_type *lo,
const char_type *hi)
const
532 for ( ; lo < hi; ++lo)
534 _C_upper_tab [_UChar (*lo)] : 0;
540const ctype<wchar_t>::char_type*
542do_tolower (char_type *lo,
const char_type *hi)
const
546 for ( ; lo < hi; ++lo)
548 _C_lower_tab [_UChar (*lo)] : 0;
554const ctype<wchar_t>::char_type*
556do_scan_is (mask
m,
const char_type *lo,
const char_type *hi)
const
560 for ( ; lo != hi; ++lo) {
562 && (_C_mask_tab [_UChar (*lo)] &
m))
570const ctype<wchar_t>::char_type*
572do_scan_not (mask
m,
const char_type *lo,
const char_type *hi)
const
575 for ( ; lo != hi; ++lo) {
577 || !(_C_mask_tab [_UChar (*lo)] &
m))
587do_narrow (char_type
c,
char dfault)
const
594const ctype<wchar_t>::char_type*
596do_narrow (
const char_type *lo,
const char_type *hi,
597 char dfault,
char *dest)
const
601 *dest++ = do_narrow (*lo++, dfault);
607ctype_byname<wchar_t>::
608ctype_byname (
const char *
name, _RWSTD_SIZE_T refs)
609 : ctype<wchar_t> (refs), _C_cvtimpl (0), _C_cvtsize (0)
611 this->_C_set_name (
name, _C_namebuf,
sizeof _C_namebuf);
613 if (
'C' ==
name [0] &&
'\0' ==
name [1])
617 _RW::__rw_ctype_t* impl =
620 _RW::__rw_get_facet_data (
LC_CTYPE, _C_impsize, _C_name)));
626 _C_cvtimpl = _RW::__rw_get_facet_data (
LC_CTYPE, _C_cvtsize, 0,
627 impl->codeset_name ());
629 if (impl == 0 || (this->_C_opts & this->_C_use_libc)) {
640 _C_mask_tab =
new mask [(_RWSTD_SIZE_T)_C_tab_size];
645 _C_upper_tab =
new _UChar [(_RWSTD_SIZE_T)_C_tab_size * 2];
646 _C_lower_tab = _C_upper_tab + _C_tab_size;
653 for (char_type
i = 0;
i <= char_type (_RWSTD_UCHAR_MAX);
i++) {
657#ifndef _RWSTD_NO_ISWSPACE
662 m |= _RW::__rw_space;
664#ifndef _RWSTD_NO_ISWPRINT
669 m |= _RW::__rw_print;
671#ifndef _RWSTD_NO_ISWCNTRL
676 m |= _RW::__rw_cntrl;
678#ifndef _RWSTD_NO_ISWUPPER
683 m |= _RW::__rw_upper;
685#ifndef _RWSTD_NO_ISWLOWER
690 m |= _RW::__rw_lower;
692#ifndef _RWSTD_NO_ISWALPHA
697 m |= _RW::__rw_alpha;
699#ifndef _RWSTD_NO_ISWDIGIT
704 m |= _RW::__rw_digit;
706#ifndef _RWSTD_NO_ISWPUNCT
711 m |= _RW::__rw_punct;
713#ifndef _RWSTD_NO_ISWXDIGIT
714 if ((::iswxdigit)(
i))
718 m |= _RW::__rw_xdigit;
720#ifndef _RWSTD_NO_ISWGRAPH
725 m |= _RW::__rw_graph;
729 typedef _RWSTD_SIZE_T SizeT;
731#ifndef _RWSTD_NO_TOWUPPER
732 const SizeT upr = SizeT ((::towupper)(
i));
734 const SizeT upr = SizeT ((::toupper)(
i));
737#ifndef _RWSTD_NO_TOWLOWER
738 const SizeT lwr = SizeT ((::towlower)(
i));
740 const SizeT lwr = SizeT ((::tolower)(
i));
744 _C_upper_tab [
i] = upr <= SizeT (_RWSTD_UCHAR_MAX) ?
745 _UChar (upr) : _UChar (0);
747 _C_lower_tab [
i] = lwr <= SizeT (_RWSTD_UCHAR_MAX) ?
748 _UChar (lwr) : _UChar (0);
753 _C_delete_it =
false;
755 _C_mask_tab = (mask*)impl->mask_tab;
756 _C_upper_tab = impl->toupper_tab;
757 _C_lower_tab = impl->tolower_tab;
762ctype_byname<wchar_t>::
766 if (_C_cvtimpl != 0 && _C_cvtsize != 0)
767 _RW::__rw_release_facet_data (_C_cvtimpl, _C_cvtsize);
772ctype_byname<wchar_t>::
773do_is (mask
m,
wchar_t c)
const
775 _RW::__rw_ctype_t* impl =
780 const bool libstd = 0 != (this->_C_opts & this->_C_use_libstd);
784 _RW::__rw_get_mask (impl, &
c, &
c + 1,
m, &
res,
false, libstd, _C_name);
790const ctype_byname<wchar_t>::char_type*
791ctype_byname<wchar_t>::
792do_is (
const char_type *lo,
const char_type *hi, mask *mvec)
const
795 _RW::__rw_ctype_t* impl =
800 const bool libstd = 0 != (this->_C_opts & this->_C_use_libstd);
802 return _RW::__rw_get_mask (impl, lo, hi, _RW::__rw_all,
803 mvec,
false, libstd, _C_name);
807ctype_byname<wchar_t>::char_type
808ctype_byname<wchar_t>::
809do_toupper (char_type
c)
const
811 _RW::__rw_ctype_t* impl =
816 const bool use_libstd = 0 != (this->_C_opts & this->_C_use_libstd);
818 return _RW::__rw_toupper (impl,
c, use_libstd, _C_name);
822ctype_byname<wchar_t>::char_type
823ctype_byname<wchar_t>::
824do_tolower (char_type
c)
const
826 _RW::__rw_ctype_t* impl =
831 const bool use_libstd = 0 != (this->_C_opts & this->_C_use_libstd);
833 return _RW::__rw_tolower (impl,
c, use_libstd, _C_name);
837const ctype_byname<wchar_t>::char_type*
838ctype_byname<wchar_t>::
839do_toupper (char_type *lo,
const char_type *hi)
const
842 _RW::__rw_ctype_t* impl =
847 const bool use_libstd = 0 != (this->_C_opts & this->_C_use_libstd);
850 for ( ; lo < hi; ++lo)
851 *lo = _RW::__rw_toupper (impl, *lo, use_libstd, _C_name);
856const ctype_byname<wchar_t>::char_type*
857ctype_byname<wchar_t>::
858do_tolower (char_type *lo,
const char_type *hi)
const
861 _RW::__rw_ctype_t* impl =
866 const bool use_libstd = 0 != (this->_C_opts & this->_C_use_libstd);
869 for ( ; lo < hi; ++lo)
870 *lo = _RW::__rw_tolower (impl, *lo, use_libstd, _C_name);
875const ctype_byname<wchar_t>::char_type*
876ctype_byname<wchar_t>::
877do_scan_is (mask
m,
const char_type* lo,
const char_type* hi)
const
881 _RW::__rw_ctype_t* impl =
885 const bool libstd = 0 != (this->_C_opts & this->_C_use_libstd);
887 return _RW::__rw_get_mask (impl, lo, hi,
m, 0,
true, libstd, _C_name);
891const ctype_byname<wchar_t>::char_type*
892ctype_byname<wchar_t>::
893do_scan_not (mask
m,
const char_type *lo,
const char_type *hi)
const
897 _RW::__rw_ctype_t* impl =
901 const bool libstd = 0 != (this->_C_opts & this->_C_use_libstd);
903 return _RW::__rw_get_mask (impl, lo, hi,
m, 0,
false, libstd, _C_name);
908ctype_byname<wchar_t>::
909do_narrow (char_type
c,
char dfault)
const
911#if _RWSTD_WCHAR_MIN < 0
925 const _RW::__rw_codecvt_t*
cvt =
929 if (0 ==
cvt || (this->_C_opts & this->_C_use_libc)) {
931#ifndef _RWSTD_NO_WCTOB
933 const _RW::__rw_setlocale clocale (_C_name,
LC_CTYPE);
935 const int tmp = wctob (
c);
937 ch =
tmp < 0 ? dfault : char (
tmp);
939#elif !defined (_RWSTD_NO_WCTOMB)
941 char tmp [_RWSTD_MB_LEN_MAX];
942 ch = 1 == wctomb (
tmp,
c) ? *
tmp : dfault;
953#if _RWSTD_WCHAR_MIN < 0
967 unsigned int* ptbl = tbl;
971 _RWSTD_SIZE_T utf8_sz = _RW::__rw_itoutf8 (
c,
tmp);
973#if _RWSTD_WCHAR_MIN < 0
975 const wchar_t imask =
wchar_t (~(_RWSTD_WCHAR_MAX));
977 const wchar_t imask =
wchar_t (~(_RWSTD_WCHAR_MAX >> 1));
980 typedef unsigned char UChar;
983 wc = ptbl [
UChar (*ptmp)];
986 if (wc == (imask | _RWSTD_WCHAR_MAX))
989 ptbl = tbl + 256 * (wc & (~imask));
997 wc = ptbl [
UChar (*ptmp)];
1003 const char* impl_raw =
1005 _RWSTD_SIZE_T
offset = wc +
sizeof (_RW::__rw_codecvt_t);
1007 if (impl_raw [
offset + 1])
1017const ctype_byname<wchar_t>::char_type*
1018ctype_byname<wchar_t>::
1019do_narrow (
const char_type *lo,
const char_type *hi,
1020 char dfault,
char *dest)
const
1026 *dest++ = do_narrow (*lo, dfault);
1033ctype_byname<wchar_t>::char_type
1034ctype_byname<wchar_t>::
1035do_widen (
char c)
const
1037 const unsigned char u_c = _UChar (
c);
1040 return char_type (u_c);
1046 const _RW::__rw_codecvt_t*
cvt =
1051 if (0 ==
cvt || (this->_C_opts & this->_C_use_libc)) {
1053#ifndef _RWSTD_NO_BTOWC
1055 const _RW::__rw_setlocale clocale (_C_name,
LC_CTYPE);
1062 ch = char_type (u_c);
1069#if _RWSTD_WCHAR_MIN < 0
1071 const char_type imask = char_type (~(_RWSTD_WCHAR_MAX));
1073 const char_type imask = char_type (~(_RWSTD_WCHAR_MAX >> 1));
1080 ch =
cvt->n_to_w_tab ()[u_c];
1082 return char_type (_RWSTD_WEOF);
1084 ch =
cvt->get_internal_at_offset (ch);
1092ctype_byname<wchar_t>::
1093do_widen (
const char *lo,
const char *hi, char_type *dest)
const
1099 *dest++ =
widen (*lo++);
const char * widen(char *dst, const char *src)
#define _RWSTD_REINTERPRET_CAST(T, x)
#define _RWSTD_UNUSED(arg)
#define _RWSTD_STATIC_CAST(T, x)
#define _RWSTD_NAMESPACE(name)
#define _RWSTD_ASSERT(ignore)
#define _RWSTD_CONST_CAST(T, x)
#define _RWSTD_SPECIALIZE_USE_FACET(fid)
#define _RWSTD_DEFINE_FACET_FACTORY(Linkage, Facet, TArgs, fid)