Line data Source code
1 : /* Copyright 1989-2020 Free Software Foundation, Inc. 2 : Written by James Clark (jjc@jclark.com) 3 : 4 : This file is part of groff, the GNU roff typesetting system. 5 : 6 : groff is free software; you can redistribute it and/or modify it under 7 : the terms of the GNU General Public License as published by the Free 8 : Software Foundation, either version 3 of the License, or 9 : (at your option) any later version. 10 : 11 : groff is distributed in the hope that it will be useful, but WITHOUT ANY 12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 : for more details. 15 : 16 : You should have received a copy of the GNU General Public License 17 : along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 : 19 : #ifdef HAVE_CONFIG_H 20 : #include <config.h> 21 : #endif 22 : 23 : #include <ctype.h> 24 : 25 : #include "lib.h" 26 : 27 : #include "cset.h" 28 : 29 : cset csalpha(CSET_BUILTIN); 30 : cset csupper(CSET_BUILTIN); 31 : cset cslower(CSET_BUILTIN); 32 : cset csdigit(CSET_BUILTIN); 33 : cset csxdigit(CSET_BUILTIN); 34 : cset csspace(CSET_BUILTIN); 35 : cset cspunct(CSET_BUILTIN); 36 : cset csalnum(CSET_BUILTIN); 37 : cset csprint(CSET_BUILTIN); 38 : cset csgraph(CSET_BUILTIN); 39 : cset cscntrl(CSET_BUILTIN); 40 : 41 : #ifdef isascii 42 : #define ISASCII(c) isascii(c) 43 : #else 44 : #define ISASCII(c) (1) 45 : #endif 46 : 47 1480 : void cset::clear() 48 : { 49 1480 : char *p = v; 50 380360 : for (int i = 0; i <= UCHAR_MAX; i++) 51 378880 : p[i] = 0; 52 1480 : } 53 : 54 0 : cset::cset() 55 : { 56 0 : clear(); 57 0 : } 58 : 59 1480 : cset::cset(const char *s) 60 : { 61 1480 : clear(); 62 7460 : while (*s) 63 5980 : v[(unsigned char)*s++] = 1; 64 1480 : } 65 : 66 0 : cset::cset(const unsigned char *s) 67 : { 68 0 : clear(); 69 0 : while (*s) 70 0 : v[*s++] = 1; 71 0 : } 72 : 73 47674 : cset::cset(cset_builtin) 74 : { 75 : // these are initialised by cset_init::cset_init() 76 47674 : } 77 : 78 0 : cset &cset::operator|=(const cset &cs) 79 : { 80 0 : for (int i = 0; i <= UCHAR_MAX; i++) 81 0 : if (cs.v[i]) 82 0 : v[i] = 1; 83 0 : return *this; 84 : } 85 : 86 : 87 : int cset_init::initialised = 0; 88 : 89 39679 : cset_init::cset_init() 90 : { 91 39679 : if (initialised) 92 35345 : return; 93 4334 : initialised = 1; 94 1113838 : for (int i = 0; i <= UCHAR_MAX; i++) { 95 1109504 : csalpha.v[i] = ISASCII(i) && isalpha(i); 96 1109504 : csupper.v[i] = ISASCII(i) && isupper(i); 97 1109504 : cslower.v[i] = ISASCII(i) && islower(i); 98 1109504 : csdigit.v[i] = ISASCII(i) && isdigit(i); 99 1109504 : csxdigit.v[i] = ISASCII(i) && isxdigit(i); 100 1109504 : csspace.v[i] = ISASCII(i) && isspace(i); 101 1109504 : cspunct.v[i] = ISASCII(i) && ispunct(i); 102 1109504 : csalnum.v[i] = ISASCII(i) && isalnum(i); 103 1109504 : csprint.v[i] = ISASCII(i) && isprint(i); 104 1109504 : csgraph.v[i] = ISASCII(i) && isgraph(i); 105 1109504 : cscntrl.v[i] = ISASCII(i) && iscntrl(i); 106 : } 107 : } 108 : 109 : // Local Variables: 110 : // fill-column: 72 111 : // mode: C++ 112 : // End: 113 : // vim: set cindent noexpandtab shiftwidth=2 textwidth=72: