1 /* $NetBSD: cset.cpp,v 1.1.1.1 2016/01/13 18:41:48 christos Exp $ */ 2 3 // -*- C++ -*- 4 /* Copyright (C) 1989, 1990, 1991, 1992, 2004 Free Software Foundation, Inc. 5 Written by James Clark (jjc@jclark.com) 6 7 This file is part of groff. 8 9 groff is free software; you can redistribute it and/or modify it under 10 the terms of the GNU General Public License as published by the Free 11 Software Foundation; either version 2, or (at your option) any later 12 version. 13 14 groff is distributed in the hope that it will be useful, but WITHOUT ANY 15 WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 for more details. 18 19 You should have received a copy of the GNU General Public License along 20 with groff; see the file COPYING. If not, write to the Free Software 21 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23 #include <ctype.h> 24 25 #include "lib.h" 26 #include "cset.h" 27 28 cset csalpha(CSET_BUILTIN); 29 cset csupper(CSET_BUILTIN); 30 cset cslower(CSET_BUILTIN); 31 cset csdigit(CSET_BUILTIN); 32 cset csxdigit(CSET_BUILTIN); 33 cset csspace(CSET_BUILTIN); 34 cset cspunct(CSET_BUILTIN); 35 cset csalnum(CSET_BUILTIN); 36 cset csprint(CSET_BUILTIN); 37 cset csgraph(CSET_BUILTIN); 38 cset cscntrl(CSET_BUILTIN); 39 40 #ifdef isascii 41 #define ISASCII(c) isascii(c) 42 #else 43 #define ISASCII(c) (1) 44 #endif 45 46 void cset::clear() 47 { 48 char *p = v; 49 for (int i = 0; i <= UCHAR_MAX; i++) 50 p[i] = 0; 51 } 52 53 cset::cset() 54 { 55 clear(); 56 } 57 58 cset::cset(const char *s) 59 { 60 clear(); 61 while (*s) 62 v[(unsigned char)*s++] = 1; 63 } 64 65 cset::cset(const unsigned char *s) 66 { 67 clear(); 68 while (*s) 69 v[*s++] = 1; 70 } 71 72 cset::cset(cset_builtin) 73 { 74 // these are initialised by cset_init::cset_init() 75 } 76 77 cset &cset::operator|=(const cset &cs) 78 { 79 for (int i = 0; i <= UCHAR_MAX; i++) 80 if (cs.v[i]) 81 v[i] = 1; 82 return *this; 83 } 84 85 86 int cset_init::initialised = 0; 87 88 cset_init::cset_init() 89 { 90 if (initialised) 91 return; 92 initialised = 1; 93 for (int i = 0; i <= UCHAR_MAX; i++) { 94 csalpha.v[i] = ISASCII(i) && isalpha(i); 95 csupper.v[i] = ISASCII(i) && isupper(i); 96 cslower.v[i] = ISASCII(i) && islower(i); 97 csdigit.v[i] = ISASCII(i) && isdigit(i); 98 csxdigit.v[i] = ISASCII(i) && isxdigit(i); 99 csspace.v[i] = ISASCII(i) && isspace(i); 100 cspunct.v[i] = ISASCII(i) && ispunct(i); 101 csalnum.v[i] = ISASCII(i) && isalnum(i); 102 csprint.v[i] = ISASCII(i) && isprint(i); 103 csgraph.v[i] = ISASCII(i) && isgraph(i); 104 cscntrl.v[i] = ISASCII(i) && iscntrl(i); 105 } 106 } 107