ctype_base.h (ctype_base): Consistency with linux.

2000-12-13  Benjamin Kosnik  <bkoz@redhat.com>

	* config/os/generic/bits/ctype_base.h (ctype_base): Consistency
	with linux.
	* config/os/generic/bits/ctype_inline.h (is): Same.
	* config/os/solaris/solaris2.5/bits/ctype_inline.h (is): Same.
	* config/os/solaris/solaris2.5/bits/ctype_base.h: Same.
	* config/os/solaris/solaris2.6/bits/ctype_inline.h (is): Same.
	* config/os/solaris/solaris2.6/bits/ctype_base.h: Same.
	* config/os/solaris/solaris2.7/bits/ctype_inline.h (is): Same.
	* config/os/solaris/solaris2.7/bits/ctype_base.h: Same.
	* config/os/irix/bits/ctype_inline.h (is): Same.
	* config/os/irix/bits/ctype_base.h (ctype_base): Same.
	* config/os/aix/bits/ctype_inline.h (is): Same.
	* config/os/aix/bits/ctype_base.h (ctype_base): Same.
	* config/os/bsd/netbsd/bits/ctype_inline.h (is): Same.
	* config/os/bsd/netbsd/bits/ctype_base.h (ctype_base): Same.
	* config/os/bsd/freebsd/bits/ctype_base.h (ctype_base): Same.
	* config/os/bsd/freebsd/bits/ctype_inline.h (is): Same.
	* config/os/newlib/bits/ctype_inline.h (is): Same.
	* config/os/newlib/bits/ctype_base.h (ctype_base): Same.

	* testsuite/22_locale/ctype_char_members.cc (test01): Add tests, fix.
	* testsuite/22_locale/ctype.cc (test01): Add tests for
	ctype_base::mask bitmask features.
	* src/locale.cc: Define const static data for ctype_base.
	* config/os/gnu-linux/bits/ctype_base.h (ctype_base): Make
	ctype_base::mask type an integer type, not an enum.
	* config/os/gnu-linux/bits/ctype_inline.h (is): Implement correctly.
	* include/bits/locale_facets.h: Tweaks.

	* include/bits/ios_base.h: Formatting tweaks.

	* docs/html/17_intro/C++STYLE: Add.

From-SVN: r38243
This commit is contained in:
Benjamin Kosnik 2000-12-14 07:20:37 +00:00 committed by Benjamin Kosnik
parent 413c5c85ca
commit d9ab8adb37
28 changed files with 418 additions and 262 deletions

View file

@ -1,3 +1,38 @@
2000-12-13 Benjamin Kosnik <bkoz@redhat.com>
* config/os/generic/bits/ctype_base.h (ctype_base): Consistency
with linux.
* config/os/generic/bits/ctype_inline.h (is): Same.
* config/os/solaris/solaris2.5/bits/ctype_inline.h (is): Same.
* config/os/solaris/solaris2.5/bits/ctype_base.h: Same.
* config/os/solaris/solaris2.6/bits/ctype_inline.h (is): Same.
* config/os/solaris/solaris2.6/bits/ctype_base.h: Same.
* config/os/solaris/solaris2.7/bits/ctype_inline.h (is): Same.
* config/os/solaris/solaris2.7/bits/ctype_base.h: Same.
* config/os/irix/bits/ctype_inline.h (is): Same.
* config/os/irix/bits/ctype_base.h (ctype_base): Same.
* config/os/aix/bits/ctype_inline.h (is): Same.
* config/os/aix/bits/ctype_base.h (ctype_base): Same.
* config/os/bsd/netbsd/bits/ctype_inline.h (is): Same.
* config/os/bsd/netbsd/bits/ctype_base.h (ctype_base): Same.
* config/os/bsd/freebsd/bits/ctype_base.h (ctype_base): Same.
* config/os/bsd/freebsd/bits/ctype_inline.h (is): Same.
* config/os/newlib/bits/ctype_inline.h (is): Same.
* config/os/newlib/bits/ctype_base.h (ctype_base): Same.
* testsuite/22_locale/ctype_char_members.cc (test01): Add tests, fix.
* testsuite/22_locale/ctype.cc (test01): Add tests for
ctype_base::mask bitmask features.
* src/locale.cc: Define const static data for ctype_base.
* config/os/gnu-linux/bits/ctype_base.h (ctype_base): Make
ctype_base::mask type an integer type, not an enum.
* config/os/gnu-linux/bits/ctype_inline.h (is): Implement correctly.
* include/bits/locale_facets.h: Tweaks.
* include/bits/ios_base.h: Formatting tweaks.
* docs/html/17_intro/C++STYLE: Add.
2000-12-12 Benjamin Kosnik <bkoz@purist.soma.redhat.com> 2000-12-12 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
* acinclude.m4 (GLIBCPP_CHECK_CTYPE_SUPPORT): Don't link ctype * acinclude.m4 (GLIBCPP_CHECK_CTYPE_SUPPORT): Don't link ctype

View file

