2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: CharsetDecl.C /main/1 1996/07/29 16:47:07 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
31 #include "CharsetDecl.h"
37 namespace SP_NAMESPACE {
40 CharsetDeclRange::CharsetDeclRange()
48 CharsetDeclRange::CharsetDeclRange(WideChar descMin, Number count,
57 CharsetDeclRange::CharsetDeclRange(WideChar descMin, Number count)
65 CharsetDeclRange::CharsetDeclRange(WideChar descMin, Number count,
75 void CharsetDeclRange::rangeDeclared(WideChar min, Number count,
76 ISet<WideChar> &declared) const
78 if (count > 0 && min + count > descMin_ && min < descMin_ + count_) {
79 WideChar commMin = (descMin_ > min) ? descMin_ : min;
80 WideChar commMax = min + ((min + count < descMin_ + count_
82 : descMin_ + count_ - min) - 1);
83 ASSERT(commMin <= commMax);
84 declared.addRange(commMin, commMax);
88 void CharsetDeclRange::usedSet(ISet<Char> &set) const
90 if (type_ != unused && count_ > 0 && descMin_ <= charMax) {
92 if (charMax - descMin_ < count_ - 1)
95 max = Char(descMin_ + (count_ - 1));
96 set.addRange(Char(descMin_), max);
100 void CharsetDeclRange::stringToChar(const StringC &str, ISet<WideChar> &to)
103 if (type_ == string && str_ == str && count_ > 0)
104 to.addRange(descMin_, descMin_ + (count_ - 1));
107 void CharsetDeclRange::numberToChar(Number n, ISet<WideChar> &to,
111 if (type_ == number && n >= baseMin_ && n - baseMin_ < count_) {
112 Number thisCount = count_ - (n - baseMin_);
113 if (to.isEmpty() || thisCount < count)
115 to.add(descMin_ + (n - baseMin_));
119 Boolean CharsetDeclRange::getCharInfo(WideChar fromChar,
120 CharsetDeclRange::Type &type,
125 if (fromChar >= descMin_ && fromChar - descMin_ < count_) {
128 n = baseMin_ + (fromChar - descMin_);
129 else if (type == string)
131 count = count_ - (fromChar - descMin_);
138 CharsetDeclSection::CharsetDeclSection()
142 void CharsetDeclSection::setPublicId(const PublicId &id)
147 void CharsetDeclSection::addRange(const CharsetDeclRange &range)
149 ranges_.push_back(range);
152 void CharsetDeclSection::rangeDeclared(WideChar min, Number count,
153 ISet<WideChar> &declared) const
155 for (size_t i = 0; i < ranges_.size(); i++)
156 ranges_[i].rangeDeclared(min, count, declared);
159 void CharsetDeclSection::usedSet(ISet<Char> &set) const
161 for (size_t i = 0; i < ranges_.size(); i++)
162 ranges_[i].usedSet(set);
165 void CharsetDeclSection::stringToChar(const StringC &str, ISet<WideChar> &to)
168 for (size_t i = 0; i < ranges_.size(); i++)
169 ranges_[i].stringToChar(str, to);
172 void CharsetDeclSection::numberToChar(const PublicId *id, Number n,
173 ISet<WideChar> &to, Number &count) const
175 PublicId::OwnerType ownerType;
177 if (id->string() == baseset_.string()
178 // Assume that 2 ISO character sets are the same if
179 // their designating sequences are the same.
180 || (id->getOwnerType(ownerType)
181 && ownerType == PublicId::ISO
182 && baseset_.getOwnerType(ownerType)
183 && ownerType == PublicId::ISO
184 && id->getDesignatingSequence(seq1)
185 && baseset_.getDesignatingSequence(seq2)
187 for (size_t i = 0; i < ranges_.size(); i++)
188 ranges_[i].numberToChar(n, to, count);
192 Boolean CharsetDeclSection::getCharInfo(WideChar fromChar,
194 CharsetDeclRange::Type &type,
199 for (size_t i = 0; i < ranges_.size(); i++)
200 if (ranges_[i].getCharInfo(fromChar, type, n, str, count)) {
207 CharsetDecl::CharsetDecl()
211 void CharsetDecl::addSection(const PublicId &id)
213 sections_.resize(sections_.size() + 1);
214 sections_.back().setPublicId(id);
217 void CharsetDecl::swap(CharsetDecl &to)
219 sections_.swap(to.sections_);
220 declaredSet_.swap(to.declaredSet_);
223 void CharsetDecl::clear()
228 void CharsetDecl::addRange(WideChar min, Number count, WideChar baseMin)
231 declaredSet_.addRange(min, min + (count - 1));
232 CharsetDeclRange range(min, count, baseMin);
233 sections_.back().addRange(range);
236 void CharsetDecl::addRange(WideChar min, Number count)
239 declaredSet_.addRange(min, min + (count - 1));
240 CharsetDeclRange range(min, count);
241 sections_.back().addRange(range);
244 void CharsetDecl::addRange(WideChar min, Number count, const StringC &str)
247 declaredSet_.addRange(min, min + (count - 1));
248 CharsetDeclRange range(min, count, str);
249 sections_.back().addRange(range);
252 void CharsetDecl::rangeDeclared(WideChar min, Number count,
253 ISet<WideChar> &declared) const
255 for (size_t i = 0; i < sections_.size(); i++)
256 sections_[i].rangeDeclared(min, count, declared);
259 void CharsetDecl::usedSet(ISet<Char> &set) const
261 for (size_t i = 0; i < sections_.size(); i++)
262 sections_[i].usedSet(set);
265 Boolean CharsetDecl::getCharInfo(WideChar fromChar,
267 CharsetDeclRange::Type &type,
272 for (size_t i = 0; i < sections_.size(); i++)
273 if (sections_[i].getCharInfo(fromChar, id, type, n, str, count))
278 void CharsetDecl::stringToChar(const StringC &str, ISet<WideChar> &to) const
280 for (size_t i = 0; i < sections_.size(); i++)
281 sections_[i].stringToChar(str, to);
284 void CharsetDecl::numberToChar(const PublicId *id, Number n,
285 ISet<WideChar> &to, Number &count) const
287 for (size_t i = 0; i < sections_.size(); i++)
288 sections_[i].numberToChar(id, n, to, count);