Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / nsgmls / UnivCharsetDesc.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: UnivCharsetDesc.h /main/1 1996/07/29 17:07:49 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef UnivCharsetDesc_INCLUDED
28 #define UnivCharsetDesc_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include <stddef.h>
34 #include "types.h"
35 #include "RangeMap.h"
36 #include "Boolean.h"
37 #include "ISet.h"
38
39 #ifdef SP_NAMESPACE
40 namespace SP_NAMESPACE {
41 #endif
42
43 #ifndef SP_API
44 #define SP_API
45 #endif
46
47 class SP_API UnivCharsetDesc {
48 public:
49   struct SP_API Range {
50     WideChar descMin;
51     // Note that this is a count, as in the SGML declaration,
52     // rather than a maximum.
53     unsigned long count;
54     UnivChar univMin;
55   };
56   enum {
57     zero = 48,
58     A = 65,
59     a = 97,
60     tab = 9,
61     rs = 10,
62     re = 13,
63     space = 32,
64     exclamation = 33,
65     lessThan = 60,
66     greaterThan = 62
67     };
68   UnivCharsetDesc();
69   UnivCharsetDesc(const Range *, size_t);
70   void set(const Range *, size_t);
71   Boolean descToUniv(WideChar from, UnivChar &to) const;
72   Boolean descToUniv(WideChar from, UnivChar &to, WideChar &alsoMax) const;
73   // Return 0 for no matches, 1 for 1, 2 for more than 1
74   unsigned univToDesc(UnivChar from, WideChar &to, ISet<WideChar> &toSet)
75        const;
76   unsigned univToDesc(UnivChar from, WideChar &to, ISet<WideChar> &toSet,
77                       WideChar &count)
78        const;
79   void addRange(WideChar descMin, WideChar descMax, UnivChar univMin);
80   void addBaseRange(const UnivCharsetDesc &baseSet,
81                     WideChar descMin,
82                     WideChar descMax,
83                     WideChar baseMin,
84                     ISet<WideChar> &baseMissing);
85   WideChar maxDesc() const;
86 private:
87   RangeMap<WideChar,UnivChar> descToUniv_;
88   friend class UnivCharsetDescIter;
89 };
90
91 class SP_API UnivCharsetDescIter {
92 public:
93   UnivCharsetDescIter(const UnivCharsetDesc &);
94   Boolean next(WideChar &descMin, WideChar &descMax, UnivChar &univMin);
95 private:
96   RangeMapIter<WideChar,UnivChar> iter_;
97 };
98
99 inline
100 Boolean UnivCharsetDesc::descToUniv(WideChar from, UnivChar &to) const
101 {
102   WideChar tem;
103   return descToUniv_.map(from, to, tem);
104 }
105
106 inline
107 Boolean UnivCharsetDesc::descToUniv(WideChar from, UnivChar &to,
108                                     WideChar &alsoMax) const
109 {
110   return descToUniv_.map(from, to, alsoMax);
111 }
112
113 inline
114 unsigned UnivCharsetDesc::univToDesc(UnivChar from, WideChar &to,
115                                      ISet<WideChar> &toSet) const
116 {
117   WideChar tem;
118   return descToUniv_.inverseMap(from, to, toSet, tem);
119 }
120
121 inline
122 unsigned UnivCharsetDesc::univToDesc(UnivChar from, WideChar &to,
123                                      ISet<WideChar> &toSet,
124                                      WideChar &count) const
125 {
126   return descToUniv_.inverseMap(from, to, toSet, count);
127 }
128
129 inline
130 void UnivCharsetDesc::addRange(WideChar descMin,
131                                WideChar descMax,
132                                UnivChar univMin)
133 {
134   descToUniv_.addRange(descMin, descMax, univMin);
135 }
136
137 inline
138 UnivCharsetDescIter::UnivCharsetDescIter(const UnivCharsetDesc &desc)
139 : iter_(desc.descToUniv_)
140 {
141 }
142
143 inline
144 Boolean UnivCharsetDescIter::next(WideChar &descMin,
145                                   WideChar &descMax,
146                                   UnivChar &univMin)
147 {
148   return iter_.next(descMin, descMax, univMin);
149 }
150
151 #ifdef SP_NAMESPACE
152 }
153 #endif
154
155 #endif /* not UnivCharsetDesc_INCLUDED */