GeezerVison is showing cplusplus.com — std::ctype
-
ctype::ctype
public member functions
ctype<char> specialization
protected members
class template
<locale>
std::ctype
template <class charT> class ctype;
Character type facet
The ctype standard facet classifies and transforms characters, adapting the functionality of the C library header <cctype> to C++ locales.
The ctype class template has a protected destructor: Programs shall only construct objects of derived classes, or use those installed in locale objects (through use_facet).
All standard locale objects support at least the following facet instantiations of the ctype class template as part of the ctype category:
| facets in locale objects | description |
ctype<char> | narrow characters
produces the same results as the functions in header <cctype> for the classic locale
* specialized with a particular implementation (see specializations below) |
ctype<wchar_t> | wide characters |
Template parameters
- charT
- Character type.
Aliased as member char_type.
Member types
| member type | definition | description |
| char_type | The template parameter (charT) | Character type |
The class also inherits ctype_base::mask, which is used extensively as a parameter and return type by member functions (see ctype_base).
Member constants
The following member constants are inherited from ctype_base; They are used to identify character categories.
| member constant | type | value | description |
| space | ctype_base::mask | unspecified (unique bits) | white-space character |
| print | ctype_base::mask | unspecified (unique bits) | printable character |
| cntrl | ctype_base::mask | unspecified (unique bits) | control character |
| upper | ctype_base::mask | unspecified (unique bits) | uppercase letter |
| lower | ctype_base::mask | unspecified (unique bits) | lowercase letter |
| alpha | ctype_base::mask | unspecified (unique bits) | alphabetic character |
| digit | ctype_base::mask | unspecified (unique bits) | decimal digit |
| punct | ctype_base::mask | unspecified (unique bits) | punctuation character |
| xdigit | ctype_base::mask | unspecified (unique bits) | hexadecimal digit |
| alnum | ctype_base::mask | alpha|digit | alpha-numeric character |
| graph | ctype_base::mask | alnum|punct | character with graphic representation |
| member constant | type | value | description |
| space | ctype_base::mask | unspecified (unique bits) | white-space character |
| print | ctype_base::mask | unspecified (unique bits) | printable character |
| cntrl | ctype_base::mask | unspecified (unique bits) | control character |
| upper | ctype_base::mask | unspecified (unique bits) | uppercase letter |
| lower | ctype_base::mask | unspecified (unique bits) | lowercase letter |
| alpha | ctype_base::mask | unspecified (unique bits) | alphabetic character |
| digit | ctype_base::mask | unspecified (unique bits) | decimal digit |
| punct | ctype_base::mask | unspecified (unique bits) | punctuation character |
| xdigit | ctype_base::mask | unspecified (unique bits) | hexadecimal digit |
| blank | ctype_base::mask | unspecified (unique bits) | blank character |
| alnum | ctype_base::mask | alpha|digit | alpha-numeric character |
| graph | ctype_base::mask | alnum|punct | character with graphic representation |
See <cctype> for details on how ASCII characters are classified with respect to these categories.
The class also contains a public static constant of type locale::id, that uniquely identifies facets with ctype semantics.
Public member functions
- (constructor)
- ctype constructor (public member function)
Character classification
- is
- Classify characters (public member function)
- scan_is
- Return first character in category (public member function)
- scan_not
- Return first character not in category (public member function)
Character transformation
- toupper
- Convert to uppercase (public member function)
- tolower
- Convert to lowercase (public member function)
- widen
- Widen character(s) (public member function)
- narrow
- Narrow character(s) (public member function)
Virtual protected member functions
The class defines the virtual protected members which implement the behavior by default of their respective public member functions:
- do_is
- Classify characters [virtual] (protected virtual member function)
- do_scan_is
- Return first character in category [virtual] (protected virtual member function)
- do_scan_not
- Return first character not in category [virtual] (protected virtual member function)
- do_toupper
- Convert to uppercase [virtual] (protected virtual member function)
- do_tolower
- Convert to lowercase [virtual] (protected virtual member function)
- do_widen
- Widen character(s) [virtual] (protected virtual member function)
- do_narrow
- Narrow character(s) [virtual] (protected virtual member function)
Along with the class destructor:
- (destructor)
- ctype destructor (protected member function)
Specializations
At least the following specializations of this template are provided in all library implementations:
| specialization |
ctype<char> |
ctype<wchar_t> |
Particular specialization: ctype<char>
On the char specialization, some of the member functions are implemented inline instead of calling their do_ counterparts (this is the case for members is, scan_is and scan_not).
It has a different constructor, and keeps an internal table of elements of type ctype::mask with the classification of each of the characters in the character set: The value of each element in the array corresponds to the classification of the character given by its order position.
The size of this table is indicated by an additional static public member constant:
| member constant | type | value | description |
| table_size | const size_t | implementation-specific (at least 256) | The size of the table |
This specialization contains two additional
protected members:
- table
- Get category table (public member function)
- classic_table
- Get classic table (public static member function)
This specialization contains two additional
public members:
- table
- Get category table (public member function)
- classic_table
- Get classic table (public static member function)
Note that do_is, do_scan_is and do_scan_not are not members of the char specialization.