-
Notifications
You must be signed in to change notification settings - Fork 0
cctype
DryPerspective edited this page Nov 20, 2023
·
1 revision
The standard library cctype header's functions have two primary issues:
-
It is undefined behaviour to take their address, meaning they cannot be used directly in range functions and algorithm calls.
-
They are undefined behaviour to use if the system's
chartype cannot be represented as eitherunsigned charor EOF.
This header contains functions which address both of these. As user-defined functions, their address can be freely taken. Similarly they will cause a compilation failure if their use is attempted on a system where a char cannot be safely cast to unsigned char in a value-preserving way.
| isalnum | Returns whether a given character is alphanumeric |
| isalpha | Returns whether a given character is alphabetic |
| islower | Returns whether a given character is lower case |
| isupper | Returns whether a given character is upper case |
| isdigit | Returns whether a given character is a numeric digit |
| isxdigit | Returns whether a given character is a hex digit (0123456789ABCDEFabcdef) |
| iscntrl | Returns whether a given character is a control character |
| isgraph | Returns whether a given character is a graphical character |
| isspace | Returns whether a given character is a space character |
| isprint | Returns whether a given character is a printable character |
| ispunct | Returns whether a given character is a punctuation character |
| tolower | Converts a given character to lower case |
| toupper | Converts a given character to upper case |
#include <algorithm>
#include <string>
#include "cpp98/cctype.h"
int main(){
std::string mix("a MiX Of CaSeS");
int num_upper_case = std::count_if(mix.begin(), mix.end(), dp::isupper); //Would be UB to use std::isupper
//Convert all to lower
std::transform(mix.begin(), mix.end(), mix.begin(), dp::tolower); //Would also be UB to use std::tolower
}