File: CharsetDecl.cxx

package info (click to toggle)
sgml-tools 1.0.9-15
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,464 kB
  • ctags: 11,469
  • sloc: cpp: 59,330; ansic: 24,525; perl: 3,140; sh: 971; makefile: 845; lex: 561; lisp: 309; awk: 142; sed: 5
file content (265 lines) | stat: -rwxr-xr-x 6,355 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
// Copyright (c) 1994 James Clark
// See the file COPYING for copying permission.

#ifdef __GNUG__
#pragma implementation
#endif
#include "splib.h"
#include "CharsetDecl.h"
#include "macros.h"
#include "ISet.h"
#include "constant.h"

#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif

CharsetDeclRange::CharsetDeclRange()
{
}

CharsetDeclRange::CharsetDeclRange(WideChar descMin, Number count,
				   WideChar baseMin)
: descMin_(descMin),
  count_(count),
  type_(number),
  baseMin_(baseMin)
{
}

CharsetDeclRange::CharsetDeclRange(WideChar descMin, Number count)
: descMin_(descMin),
  count_(count),
  type_(unused)
     
{
}

CharsetDeclRange::CharsetDeclRange(WideChar descMin, Number count,
				   const StringC &str)
: descMin_(descMin),
  count_(count),
  type_(string),
  str_(str)
{
}

void CharsetDeclRange::rangeDeclared(WideChar min, Number count,
				     ISet<WideChar> &declared) const
{
  if (count > 0 && min + count > descMin_ && min < descMin_ + count_) {
    WideChar commMin = (descMin_ > min) ? descMin_ : min;
    WideChar commMax = min + ((min + count < descMin_ + count_
			       ? count
			       : descMin_ + count_ - min) - 1);
    ASSERT(commMin <= commMax);
    declared.addRange(commMin, commMax);
  }
}

void CharsetDeclRange::usedSet(ISet<Char> &set) const
{
  if (type_ != unused && count_ > 0 && descMin_ <= charMax) {
    Char max;
    if (charMax - descMin_ < count_ - 1)
      max = charMax;
    else
      max = Char(descMin_ + (count_ - 1));
    set.addRange(Char(descMin_), max);
  }
}

void CharsetDeclRange::stringToChar(const StringC &str, ISet<WideChar> &to)
     const
{
  if (type_ == string && str_ == str && count_ > 0)
    to.addRange(descMin_, descMin_ + (count_ - 1));
}

void CharsetDeclRange::numberToChar(Number n, ISet<WideChar> &to,
				    Number &count)
     const
{
  if (type_ == number && n >= baseMin_ && n - baseMin_ < count_) {
    Number thisCount = count_ - (n - baseMin_);
    if (to.isEmpty() || thisCount < count)
      count = thisCount;
    to.add(descMin_ + (n - baseMin_));
  }
}

Boolean CharsetDeclRange::getCharInfo(WideChar fromChar,
				      CharsetDeclRange::Type &type,
				      Number &n,
				      StringC &str,
				      Number &count) const
{
  if (fromChar >= descMin_ && fromChar - descMin_ < count_) {
    type = type_;
    if (type == number)
      n = baseMin_ + (fromChar - descMin_);
    else if (type == string)
      str = str_;
    count = count_ - (fromChar - descMin_);
    return 1;
  }
  else
    return 0;
}

CharsetDeclSection::CharsetDeclSection()
{
}

void CharsetDeclSection::setPublicId(const PublicId &id)
{
  baseset_ = id;
}

void CharsetDeclSection::addRange(const CharsetDeclRange &range)
{
  ranges_.push_back(range);
}

void CharsetDeclSection::rangeDeclared(WideChar min, Number count,
				       ISet<WideChar> &declared) const
{
  for (size_t i = 0; i < ranges_.size(); i++)
    ranges_[i].rangeDeclared(min, count, declared);
}

void CharsetDeclSection::usedSet(ISet<Char> &set) const
{
  for (size_t i = 0; i < ranges_.size(); i++)
    ranges_[i].usedSet(set);
}

