1 /* GNU Mailutils -- a suite of utilities for electronic mail 2 Copyright (C) 2009-2021 Free Software Foundation, Inc. 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 3 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General 15 Public License along with this library. If not, see 16 <http://www.gnu.org/licenses/>. */ 17 18 /* Ctype functions for ASCII character set */ 19 20 #ifndef _MAILUTILS_MUCTYPE_H 21 #define _MAILUTILS_MUCTYPE_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define MU_CTYPE_ALPHA 0x00001 28 #define MU_CTYPE_DIGIT 0x00002 29 #define MU_CTYPE_BLANK 0x00004 30 #define MU_CTYPE_CNTRL 0x00008 31 #define MU_CTYPE_GRAPH 0x00010 32 #define MU_CTYPE_LOWER 0x00020 33 #define MU_CTYPE_UPPER 0x00040 34 #define MU_CTYPE_PRINT 0x00080 35 #define MU_CTYPE_PUNCT 0x00100 36 #define MU_CTYPE_SPACE 0x00200 37 #define MU_CTYPE_XLETR 0x00400 38 #define MU_CTYPE_ENDLN 0x00800 39 #define MU_CTYPE_TSPEC 0x01000 /* tspecials: RFC 2045, section 5.1. */ 40 #define MU_CTYPE_IDENT 0x02000 /* Valid identifier consituent: alnum or _ */ 41 #define MU_CTYPE_HEADR 0x04000 /* Valid header name consituent: alnum, _, 42 or - */ 43 #define MU_CTYPE_IMSPC 0x08000 /* Internet Message Format Specials: 44 RFC2822, 3.2.1 */ 45 #define MU_CTYPE_NWCTL 0x10000 /* Internet Message NO-WS-CTL: 46 RFC2822, 3.2.1 */ 47 #define MU_CTYPE_IMATM 0x20000 /* Internet Message atom constituent */ 48 49 #define MU_C_TAB_MAX 128 50 51 extern int mu_c_tab[MU_C_TAB_MAX]; 52 53 #define mu_c_is_class(c, class) \ 54 (((unsigned)(c)) < 128 && mu_c_tab[(unsigned)(c)] & (class)) 55 56 #define mu_isalpha(c) mu_c_is_class (c, MU_CTYPE_ALPHA) 57 #define mu_iscntrl(c) mu_c_is_class (c, MU_CTYPE_CNTRL) 58 #define mu_isdigit(c) mu_c_is_class (c, MU_CTYPE_DIGIT) 59 #define mu_isgraph(c) mu_c_is_class (c, MU_CTYPE_GRAPH) 60 #define mu_islower(c) mu_c_is_class (c, MU_CTYPE_LOWER) 61 #define mu_isprint(c) mu_c_is_class (c, MU_CTYPE_PRINT) 62 #define mu_ispunct(c) mu_c_is_class (c, MU_CTYPE_PUNCT) 63 #define mu_isspace(c) mu_c_is_class (c, MU_CTYPE_SPACE) 64 #define mu_isupper(c) mu_c_is_class (c, MU_CTYPE_UPPER) 65 #define mu_isxdigit(c) mu_c_is_class (c, MU_CTYPE_DIGIT|MU_CTYPE_XLETR) 66 #define mu_isalnum(c) mu_c_is_class (c, MU_CTYPE_ALPHA|MU_CTYPE_DIGIT) 67 #define mu_isascii(c) (((unsigned)c) < MU_C_TAB_MAX) 68 #define mu_isblank(c) mu_c_is_class (c, MU_CTYPE_BLANK) 69 #define mu_isendln(c) mu_c_is_class (c, MU_CTYPE_ENDLN) 70 #define mu_istspec(c) mu_c_is_class (c, MU_CTYPE_TSPEC) 71 #define mu_isident(c) mu_c_is_class (c, MU_CTYPE_IDENT) 72 #define mu_isheadr(c) mu_c_is_class (c, MU_CTYPE_HEADR) 73 #define mu_isimspc(c) mu_c_is_class (c, MU_CTYPE_IMSPC) 74 #define mu_isnwctl(c) mu_c_is_class (c, MU_CTYPE_NWCTL) 75 #define mu_isimatm(c) mu_c_is_class (c, MU_CTYPE_IMATM) 76 77 #define mu_tolower(c) \ 78 ({ int __c = (c); \ 79 (__c >= 'A' && __c <= 'Z' ? __c - 'A' + 'a' : __c); \ 80 }) 81 82 #define mu_toupper(c) \ 83 ({ int __c = (c); \ 84 (__c >= 'a' && __c <= 'z' ? __c - 'a' + 'A' : __c); \ 85 }) 86 87 #ifdef __cplusplus 88 } 89 #endif 90 91 #endif 92