@ -35,28 +35,21 @@
struct ctype_base struct ctype_base
{ {
typedef unsigned char mask;
// Non-standard typedefs. // Non-standard typedefs.
typedef const int* __to_type; typedef const int* __to_type;
enum // NB: Offsets into ctype<char>::_M_table force a particular size
{ // on the mask type. Because of this, we don't use an enum.
space = _ISSPACE, typedef unsigned char mask;
print = _ISPRINT, static const mask upper = _ISUPPER;
cntrl = _ISCNTRL, static const mask lower = _ISLOWER;
upper = _ISUPPER, static const mask alpha = _ISALPHA;
lower = _ISLOWER, static const mask digit = _ISDIGIT;
alpha = _ISALPHA, static const mask xdigit = _ISXDIGIT;
digit = _ISDIGIT, static const mask space = _ISSPACE;
punct = _ISPUNCT, static const mask print = _ISPRINT;
xdigit = _ISXDIGIT, static const mask graph = _ISGRAPH;
alnum = _ISALNUM, static const mask cntrl = _ISCNTRL;
graph = _ISGRAPH static const mask punct = _ISPUNCT;
}; static const mask alnum = _ISALNUM;
}; };

View file

@ -43,8 +43,15 @@
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
while (__low < __high) const int __bitmasksize = sizeof(mask) * 8;
*__vec++ = __OBJ_DATA(__lc_ctype)->mask[*__low++]; for (;__low < __high; ++__vec, ++__low)
{
mask __m = __OBJ_DATA(__lc_ctype)->mask[*__low++];
int __i = 0; // Lowest bitmask.
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }

View file

@ -37,40 +37,39 @@
struct ctype_base struct ctype_base
{ {
typedef unsigned long mask;
// Non-standard typedefs. // Non-standard typedefs.
typedef const int* __to_type; typedef const int* __to_type;
enum // NB: Offsets into ctype<char>::_M_table force a particular size
{ // on the mask type. Because of this, we don't use an enum.
typedef unsigned long mask;
#ifdef _CTYPE_S #ifdef _CTYPE_S
// FreeBSD 4.0 uses this style of define. // FreeBSD 4.0 uses this style of define.
space = _CTYPE_S, static const mask upper = _CTYPE_U;
print = _CTYPE_R, static const mask lower = _CTYPE_L;
cntrl = _CTYPE_C, static const mask alpha = _CTYPE_A;
upper = _CTYPE_U, static const mask digit = _CTYPE_D;
lower = _CTYPE_L, static const mask xdigit = _CTYPE_X;
alpha = _CTYPE_A, static const mask space = _CTYPE_S;
digit = _CTYPE_D, static const mask print = _CTYPE_R;
punct = _CTYPE_P, static const mask graph = _CTYPE_G;
xdigit = _CTYPE_X, static const mask cntrl = _CTYPE_C;
alnum = _CTYPE_A | _CTYPE_D, static const mask punct = _CTYPE_P;
graph = _CTYPE_G static const mask alnum = _CTYPE_A | _CTYPE_D;
#else #else
// Older versions, including Free BSD 3.4, use this style of define. // Older versions, including Free BSD 3.4, use this style of define.
space = _S, static const mask upper = _U;
print = _R, static const mask lower = _L;
cntrl = _C, static const mask alpha = _A;
upper = _U, static const mask digit = _D;
lower = _L, static const mask xdigit = _X;
alpha = _A, static const mask space = _S;
digit = _D, static const mask print = _R;
punct = _P, static const mask graph = _G;
xdigit = _X, static const mask cntrl = _C;
alnum = _A | _D, static const mask punct = _P;
graph = _G static const mask alnum = _A | _D;
#endif #endif
};
}; };

View file

@ -48,9 +48,15 @@
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
// XXX const int __bitmasksize = sizeof(mask) * 8;
while (__low < __high) for (;__low < __high; ++__vec, ++__low)
*__vec++ = _M_table[(unsigned char)(*__low++)]; {
mask __m = _M_table[*__low];
int __i = 0; // Lowest bitmask value, 1 == 1 << 0 means 0
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }

View file

@ -38,26 +38,21 @@
struct ctype_base struct ctype_base
{ {
typedef unsigned char mask;
// Non-standard typedefs. // Non-standard typedefs.
typedef const unsigned char* __to_type; typedef const unsigned char* __to_type;
enum // NB: Offsets into ctype<char>::_M_table force a particular size
{ // on the mask type. Because of this, we don't use an enum.
// NetBSD typedef unsigned char mask;
space = _S, static const mask upper = _U;
print = _P | _U | _L | _N | _B, static const mask lower = _L;
cntrl = _C, static const mask alpha = _U | _L;
upper = _U, static const mask digit = _N;
lower = _L, static const mask xdigit = _N | _X;
alpha = _U | _L, static const mask space = _S;
digit = _N, static const mask print = _P | _U | _L | _N | _B;
punct = _P, static const mask graph = _P | _U | _L | _N;
xdigit = _N | _X, static const mask cntrl = _C;
alnum = _U | _L | _N, static const mask punct = _P;
graph = _P | _U | _L | _N, static const mask alnum = _U | _L | _N;
};
}; };

