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