Sync-to-go: update copyright for 2015
[s-roff.git] / src / lib-roff / cset.cpp
blobd9deb1efba36aa5e912b5686b17c2cf71f663e93
1 /*@
2 * Copyright (c) 2014 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
4 * Copyright (C) 1989 - 1992, 2004 Free Software Foundation, Inc.
5 * Written by James Clark (jjc@jclark.com)
7 * This is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2, or (at your option) any later
10 * version.
12 * This is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with groff; see the file COPYING. If not, write to the Free Software
19 * Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "config.h"
23 #include "lib.h"
25 #include <ctype.h>
27 #include "cset.h"
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);
41 #ifdef isascii /* FIXME lib.h? */
42 #define ISASCII(c) isascii(c)
43 #else
44 #define ISASCII(c) (1)
45 #endif
47 void cset::clear()
49 char *p = v;
50 for (int i = 0; i <= UCHAR_MAX; i++)
51 p[i] = 0;
54 cset::cset()
56 clear();
59 cset::cset(const char *s)
61 clear();
62 while (*s)
63 v[(unsigned char)*s++] = 1;
66 cset::cset(const unsigned char *s)
68 clear();
69 while (*s)
70 v[*s++] = 1;
73 cset::cset(cset_builtin)
75 // these are initialised by cset_init::cset_init()
78 cset &cset::operator|=(const cset &cs)
80 for (int i = 0; i <= UCHAR_MAX; i++)
81 if (cs.v[i])
82 v[i] = 1;
83 return *this;
87 int cset_init::initialised = 0;
89 cset_init::cset_init()
91 if (initialised)
92 return;
93 initialised = 1;
94 for (int i = 0; i <= UCHAR_MAX; i++) {
95 csalpha.v[i] = ISASCII(i) && isalpha(i);
96 csupper.v[i] = ISASCII(i) && isupper(i);
97 cslower.v[i] = ISASCII(i) && islower(i);
98 csdigit.v[i] = ISASCII(i) && isdigit(i);
99 csxdigit.v[i] = ISASCII(i) && isxdigit(i);
100 csspace.v[i] = ISASCII(i) && isspace(i);
101 cspunct.v[i] = ISASCII(i) && ispunct(i);
102 csalnum.v[i] = ISASCII(i) && isalnum(i);
103 csprint.v[i] = ISASCII(i) && isprint(i);
104 csgraph.v[i] = ISASCII(i) && isgraph(i);
105 cscntrl.v[i] = ISASCII(i) && iscntrl(i);
109 // s-it2-mode