View file

@ -43,8 +43,15 @@
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
while (__low < __high) const int __bitmasksize = sizeof(mask) * 8;
*__vec++ = _M_table[(unsigned char)(*__low++)]; for (;__low < __high; ++__vec, ++__low)
{
mask __m = _M_table[*__low];
int __i = 0; // Lowest bitmask.
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }

View file

@ -35,24 +35,23 @@
struct ctype_base struct ctype_base
{ {
typedef unsigned int mask;
// Non-standard typedefs. // Non-standard typedefs.
typedef const int* __to_type; typedef const int* __to_type;
enum // NB: Offsets into ctype<char>::_M_table force a particular size
{ // on the mask type. Because of this, we don't use an enum.
space = (1 << 0), // Whitespace typedef unsigned int mask;
print = (1 << 1), // Printing static const mask upper = 1 << 0;
cntrl = (1 << 2), // Control character static const mask lower = 1 << 1;
upper = (1 << 3), // UPPERCASE static const mask alpha = 1 << 2;
lower = (1 << 4), // lowercase static const mask digit = 1 << 3;
alpha = (1 << 5), // Alphabetic static const mask xdigit = 1 << 4;
digit = (1 << 6), // Numeric static const mask space = 1 << 5;
punct = (1 << 7), // Punctuation static const mask print = 1 << 6;
xdigit = (1 << 8), // Hexadecimal numeric static const mask graph = 1 << 7;
alnum = (1 << 9), // Alphanumeric static const mask cntrl = 1 << 8;
graph = (1 << 10) // Graphical static const mask punct = 1 << 9;
}; static const mask alnum = 1 << 10;
}; };

View file

@ -43,7 +43,7 @@
ctype<char>:: ctype<char>::
is(mask __m, char __c) const throw() is(mask __m, char __c) const throw()
{ {
bool __ret = false; bool __ret;
switch (__m) switch (__m)
{ {
case space: case space:
@ -80,6 +80,7 @@
__ret = isgraph(__c); __ret = isgraph(__c);
break; break;
default: default:
__ret = false;
break; break;
} }
return __ret; return __ret;
@ -89,8 +90,15 @@
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
while (__low < __high) const int __bitmasksize = 11; // Highest bitmask in ctype_base == 10
*__vec++ = _M_table[(unsigned char)(*__low++)]; for (;__low < __high; ++__vec, ++__low)
{
mask __m = _M_table[*__low];
int __i = 0; // Lowest bitmask in ctype_base == 0
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }

View file

@ -50,29 +50,20 @@
struct ctype_base struct ctype_base
{ {
// Non-standard typedefs. // Non-standard typedefs.
// XXX
typedef unsigned short mask;
typedef unsigned short __table_type;
typedef const int* __to_type; typedef const int* __to_type;
// XXX // NB: Offsets into ctype<char>::_M_table force a particular size
// enum mask // on the mask type. Because of this, we don't use an enum.
enum typedef unsigned short mask;
{ static const mask upper = _ISupper;
space = _ISspace, static const mask lower = _ISlower;
print = _ISprint, static const mask alpha = _ISalpha;
cntrl = _IScntrl, static const mask digit = _ISdigit;
upper = _ISupper, static const mask xdigit = _ISxdigit;
lower = _ISlower, static const mask space = _ISspace;
alpha = _ISalpha, static const mask print = _ISprint;
digit = _ISdigit, static const mask graph = _ISgraph;
punct = _ISpunct, static const mask cntrl = _IScntrl;
xdigit = _ISxdigit, static const mask punct = _ISpunct;
alnum = _ISalnum, static const mask alnum = _ISalnum;
graph = _ISgraph
};
}; };

View file

@ -37,14 +37,21 @@
bool bool
ctype<char>:: ctype<char>::
is(mask __m, char __c) const throw() is(mask __m, char __c) const throw()
{ return _M_table[(unsigned char)(__c)] & __m; } { return _M_table[__c] & __m; }
const char* const char*
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
while (__low < __high) const int __bitmasksize = sizeof(mask) * 8;
*__vec++ = _M_table[(unsigned char)(*__low++)]; for (;__low < __high; ++__vec, ++__low)
{
mask __m = _M_table[*__low];
int __i = 1; // Lowest bitmask on linux, 1 <= x <= 15
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }
@ -52,7 +59,7 @@
ctype<char>:: ctype<char>::
scan_is(mask __m, const char* __low, const char* __high) const throw() scan_is(mask __m, const char* __low, const char* __high) const throw()
{ {
while (__low < __high && !(_M_table[(unsigned char)(*__low)] & __m)) while (__low < __high && !(_M_table[*__low] & __m))
++__low; ++__low;
return __low; return __low;
} }
@ -62,7 +69,7 @@
scan_not(mask __m, const char* __low, const char* __high) const throw() scan_not(mask __m, const char* __low, const char* __high) const throw()
{ {
while (__low < __high while (__low < __high
&& (_M_table[(unsigned char)(*__low)] & __m) != 0) && (_M_table[*__low] & __m) != 0)
++__low; ++__low;
return __low; return __low;
} }

View file

@ -39,11 +39,11 @@
using _C_legacy::__ctype_b; using _C_legacy::__ctype_b;
#endif #endif
ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) :
: __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del), __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del),
_M_toupper(__ctype_toupper), _M_tolower(__ctype_tolower), _M_toupper(__ctype_toupper), _M_tolower(__ctype_tolower),
_M_ctable(__ctype_b), _M_table(__table == 0 ? _M_ctable: __table) _M_ctable(__ctype_b), _M_table(__table == 0 ? _M_ctable : __table)
{ } { }
char char
ctype<char>::do_toupper(char __c) const ctype<char>::do_toupper(char __c) const

View file

@ -35,26 +35,21 @@
struct ctype_base struct ctype_base
{ {
typedef unsigned int mask;
// Non-standard typedefs. // Non-standard typedefs.
typedef int* __to_type; typedef int* __to_type;
enum // NB: Offsets into ctype<char>::_M_table force a particular size
{ // on the mask type. Because of this, we don't use an enum.
space = _ISspace, typedef unsigned int mask;
print = _ISprint, static const mask upper = _ISupper;
cntrl = _IScntrl, static const mask lower = _ISlower;
upper = _ISupper, static const mask alpha = _ISalpha;
lower = _ISlower, static const mask digit = _ISdigit;
alpha = _ISalpha, static const mask xdigit = _ISxdigit;
digit = _ISdigit, static const mask space = _ISspace;
punct = _ISpunct, static const mask print = _ISprint;
xdigit = _ISxdigit, static const mask graph = _ISgraph;
alnum = _ISalnum, static const mask cntrl = _IScntrl;
graph = _ISgraph static const mask punct = _ISpunct;
}; static const mask alnum = _ISalnum;
}; };

View file

@ -37,14 +37,21 @@
bool bool
ctype<char>:: ctype<char>::
is(mask __m, char __c) const throw() is(mask __m, char __c) const throw()
{ return (_M_table)[(unsigned char)(__c)] & __m; } { return (_M_table)[__c] & __m; }
const char* const char*
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
while (__low < __high) const int __bitmasksize = sizeof(mask) * 8;
*__vec++ = (_M_table)[(unsigned char)(*__low++)]; for (;__low < __high; ++__vec, ++__low)
{
mask __m = _M_table[*__low];
int __i = 1; // Lowest bitmask on linux, 1 <= x <= 15
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }
@ -52,7 +59,7 @@
ctype<char>:: ctype<char>::
scan_is(mask __m, const char* __low, const char* __high) const throw() scan_is(mask __m, const char* __low, const char* __high) const throw()
{ {
while (__low < __high && !((_M_table)[(unsigned char)(*__low)] & __m)) while (__low < __high && !((_M_table)[*__low] & __m))
++__low; ++__low;
return __low; return __low;
} }
@ -61,8 +68,7 @@
ctype<char>:: ctype<char>::
scan_not(mask __m, const char* __low, const char* __high) const throw() scan_not(mask __m, const char* __low, const char* __high) const throw()
{ {
while (__low < __high while (__low < __high && ((_M_table + 1)[*__low] & __m) != 0)
&& ((_M_table + 1)[(unsigned char)(*__low)] & __m) != 0)
++__low; ++__low;
return __low; return __low;
} }

View file

@ -37,25 +37,21 @@
struct ctype_base struct ctype_base
{ {
typedef char mask;
// Non-standard typedefs. // Non-standard typedefs.
typedef const int* __to_type; typedef const int* __to_type;
enum // NB: Offsets into ctype<char>::_M_table force a particular size
{ // on the mask type. Because of this, we don't use an enum.
space = 010, // Whitespace typedef char mask;
print = 020 | 01 | 02 | 04 | 0200, // Printing static const mask upper = _U;
cntrl = 040, // Control character static const mask lower = _L;
upper = 01, // UPPERCASE static const mask alpha = _U | _L;
lower = 02, // lowercase static const mask digit = _N;
alpha = 01 | 02, // Alphabetic static const mask xdigit = _X | _N;
digit = 04, // Numeric static const mask space = _S;
punct = 020, // Punctuation static const mask print = _P | _U | _L | _N | _B;
xdigit = 0200, // Hexadecimal numeric static const mask graph = _P | _U | _L | _N;
alnum = 01 | 02 | 04, // Alphanumeric static const mask cntrl = _C;
graph = 020 | 01 | 02 | 04 // Graphical static const mask punct = _P;
}; static const mask alnum = _U | _L | _N;
}; };

View file

@ -43,8 +43,15 @@
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
while (__low < __high) const int __bitmasksize = sizeof(mask) * 8;
*__vec++ = (_M_table + 1)[(unsigned char)(*__low++)]; for (;__low < __high; ++__vec, ++__low)
{
mask __m = _M_table[*__low];
int __i = 0; // Lowest bitmask with newlib, 1 << 0 == 01
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }

