1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
4
5 #ifndef CharsetDecl_INCLUDED
6 #define CharsetDecl_INCLUDED 1
7 #ifdef __GNUG__
8 #pragma interface
9 #endif
10
11 #include "types.h"
12 #include "Vector.h"
13 #include "ExternalId.h"
14 #include "ISet.h"
15 #include "Boolean.h"
16
17 #ifdef SP_NAMESPACE
18 namespace SP_NAMESPACE {
19 #endif
20
21 class SP_API CharsetDeclRange {
22 public:
23 enum Type {
24 number,
25 string,
26 unused
27 };
28 CharsetDeclRange();
29 CharsetDeclRange(WideChar, Number, WideChar);
30 CharsetDeclRange(WideChar, Number);
31 CharsetDeclRange(WideChar, Number, const StringC &);
32 void rangeDeclared(WideChar min, Number count,
33 ISet<WideChar> &declared) const;
34 void usedSet(ISet<Char> &) const;
35 Boolean getCharInfo(WideChar fromChar,
36 CharsetDeclRange::Type &type,
37 Number &n,
38 StringC &str,
39 Number &count) const;
40 void stringToChar(const StringC &str, ISet<WideChar> &to) const;
41 void numberToChar(Number n, ISet<WideChar> &to, Number &count) const;
42 private:
43 WideChar descMin_;
44 Number count_;
45 WideChar baseMin_;
46 Type type_;
47 StringC str_;
48 };
49
50 class SP_API CharsetDeclSection {
51 public:
52 CharsetDeclSection();
53 void setPublicId(const PublicId &);
54 void addRange(const CharsetDeclRange &);
55 void rangeDeclared(WideChar min, Number count,
56 ISet<WideChar> &declared) const;
57 void usedSet(ISet<Char> &) const;
58 Boolean getCharInfo(WideChar fromChar,
59 const PublicId *&id,
60 CharsetDeclRange::Type &type,
61 Number &n,
62 StringC &str,
63 Number &cout) const;
64 void stringToChar(const StringC &str, ISet<WideChar> &to) const;
65 void numberToChar(const PublicId *id, Number n,
66 ISet<WideChar> &to, Number &count) const;
67 private:
68 PublicId baseset_;
69 Vector<CharsetDeclRange> ranges_;
70 };
71
72 class SP_API CharsetDecl {
73 public:
74 CharsetDecl();
75 void addSection(const PublicId &);
76 void swap(CharsetDecl &);
77 void clear();
78 void usedSet(ISet<Char> &) const;
79 void declaredSet(ISet<WideChar> &set) const;
80 Boolean charDeclared(WideChar) const;
81 void rangeDeclared(WideChar min, Number count,
82 ISet<WideChar> &declared) const;
83 void addRange(WideChar, Number, WideChar);
84 void addRange(WideChar, Number);
85 void addRange(WideChar, Number, const StringC &);
86 Boolean getCharInfo(WideChar fromChar,
87 const PublicId *&id,
88 CharsetDeclRange::Type &type,
89 Number &n,
90 StringC &str) const;
91 Boolean getCharInfo(WideChar fromChar,
92 const PublicId *&id,
93 CharsetDeclRange::Type &type,
94 Number &n,
95 StringC &str,
96 Number &count) const;
97 void stringToChar(const StringC &str, ISet<WideChar> &to) const;
98 void numberToChar(const PublicId *id, Number n,
99 ISet<WideChar> &to, Number &count) const;
100 void numberToChar(const PublicId *id, Number n, ISet<WideChar> &to) const;
101 private:
102 Vector<CharsetDeclSection> sections_;
103 ISet<WideChar> declaredSet_;
104 };
105
106 inline
getCharInfo(WideChar fromChar,const PublicId * & id,CharsetDeclRange::Type & type,Number & n,StringC & str)107 Boolean CharsetDecl::getCharInfo(WideChar fromChar,
108 const PublicId *&id,
109 CharsetDeclRange::Type &type,
110 Number &n,
111 StringC &str) const
112 {
113 Number tem;
114 return getCharInfo(fromChar, id, type, n, str, tem);
115 }
116
117 inline
numberToChar(const PublicId * id,Number n,ISet<WideChar> & to)118 void CharsetDecl::numberToChar(const PublicId *id, Number n,
119 ISet<WideChar> &to) const
120 {
121 Number tem;
122 numberToChar(id, n, to, tem);
123 }
124
125 inline
declaredSet(ISet<WideChar> & set)126 void CharsetDecl::declaredSet(ISet<WideChar> &set) const
127 {
128 set = declaredSet_;
129 }
130
131 inline
charDeclared(WideChar c)132 Boolean CharsetDecl::charDeclared(WideChar c) const
133 {
134 return declaredSet_.contains(c);
135 }
136
137 #ifdef SP_NAMESPACE
138 }
139 #endif
140
141 #endif /* not CharsetDecl_INCLUDED */
142