C character classification
C character classification is a group of operations in the C standard library that test a character for membership in a particular class of characters; such as alphabetic, control, etc. Both single-byte, and wide characters are supported.[1] HistoryEarly C programmers working on the Unix operating system developed programming idioms for classifying characters. For example, the following code evaluates as true for an ASCII letter character ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')
Eventually, the interface to common character classification functionality was codified in the C standard library file ctype.h. ImplementationFor performance, the standard character classification functions are usually implemented as macros instead of functions. But, due to limitations of macro evaluation, they are generally not implemented today as they were in early versions of Linux like: #define isdigit(c) ((c) >= '0' && (c) <= '9')
This can lead to an error when the macro parameter To eliminate this problem, a common implementation is for the macro to use table lookup. For example, the standard library provides an array of 256 integers – one for each character value – that each contain a bit-field for each supported classification. A macro references an integer by character value index and accesses the associated bit-field. For example, if the low bit indicates whether the character is a digit, then the #define isdigit(c) (TABLE[c] & 1)
The macro argument, Overview of functionsThe functions that operate on single-byte characters are defined in ctype.h header file (cctype in C++). The functions that operate on wide characters are defined in wctype.h header file (cwctype in C++). The classification is evaluated according to the effective locale.
References
External linksThe Wikibook A Little C Primer has a page on the topic of: C Character Class Test Library The Wikibook C Programming has a page on the topic of: C Programming/C Reference
|
Portal di Ensiklopedia Dunia