View file

@ -1,6 +1,6 @@
// Locale support -*- C++ -*- // Locale support -*- C++ -*-
// Copyright (C) 1997-1999 Cygnus Solutions // Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
@ -35,22 +35,21 @@
struct ctype_base struct ctype_base
{ {
typedef unsigned char mask;
// Non-standard typedefs. // Non-standard typedefs.
typedef const int* __to_type; typedef const int* __to_type;
enum // NB: Offsets into ctype<char>::_M_table force a particular size
{ // on the mask type. Because of this, we don't use an enum.
space = 010, // Whitespace typedef unsigned char mask;
print = 020 | 01 | 02 | 04 | 0200, // Printing static const mask upper = 01;
cntrl = 040, // Control character static const mask lower = 02;
upper = 01, // UPPERCASE static const mask alpha = 01 | 02;
lower = 02, // lowercase static const mask digit = 04;
alpha = 01 | 02, // Alphabetic static const mask xdigit = 0200;
digit = 04, // Numeric static const mask space = 010;
punct = 020, // Punctuation static const mask print = 020 | 01 | 02 | 04 | 0200;
xdigit = 0200, // Hexadecimal numeric static const mask graph = 020 | 01 | 02 | 04;
alnum = 01 | 02 | 04, // Alphanumeric static const mask cntrl = 040;
graph = 020 | 01 | 02 | 04 // Graphical static const mask punct = 020;
}; static const mask alnum = 01 | 02 | 04;
}; };

View file

@ -1,6 +1,6 @@
// Locale support -*- C++ -*- // Locale support -*- C++ -*-
// Copyright (C) 2000 Cygnus Solutions // Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
@ -43,8 +43,15 @@
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
while (__low < __high) const int __bitmasksize = sizeof(mask) * 8;
*__vec++ = (_M_table + 1)[(unsigned char)(*__low++)]; for (;__low < __high; ++__vec, ++__low)
{
mask __m = _M_table[*__low];
int __i = 0; // Lowest bitmask in ctype_base::mask.
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }

View file

@ -1,6 +1,6 @@
// Locale support -*- C++ -*- // Locale support -*- C++ -*-
// Copyright (C) 1997-1999 Cygnus Solutions // Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
@ -32,27 +32,25 @@
// //
// Information as gleaned from /usr/include/ctype.h. Looks like this // Information as gleaned from /usr/include/ctype.h. Looks like this
// only works with solaris2.6 and solaris2.7, but not solaris2.5.1. // only works with solaris2.6.
struct ctype_base struct ctype_base
{ {
typedef unsigned int mask;
// Non-standard typedefs. // Non-standard typedefs.
typedef long* __to_type; typedef long* __to_type;
enum // NB: Offsets into ctype<char>::_M_table force a particular size
{ // on the mask type. Because of this, we don't use an enum.
space = _ISSPACE, typedef unsigned int mask;
print = _ISPRINT, static const mask upper = _ISUPPER;
cntrl = _ISCNTRL, static const mask lower = _ISLOWER;
upper = _ISUPPER, static const mask alpha = _ISALPHA;
lower = _ISLOWER, static const mask digit = _ISDIGIT;
alpha = _ISALPHA, static const mask xdigit = _ISXDIGIT;
digit = _ISDIGIT, static const mask space = _ISSPACE;
punct = _ISPUNCT, static const mask print = _ISPRINT;
xdigit = _ISXDIGIT, static const mask graph = _ISGRAPH;
alnum = _ISALNUM, static const mask cntrl = _ISCNTRL;
graph = _ISGRAPH static const mask punct = _ISPUNCT;
}; static const mask alnum = _ISALNUM;
}; };

View file

@ -1,6 +1,6 @@
// Locale support -*- C++ -*- // Locale support -*- C++ -*-
// Copyright (C) 2000 Cygnus Solutions // Copyright (C) 2000 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
@ -37,14 +37,21 @@
bool bool
ctype<char>:: ctype<char>::
is(mask __m, char __c) const throw() is(mask __m, char __c) const throw()
{ return _M_table[(unsigned char)(__c)] & __m; } { return _M_table[__c] & __m; }
const char* const char*
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
while (__low < __high) const int __bitmasksize = sizeof(mask) * 8;
*__vec++ = _M_table[(unsigned char)(*__low++)]; for (;__low < __high; ++__vec, ++__low)
{
mask __m = _M_table[*__low];
int __i = 0; // Lowest bitmask value from ctype_base.
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }
@ -52,7 +59,7 @@
ctype<char>:: ctype<char>::
scan_is(mask __m, const char* __low, const char* __high) const throw() scan_is(mask __m, const char* __low, const char* __high) const throw()
{ {
while (__low < __high && !(_M_table[(unsigned char)(*__low)] & __m)) while (__low < __high && !(_M_table[*__low] & __m))
++__low; ++__low;
return __low; return __low;
} }
@ -62,7 +69,7 @@
scan_not(mask __m, const char* __low, const char* __high) const throw() scan_not(mask __m, const char* __low, const char* __high) const throw()
{ {
while (__low < __high while (__low < __high
&& (_M_table[(unsigned char)(*__low)] & __m) != 0) && (_M_table[*__low] & __m) != 0)
++__low; ++__low;
return __low; return __low;
} }

