00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00016 00017 /*! 00018 * @defgroup char Character classification and manipulation 00019 * 00020 * The char family of macros check whether ch, which must have the value of 00021 * an unsigned char, falls into a certain character class. 00022 * 00023 * char_isalnum() checks for an alphanumeric character; it is equivalent to 00024 * (char_isalpha(ch) || char_isdigit(ch)). 00025 * 00026 * char_isalpha() checks for an alphabetic character; it is equivalent to 00027 * (char_isupper(c) || char_islower(c)). 00028 * 00029 * char_isascii() checks whether ch is a 7-bit unsigned char value that fits 00030 * into the ASCII character set. 00031 * 00032 * char_isblank() checks for a blank character; that is, a space or a tab. 00033 * 00034 * char_iscntrl() checks for a control character. 00035 * 00036 * char_isdigit() checks for a digit (0 through 9). 00037 * 00038 * char_isgraph() checks for any printable character except space. 00039 * 00040 * char_islower() checks for a lower-case character. 00041 * 00042 * char_isprint() checks for any printable character including space. 00043 * 00044 * char_ispunct() checks for any printable character which is not a space or 00045 * an alphanumeric character. 00046 * 00047 * char_isspace() checks for white-space characters. These are: space, 00048 * form-feed ('\f'), newline ('\n'), carriage return ('\r'), 00049 * horizontal tab ('\t'), and vertical tab ('\v'). 00050 * 00051 * char_isupper() checks for an uppercase letter. 00052 * 00053 * char_isxdigit() checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 00054 * 8 9 a b c d e f A B C D E F. 00055 * 00056 * char_tolower() converts a character to lowercase if applicable. 00057 * 00058 * char_toupper() converts a character to uppercase if applicable. 00059 * 00060 * @{ 00061 */ 00062 00063 #ifndef _LUCID_CHAR_H 00064 #define _LUCID_CHAR_H 00065 00066 /*! @brief check for an ASCII character */ 00067 #define char_isascii(ch) ((unsigned int)(ch) < 128u) 00068 00069 /*! @brief check for a blank character (space, horizontal tab) */ 00070 #define char_isblank(ch) (ch == ' ' || ch == '\t') 00071 00072 /*! @brief check for an ASCII control character */ 00073 #define char_iscntrl(ch) ((unsigned int)(ch) < 32u || ch == 127) 00074 00075 /*! @brief check for a digit character (0-9) */ 00076 #define char_isdigit(ch) ((unsigned int)(ch - '0') < 10u) 00077 00078 /*! @brief check for graphable characters (excluding space) */ 00079 #define char_isgraph(ch) ((unsigned int)(ch - '!') < 94u) 00080 00081 /*! @brief check for a lower-case character */ 00082 #define char_islower(ch) ((unsigned int)(ch - 'a') < 26u) 00083 00084 /*! @brief check for a printable character (including space) */ 00085 #define char_isprint(ch) ((unsigned int)(ch - ' ') < 95u) 00086 00087 /*! @brief check for a whitespace character (\\t, \\n, \\v, \\f, \\r) */ 00088 #define char_isspace(ch) ((unsigned int)(ch - '\t') < 5u || ch == ' ') 00089 00090 /*! @brief check for an upper-case character */ 00091 #define char_isupper(ch) ((unsigned int)(ch - 'A') < 26u) 00092 00093 /*! @brief check for a hexadecimal character */ 00094 #define char_isxdigit(ch) (char_isdigit(ch) || \ 00095 (unsigned int)(ch - 'a') < 6u || \ 00096 (unsigned int)(ch - 'A') < 6u) 00097 00098 00099 /*! @brief check for an upper- or lower-case character */ 00100 #define char_isalpha(ch) (char_islower(ch) || char_isupper(ch)) 00101 00102 /*! @brief check for an upper-, lower-case or digit character */ 00103 #define char_isalnum(ch) (char_isalpha(ch) || char_isdigit(ch)) 00104 00105 /*! @brief check for a punctuation character */ 00106 #define char_ispunct(ch) (char_isprint(ch) && \ 00107 !char_isalnum(ch) && \ 00108 !char_isspace(ch)) 00109 00110 00111 /*! @brief convert character to lower-case */ 00112 #define char_tolower(ch) do { if (char_isupper(ch)) ch += 32; } while(0) 00113 00114 /*! @brief convert character to upper-case */ 00115 #define char_toupper(ch) do { if (char_islower(ch)) ch -= 32; } while(0) 00116 00117 #endif 00118 00119 /*! @} char */