Imported Upstream version 1.22.4
[platform/upstream/groff.git] / src / include / cset.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989-2018 Free Software Foundation, Inc.
3      Written by James Clark (jjc@jclark.com)
4
5 This file is part of groff.
6
7 groff 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 3 of the License, or
10 (at your option) any later version.
11
12 groff 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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifdef HAVE_CC_LIMITS_H
21 #include <limits.h>
22 #else /* not HAVE_CC_LIMITS_H */
23 #ifndef UCHAR_MAX
24 #define UCHAR_MAX 255
25 #endif
26 #endif /* not HAVE_CC_LIMITS_H */ 
27
28 enum cset_builtin { CSET_BUILTIN };
29
30 class cset {
31 public:
32   cset();
33   cset(cset_builtin);
34   cset(const char *);
35   cset(const unsigned char *);
36   int operator()(unsigned char) const;
37
38   cset &operator|=(const cset &);
39   cset &operator|=(unsigned char);
40
41   friend class cset_init;
42 private:
43   char v[UCHAR_MAX+1];
44   void clear();
45 };
46
47 inline int cset::operator()(unsigned char c) const
48 {
49   return v[c];
50 }
51
52 inline cset &cset::operator|=(unsigned char c)
53 {
54   v[c] = 1;
55   return *this;
56 }
57
58 extern cset csalpha;
59 extern cset csupper;
60 extern cset cslower;
61 extern cset csdigit;
62 extern cset csxdigit;
63 extern cset csspace;
64 extern cset cspunct;
65 extern cset csalnum;
66 extern cset csprint;
67 extern cset csgraph;
68 extern cset cscntrl;
69
70 static class cset_init {
71   static int initialised;
72 public:
73   cset_init();
74 } _cset_init;