Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

ctype.h

Go to the documentation of this file.
00001 /*!     \file include/ctype.h
00002  *      \brief Character types header.
00003  *      \author Linus Torvalds.
00004  *      \date Last update: 2003-11-05 by Andrea Righi.
00005  *      \note Added Doxygen documentation.
00006  */
00007 
00008 #ifndef CTYPE_H
00009 #define CTYPE_H
00010 
00011 /*
00012  * NOTE! This ctype does not handle EOF like the standard C
00013  * library is required to.
00014  */
00015 
00016 #define _U      0x01    //!< upper.
00017 #define _L      0x02    //!< lower.
00018 #define _D      0x04    //!< digit.
00019 #define _C      0x08    //!< cntrl.
00020 #define _P      0x10    //!< punct.
00021 #define _S      0x20    //!< white space (space/lf/tab).
00022 #define _X      0x40    //!< hex digit.
00023 #define _SP     0x80    //!< hard space (0x20).
00024 
00025 extern unsigned char _ctype[];
00026 
00027 #define __ismask(x) (_ctype[(int)(unsigned char)(x)])
00028 
00029 //! Return a value != 0 only if \p c is an alphanumeric character.
00030 #define isalnum(c)      ((__ismask(c)&(_U|_L|_D)) != 0)
00031 //! Return a value != 0 only if \p c is an alphabetic character.
00032 #define isalpha(c)      ((__ismask(c)&(_U|_L)) != 0)
00033 //! Return a value != 0 only if \p c is a control character.
00034 #define iscntrl(c)      ((__ismask(c)&(_C)) != 0)
00035 //! Return a value != 0 only if \p c is a digit character.
00036 #define isdigit(c)      ((__ismask(c)&(_D)) != 0)
00037 //! Return a value != 0 only if \p c is a printable (not a space)
00038 //! character.
00039 #define isgraph(c)      ((__ismask(c)&(_P|_U|_L|_D)) != 0)
00040 //! Return a value != 0 only if \p c is a lower case character.
00041 #define islower(c)      ((__ismask(c)&(_L)) != 0)
00042 //! Return a value != 0 only if \p c is a printable character.
00043 #define isprint(c)      ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
00044 //! Return a value != 0 only if \p c is a punctuation-mark.
00045 #define ispunct(c)      ((__ismask(c)&(_P)) != 0)
00046 //! Return a value != 0 only if \p c is an empty space
00047 //! like TAB, CR, LF...
00048 #define isspace(c)      ((__ismask(c)&(_S)) != 0)
00049 //! Return a value != 0 only if \p c is an upper case character.
00050 #define isupper(c)      ((__ismask(c)&(_U)) != 0)
00051 //! Return a value != 0 only if \p c is a hexadecimal digit.
00052 #define isxdigit(c)     ((__ismask(c)&(_D|_X)) != 0)
00053 //! Return a value != 0 only if \p c is an ASCII character <= 127.
00054 #define isascii(c) (((unsigned char)(c))<=0x7f)
00055 //! Return only the ASCII lower 7 bits of the \p c character.
00056 #define toascii(c) (((unsigned char)(c))&0x7f)
00057 
00058 //! \brief Convert a character into the lower case.
00059 //! \param c The character to convert.
00060 //! \return The lower case of \p c.
00061 static inline unsigned char __tolower(unsigned char c)
00062 {
00063         if (isupper(c))
00064                 c -= 'A'-'a';
00065         return c;
00066 }
00067 
00068 //! \brief Convert a character into the upper case.
00069 //! \param c The character to convert.
00070 //! \return The upper case of \p c.
00071 static inline unsigned char __toupper(unsigned char c)
00072 {
00073         if (islower(c))
00074                 c -= 'a'-'A';
00075         return c;
00076 }
00077 
00078 //! Macro equivalent to __tolower(c).
00079 #define tolower(c) __tolower(c)
00080 
00081 //! Macro equivalent to __toupper(c).
00082 #define toupper(c) __toupper(c)
00083 
00084 #endif

Generated on Fri Feb 20 15:32:15 2004 for Minirighi by doxygen1.2.18