Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / nsgmls / CharsetDecl.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: CharsetDecl.h /main/1 1996/07/29 16:47:13 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef CharsetDecl_INCLUDED
28 #define CharsetDecl_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "types.h"
34 #include "Vector.h"
35 #include "ExternalId.h"
36 #include "ISet.h"
37 #include "Boolean.h"
38
39 #ifdef SP_NAMESPACE
40 namespace SP_NAMESPACE {
41 #endif
42
43 class SP_API CharsetDeclRange {
44 public:
45   enum Type {
46     number,
47     string,
48     unused
49     };
50   CharsetDeclRange();
51   CharsetDeclRange(WideChar, Number, WideChar);
52   CharsetDeclRange(WideChar, Number);
53   CharsetDeclRange(WideChar, Number, const StringC &);
54   void rangeDeclared(WideChar min, Number count,
55                      ISet<WideChar> &declared) const;
56   void usedSet(ISet<Char> &) const;
57   Boolean getCharInfo(WideChar fromChar,
58                       CharsetDeclRange::Type &type,
59                       Number &n,
60                       StringC &str,
61                       Number &count) const;
62   void stringToChar(const StringC &str, ISet<WideChar> &to) const;
63   void numberToChar(Number n, ISet<WideChar> &to, Number &count) const;
64 private:
65   WideChar descMin_;
66   Number count_;
67   WideChar baseMin_;
68   Type type_;
69   StringC str_;
70 };
71
72 class SP_API CharsetDeclSection {
73 public:
74   CharsetDeclSection();
75   void setPublicId(const PublicId &);
76   void addRange(const CharsetDeclRange &);
77   void rangeDeclared(WideChar min, Number count,
78                      ISet<WideChar> &declared) const;
79   void usedSet(ISet<Char> &) const;
80   Boolean getCharInfo(WideChar fromChar,
81                       const PublicId *&id,
82                       CharsetDeclRange::Type &type,
83                       Number &n,
84                       StringC &str,
85                       Number &cout) const;
86   void stringToChar(const StringC &str, ISet<WideChar> &to) const;
87   void numberToChar(const PublicId *id, Number n,
88                     ISet<WideChar> &to, Number &count) const;
89 private:
90   PublicId baseset_;
91   Vector<CharsetDeclRange> ranges_;
92 };
93
94 class SP_API CharsetDecl {
95 public:
96   CharsetDecl();
97   void addSection(const PublicId &);
98   void swap(CharsetDecl &);
99   void clear();
100   void usedSet(ISet<Char> &) const;
101   void declaredSet(ISet<WideChar> &set) const;
102   Boolean charDeclared(WideChar) const;
103   void rangeDeclared(WideChar min, Number count,
104                      ISet<WideChar> &declared) const;
105   void addRange(WideChar, Number, WideChar);
106   void addRange(WideChar, Number);
107   void addRange(WideChar, Number, const StringC &);
108   Boolean getCharInfo(WideChar fromChar,
109                       const PublicId *&id,
110                       CharsetDeclRange::Type &type,
111                       Number &n,
112                       StringC &str) const;
113   Boolean getCharInfo(WideChar fromChar,
114                       const PublicId *&id,
115                       CharsetDeclRange::Type &type,
116                       Number &n,
117                       StringC &str,
118                       Number &count) const;
119   void stringToChar(const StringC &str, ISet<WideChar> &to) const;
120   void numberToChar(const PublicId *id, Number n,
121                     ISet<WideChar> &to, Number &count) const;
122   void numberToChar(const PublicId *id, Number n, ISet<WideChar> &to) const;
123 private:
124   Vector<CharsetDeclSection> sections_;
125   ISet<WideChar> declaredSet_;
126 };
127
128 inline
129 Boolean CharsetDecl::getCharInfo(WideChar fromChar,
130                                  const PublicId *&id,
131                                  CharsetDeclRange::Type &type,
132                                  Number &n,
133                                  StringC &str) const
134 {
135   Number tem;
136   return getCharInfo(fromChar, id, type, n, str, tem);
137 }
138
139 inline
140 void CharsetDecl::numberToChar(const PublicId *id, Number n,
141                                ISet<WideChar> &to) const
142 {
143   Number tem;
144   numberToChar(id, n, to, tem);
145 }
146
147 inline
148 void CharsetDecl::declaredSet(ISet<WideChar> &set) const
149 {
150   set = declaredSet_;
151 }
152
153 inline
154 Boolean CharsetDecl::charDeclared(WideChar c) const
155 {
156   return declaredSet_.contains(c);
157 }
158
159 #ifdef SP_NAMESPACE
160 }
161 #endif
162
163 #endif /* not CharsetDecl_INCLUDED */