View file

@ -1,6 +1,6 @@
// Locale support -*- C++ -*- // Locale support -*- C++ -*-
// Copyright (C) 1997-1999 Cygnus Solutions // Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
@ -32,27 +32,26 @@
// //
// Information as gleaned from /usr/include/ctype.h. Looks like this // Information as gleaned from /usr/include/ctype.h. Looks like this
// only works with solaris2.6 and solaris2.7, but not solaris2.5.1. // only works with solaris2.7 and solaris2.8. Thanks for not changing
// things, sun engineers!
struct ctype_base struct ctype_base
{ {
typedef unsigned int mask;
// Non-standard typedefs. // Non-standard typedefs.
typedef int* __to_type; typedef int* __to_type;
enum // NB: Offsets into ctype<char>::_M_table force a particular size
{ // on the mask type. Because of this, we don't use an enum.
space = _ISSPACE, typedef unsigned int mask;
print = _ISPRINT, static const mask upper = _ISUPPER;
cntrl = _ISCNTRL, static const mask lower = _ISLOWER;
upper = _ISUPPER, static const mask alpha = _ISALPHA;
lower = _ISLOWER, static const mask digit = _ISDIGIT;
alpha = _ISALPHA, static const mask xdigit = _ISXDIGIT;
digit = _ISDIGIT, static const mask space = _ISSPACE;
punct = _ISPUNCT, static const mask print = _ISPRINT;
xdigit = _ISXDIGIT, static const mask graph = _ISGRAPH;
alnum = _ISALNUM, static const mask cntrl = _ISCNTRL;
graph = _ISGRAPH static const mask punct = _ISPUNCT;
}; static const mask alnum = _ISALNUM;
}; };

View file

@ -1,6 +1,6 @@
// Locale support -*- C++ -*- // Locale support -*- C++ -*-
// Copyright (C) 2000 Cygnus Solutions // Copyright (C) 2000 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
@ -37,14 +37,21 @@
bool bool
ctype<char>:: ctype<char>::
is(mask __m, char __c) const throw() is(mask __m, char __c) const throw()
{ return _M_table[(unsigned char)(__c)] & __m; } { return _M_table[__c] & __m; }
const char* const char*
ctype<char>:: ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const throw() is(const char* __low, const char* __high, mask* __vec) const throw()
{ {
while (__low < __high) const int __bitmasksize = sizeof(mask) * 8;
*__vec++ = _M_table[(unsigned char)(*__low++)]; for (;__low < __high; ++__vec, ++__low)
{
mask __m = _M_table[*__low];
int __i = 0; // Lowest bitmask value from ctype_base.
while (__i < __bitmasksize && !(__m & static_cast<mask>(1 << __i)))
++__i;
*__vec = static_cast<mask>(1 << __i);
}
return __high; return __high;
} }
@ -52,7 +59,7 @@
ctype<char>:: ctype<char>::
scan_is(mask __m, const char* __low, const char* __high) const throw() scan_is(mask __m, const char* __low, const char* __high) const throw()
{ {
while (__low < __high && !(_M_table[(unsigned char)(*__low)] & __m)) while (__low < __high && !(_M_table[*__low] & __m))
++__low; ++__low;
return __low; return __low;
} }
@ -62,7 +69,7 @@
scan_not(mask __m, const char* __low, const char* __high) const throw() scan_not(mask __m, const char* __low, const char* __high) const throw()
{ {
while (__low < __high while (__low < __high
&& (_M_table[(unsigned char)(*__low)] & __m) != 0) && (_M_table[*__low] & __m) != 0)
++__low; ++__low;
return __low; return __low;
} }

View file