void CharsetDeclSection::stringToChar(const StringC &str, ISet<WideChar> &to)
     const
{
  for (size_t i = 0; i < ranges_.size(); i++)
    ranges_[i].stringToChar(str, to);
}

void CharsetDeclSection::numberToChar(const PublicId *id, Number n,
				      ISet<WideChar> &to, Number &count) const
{
  PublicId::OwnerType ownerType;
  StringC seq1, seq2;
  if (id->string() == baseset_.string()
      // Assume that 2 ISO character sets are the same if
      // their designating sequences are the same.
      || (id->getOwnerType(ownerType)
	  && ownerType == PublicId::ISO
	  && baseset_.getOwnerType(ownerType)
	  && ownerType == PublicId::ISO
	  && id->getDesignatingSequence(seq1)
	  && baseset_.getDesignatingSequence(seq2)
	  && seq1 == seq2)) {
    for (size_t i = 0; i < ranges_.size(); i++)
      ranges_[i].numberToChar(n, to, count);
  }
}

Boolean CharsetDeclSection::getCharInfo(WideChar fromChar,
					const PublicId *&id,
					CharsetDeclRange::Type &type,
					Number &n,
					StringC &str,
					Number &count) const
{
  for (size_t i = 0; i < ranges_.size(); i++)
    if (ranges_[i].getCharInfo(fromChar, type, n, str, count)) {
      id = &baseset_;
      return 1;
    }
  return 0;
}

CharsetDecl::CharsetDecl()
{
}

void CharsetDecl::addSection(const PublicId &id)
{
  sections_.resize(sections_.size() + 1);
  sections_.back().setPublicId(id);
}

void CharsetDecl::swap(CharsetDecl &to)
{
  sections_.swap(to.sections_);
  declaredSet_.swap(to.declaredSet_);
}

void CharsetDecl::clear()
{
  sections_.clear();
}

void CharsetDecl::addRange(WideChar min, Number count, WideChar baseMin)
{
  if (count > 0)
    declaredSet_.addRange(min, min + (count - 1));
  CharsetDeclRange range(min, count, baseMin);
  sections_.back().addRange(range);
}

void CharsetDecl::addRange(WideChar min, Number count)
{
  if (count > 0)
    declaredSet_.addRange(min, min + (count - 1));
  CharsetDeclRange range(min, count);
  sections_.back().addRange(range);
}

void CharsetDecl::addRange(WideChar min, Number count, const StringC &str)
{
  if (count > 0)
    declaredSet_.addRange(min, min + (count - 1));
  CharsetDeclRange range(min, count, str);
  sections_.back().addRange(range);
}

void CharsetDecl::rangeDeclared(WideChar min, Number count,
				ISet<WideChar> &declared) const
{
  for (size_t i = 0; i < sections_.size(); i++)
    sections_[i].rangeDeclared(min, count, declared);
}

void CharsetDecl::usedSet(ISet<Char> &set) const
{
  for (size_t i = 0; i < sections_.size(); i++)
    sections_[i].usedSet(set);
}

Boolean CharsetDecl::getCharInfo(WideChar fromChar,
				 const PublicId *&id,
				 CharsetDeclRange::Type &type,
				 Number &n,
				 StringC &str,
				 Number &count) const
{
  for (size_t i = 0; i < sections_.size(); i++)
    if (sections_[i].getCharInfo(fromChar, id, type, n, str, count))
      return 1;
  return 0;
}

void CharsetDecl::stringToChar(const StringC &str, ISet<WideChar> &to) const
{
  for (size_t i = 0; i < sections_.size(); i++)
    sections_[i].stringToChar(str, to);
}

void CharsetDecl::numberToChar(const PublicId *id, Number n,
			       ISet<WideChar> &to, Number &count) const
{
  for (size_t i = 0; i < sections_.size(); i++)
    sections_[i].numberToChar(id, n, to, count);
}

#ifdef SP_NAMESPACE
}
#endif