One of the oldest and most useful C++ libraries
is the Character Type library inherited from ANSI C.
You use these function to classify characters by their type
and they work on even weird character sets like EBCDIC.
On the other hand they don't work on strings or arrays of characters.
Most of the functions test for particular types of characters, but
two function change a characters case...
- For c:char.
In the following list c stands for a char.
- isalnum(c)::bool=c is an alphanumeric character.
if( isalnum(c) ) ....
- isalpha(c)::bool=c is a letter.
while( isalpha(c) ) ....
- iscntrl(c)::bool=c is a special control character, ASCII(0)..ASCII(31).
bool remember_is_control = iscntrl(c);
- isdigit(c)::bool=c is a decimal digit, '0'..'9'.
- isgraph(c)::bool=c is a graphic character, a printing character other than space.
- islower(c)::bool=c is a lower case letter, 'a'..'z'.
- isprint(c)::bool=c is not a control character but prints something including a space.
- ispunct(c)::bool=c is a punctuation character = isprint(c) && !isspace(c) && !isalnum(c).
- isspace(c)::bool=c is a white space character including space, tab, newline, carriage return etc..
- isupper(c)::bool=c is an UPPER CASE LETTER.
- isxdigit(c)::bool=c is a hexadecimal digit, '0'..'9' | 'A'..'F' | 'a'..'f'.
- toupper(c)::char=converts lower case letters into upper case letters and copies all others.
char upper= toupper(c);
- tolower(c)::char=converts upper case letters into lower case letters and copies all others.
char lower= tolower(c);
- char::data_type=the 8 bit character set available on the computer in use.
- bool::data_type=data that is true or false and is used in conditions.
Converting the case of strings
The toupper and tolower functions apply only to characters not to
strings. The don't have the best definitions to work with the <algorithm>
library. Worse they are overloaded with versions in the <locale> library
[ topic.asp?topic_id=228118 ]
[ msg01286.html ]
and so code like this
[ toUpper.cpp ]
is needed to use transform to
change the case of a C++ string.