@ -146,7 +146,18 @@ Notable areas of divergence from what may be previous local practice
-NOT- -NOT-
sync() sync()
Reason: ??? Reason: Koenig lookup.
11. constructor member intialization lists
should look like this:
ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) :
__ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del),
_M_toupper(__ctype_toupper), _M_tolower(__ctype_tolower),
_M_ctable(static_cast<const mask*>(__ctype_b),
_M_table(__table == 0 ? _M_ctable : __table)
{ }
The library currently has a mixture of GNU-C and modern C++ coding The library currently has a mixture of GNU-C and modern C++ coding
styles. The GNU C usages will be combed out gradually. styles. The GNU C usages will be combed out gradually.

View file

@ -40,7 +40,7 @@ namespace std {
// as permitted (but not required) in the standard, in order to provide // as permitted (but not required) in the standard, in order to provide
// better type safety in iostream calls. A side effect is that // better type safety in iostream calls. A side effect is that
// expressions involving them are no longer compile-time constants. // expressions involving them are no longer compile-time constants.
enum _Ios_Fmtflags { _S_ios_fmtflags_end = 1<<16 }; enum _Ios_Fmtflags { _M_ios_fmtflags_end = 1 << 16 };
inline _Ios_Fmtflags inline _Ios_Fmtflags
operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
@ -71,7 +71,7 @@ namespace std {
{ return _Ios_Fmtflags(~static_cast<int>(__a)); } { return _Ios_Fmtflags(~static_cast<int>(__a)); }
enum _Ios_Openmode { _S_ios_openmode_end = 1<<16 }; enum _Ios_Openmode { _M_ios_openmode_end = 1 << 16 };
inline _Ios_Openmode inline _Ios_Openmode
operator&(_Ios_Openmode __a, _Ios_Openmode __b) operator&(_Ios_Openmode __a, _Ios_Openmode __b)
@ -102,7 +102,7 @@ namespace std {
{ return _Ios_Openmode(~static_cast<int>(__a)); } { return _Ios_Openmode(~static_cast<int>(__a)); }
enum _Ios_Iostate { _S_ios_iostate_end = 1<<16 }; enum _Ios_Iostate { _M_ios_iostate_end = 1 << 16 };
inline _Ios_Iostate inline _Ios_Iostate
operator&(_Ios_Iostate __a, _Ios_Iostate __b) operator&(_Ios_Iostate __a, _Ios_Iostate __b)
@ -132,7 +132,7 @@ namespace std {
operator~(_Ios_Iostate __a) operator~(_Ios_Iostate __a)
{ return _Ios_Iostate(~static_cast<int>(__a)); } { return _Ios_Iostate(~static_cast<int>(__a)); }
enum _Ios_Seekdir { _S_ios_Seekdir_end = 1<<16 }; enum _Ios_Seekdir { _M_ios_seekdir_end = 1 << 16 };
// 27.4.2 Class ios_base // 27.4.2 Class ios_base
class ios_base class ios_base
@ -229,9 +229,8 @@ namespace std {
streamsize _M_width; streamsize _M_width;
fmtflags _M_flags; fmtflags _M_flags;
// 27.4.2.6 Members for callbacks // 27.4.2.6 Members for callbacks
// 27.4.2.6 ios_base callbacks // 27.4.2.6 ios_base callbacks
struct _Callback_list struct _Callback_list
{ {
// Data Members // Data Members
@ -259,7 +258,7 @@ namespace std {
void void
_M_dispose_callbacks(void); _M_dispose_callbacks(void);
// 27.4.2.5 Members for iword/pword storage // 27.4.2.5 Members for iword/pword storage
struct _Words struct _Words
{ {
void* _M_pword; void* _M_pword;
@ -282,11 +281,11 @@ namespace std {
_M_init(); _M_init();
public: public:
// 27.4.2.1.6 Class ios_base::Init // 27.4.2.1.6 Class ios_base::Init
// Used to initialize standard streams. In theory, g++ could use // Used to initialize standard streams. In theory, g++ could use
// -finit-priority to order this stuff correctly without going // -finit-priority to order this stuff correctly without going
// through these machinations. // through these machinations.
class Init class Init
{ {
friend class ios_base; friend class ios_base;
@ -362,7 +361,7 @@ namespace std {
static bool static bool
sync_with_stdio(bool __sync = true); sync_with_stdio(bool __sync = true);
// Locales: // Locales:
locale locale
imbue(const locale& __loc); imbue(const locale& __loc);

View file

@ -215,7 +215,6 @@ namespace std
public: public:
// Types: // Types:
typedef char char_type; typedef char char_type;
typedef ctype::mask mask;
private: private:
// Data Members: // Data Members:
@ -248,12 +247,10 @@ namespace std
virtual virtual
~ctype(); ~ctype();
// XXX
const mask* const mask*
table() const throw() table() const throw()
{ return _M_table; } { return _M_table; }
// XXX
const mask* const mask*
classic_table() throw() classic_table() throw()
{ return _M_ctable; } { return _M_ctable; }
@ -312,7 +309,6 @@ namespace std
public: public:
// Types: // Types:
typedef wchar_t char_type; typedef wchar_t char_type;
typedef ctype::mask mask;
typedef wctype_t __wmask_type; typedef wctype_t __wmask_type;
// Data Members: // Data Members:

View file

@ -778,6 +778,19 @@ namespace std {
_Bad_use_facet:: _Bad_use_facet::
~_Bad_use_facet() throw() { } ~_Bad_use_facet() throw() { }
// Definitions for static const data members of ctype_base.
const ctype_base::mask ctype_base::space;
const ctype_base::mask ctype_base::print;
const ctype_base::mask ctype_base::cntrl;
const ctype_base::mask ctype_base::upper;
const ctype_base::mask ctype_base::lower;
const ctype_base::mask ctype_base::alpha;
const ctype_base::mask ctype_base::digit;
const ctype_base::mask ctype_base::punct;
const ctype_base::mask ctype_base::xdigit;
const ctype_base::mask ctype_base::alnum;
const ctype_base::mask ctype_base::graph;
// Platform-specific initialization code for ctype tables. // Platform-specific initialization code for ctype tables.
#include <bits/ctype_noninline.h> #include <bits/ctype_noninline.h>

View file

@ -30,5 +30,29 @@ int mask ();
class gnu_ctype: public std::ctype<unsigned char> { }; class gnu_ctype: public std::ctype<unsigned char> { };
gnu_ctype facet01; gnu_ctype facet01;
// 3: Sanity check ctype_base::mask bitmask requirements
void
test01()
{
using namespace std;
int main() { } ctype_base::mask m01;
ctype_base::mask m02;
m01 = ctype_base::space;
m02 = ctype_base::xdigit;
m01 & m02;
m01 | m02;
m01 ^ m02;
m01 ~ m02;
m01 &= m02;
m01 |= m02;
m01 ^= m02;
}
int main()
{
test01();
return 0;
}

View file

@ -56,6 +56,22 @@ void test01()
int len = std::char_traits<char>::length(strlit00); int len = std::char_traits<char>::length(strlit00);
char c_array[len + 1]; char c_array[len + 1];
// sanity check ctype_base::mask members
int i01 = std::ctype_base::space;
int i02 = std::ctype_base::upper;
int i03 = std::ctype_base::lower;
int i04 = std::ctype_base::digit;
int i05 = std::ctype_base::punct;
int i06 = std::ctype_base::alpha;
int i07 = std::ctype_base::xdigit;
int i08 = std::ctype_base::alnum;
int i09 = std::ctype_base::graph;
int i10 = std::ctype_base::print;
int i11 = std::ctype_base::cntrl;
int i12 = sizeof(std::ctype_base::mask);
VERIFY ( i01 != i02 != i03 != i04 != i05 != i06 != i07 != i08 != i09 );
VERIFY ( i01 != i10 != i11);
// bool is(mask m, char c) const; // bool is(mask m, char c) const;
VERIFY( gctype.is(std::ctype_base::space, c30) ); VERIFY( gctype.is(std::ctype_base::space, c30) );
VERIFY( gctype.is(std::ctype_base::upper, c00) ); VERIFY( gctype.is(std::ctype_base::upper, c00) );
@ -72,20 +88,49 @@ void test01()
VERIFY( gctype.is(std::ctype_base::graph, c20) ); VERIFY( gctype.is(std::ctype_base::graph, c20) );
// const char* is(const char* low, const char* high, mask* vec) const // const char* is(const char* low, const char* high, mask* vec) const
std::ctype_base::mask m01 = static_cast<std::ctype_base::mask>(0); std::ctype_base::mask m00 = static_cast<std::ctype_base::mask>(0);
std::ctype_base::mask m02 = std::ctype_base::digit; std::ctype_base::mask m01[3];
std::ctype_base::mask m02[13];
const char* cc0 = strlit00; const char* cc0 = strlit00;
const char* cc1 = NULL; const char* cc1 = NULL;
const char* cc2 = NULL; const char* cc2 = NULL;
#if 1
cc1 = gctype.is(cc0, cc0, &m01);
VERIFY( cc1 == strlit00 );
cc2 = gctype.is(cc0, cc0 + 3, &m01);
VERIFY( cc2 == strlit00 + 3);
cc1 = gctype.is(cc0, cc0 + 13, &m02); cc0 = strlit00;
m01[0] = m00;
m01[1] = m00;
m01[2] = m00;
cc1 = gctype.is(cc0, cc0, m01);
VERIFY( cc1 == strlit00 );
VERIFY( m01[0] == m00 );
VERIFY( m01[1] == m00 );
VERIFY( m01[2] == m00 );
cc0 = strlit00;
m01[0] = m00;
m01[1] = m00;
m01[2] = m00;
cc2 = gctype.is(cc0, cc0 + 3, m01);
VERIFY( cc2 == strlit00 + 3);
VERIFY( m01[0] != m00 );
VERIFY( m01[1] != m00 );
VERIFY( m01[2] != m00 );
VERIFY( gctype.is(m01[0], cc0[0]) );
VERIFY( gctype.is(m01[1], cc0[1]) );
VERIFY( gctype.is(m01[2], cc0[2]) );
cc0 = strlit00;
cc1 = gctype.is(cc0, cc0 + 13, m02);
VERIFY( cc1 == strlit00 + 13); VERIFY( cc1 == strlit00 + 13);
#endif VERIFY( m02[6] != m00 );
VERIFY( m02[7] != m00 );
VERIFY( m02[8] != m00 );
VERIFY( m02[8] != m02[6] != m02[7] );
VERIFY( static_cast<bool>(m02[6] & std::ctype_base::alnum) );
VERIFY( static_cast<bool>(m02[7] & std::ctype_base::punct) );
VERIFY( static_cast<bool>(m02[8] & std::ctype_base::space) );
VERIFY( gctype.is(m02[6], cc0[6]) );
VERIFY( gctype.is(m02[7], cc0[7]) );
VERIFY( gctype.is(m02[8], cc0[8]) );
// char toupper(char c) const // char toupper(char c) const
c100 = gctype.toupper(c10); c100 = gctype.toupper(c10);