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 librararies 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()
44 CharsetDeclRange::CharsetDeclRange(WideChar descMin, Number count,
53 CharsetDeclRange::CharsetDeclRange(WideChar descMin, Number count)
61 CharsetDeclRange::CharsetDeclRange(WideChar descMin, Number count,
70 void CharsetDeclRange::rangeDeclared(WideChar min, Number count,
71 ISet<WideChar> &declared) const
73 if (count > 0 && min + count > descMin_ && min < descMin_ + count_) {
74 WideChar commMin = (descMin_ > min) ? descMin_ : min;
75 WideChar commMax = min + ((min + count < descMin_ + count_
77 : descMin_ + count_ - min) - 1);
78 ASSERT(commMin <= commMax);
79 declared.addRange(commMin, commMax);
83 void CharsetDeclRange::usedSet(ISet<Char> &set) const
85 if (type_ != unused && count_ > 0 && descMin_ <= charMax) {
87 if (charMax - descMin_ < count_ - 1)
90 max = Char(descMin_ + (count_ - 1));
91 set.addRange(Char(descMin_), max);
95 void CharsetDeclRange::stringToChar(const StringC &str, ISet<WideChar> &to)
98 if (type_ == string && str_ == str && count_ > 0)
99 to.addRange(descMin_, descMin_ + (count_ - 1));
102 void CharsetDeclRange::numberToChar(Number n, ISet<WideChar> &to,
106 if (type_ == number && n >= baseMin_ && n - baseMin_ < count_) {
107 Number thisCount = count_ - (n - baseMin_);
108 if (to.isEmpty() || thisCount < count)
110 to.add(descMin_ + (n - baseMin_));
114 Boolean CharsetDeclRange::getCharInfo(WideChar fromChar,
115 CharsetDeclRange::Type &type,
120 if (fromChar >= descMin_ && fromChar - descMin_ < count_) {
123 n = baseMin_ + (fromChar - descMin_);
124 else if (type == string)
126 count = count_ - (fromChar - descMin_);
133 CharsetDeclSection::CharsetDeclSection()
137 void CharsetDeclSection::setPublicId(const PublicId &id)
142 void CharsetDeclSection::addRange(const CharsetDeclRange &range)
144 ranges_.push_back(range);
147 void CharsetDeclSection::rangeDeclared(WideChar min, Number count,
148 ISet<WideChar> &declared) const
150 for (size_t i = 0; i < ranges_.size(); i++)
151 ranges_[i].rangeDeclared(min, count, declared);
154 void CharsetDeclSection::usedSet(ISet<Char> &set) const
156 for (size_t i = 0; i < ranges_.size(); i++)
157 ranges_[i].usedSet(set);
160 void CharsetDeclSection::stringToChar(const StringC &str, ISet<WideChar> &to)
163 for (size_t i = 0; i < ranges_.size(); i++)
164 ranges_[i].stringToChar(str, to);
167 void CharsetDeclSection::numberToChar(const PublicId *id, Number n,
168 ISet<WideChar> &to, Number &count) const
170 PublicId::OwnerType ownerType;
172 if (id->string() == baseset_.string()
173 // Assume that 2 ISO character sets are the same if
174 // their designating sequences are the same.
175 || (id->getOwnerType(ownerType)
176 && ownerType == PublicId::ISO
177 && baseset_.getOwnerType(ownerType)
178 && ownerType == PublicId::ISO
179 && id->getDesignatingSequence(seq1)
180 && baseset_.getDesignatingSequence(seq2)
182 for (size_t i = 0; i < ranges_.size(); i++)
183 ranges_[i].numberToChar(n, to, count);
187 Boolean CharsetDeclSection::getCharInfo(WideChar fromChar,
189 CharsetDeclRange::Type &type,
194 for (size_t i = 0; i < ranges_.size(); i++)
195 if (ranges_[i].getCharInfo(fromChar, type, n, str, count)) {
202 CharsetDecl::CharsetDecl()
206 void CharsetDecl::addSection(const PublicId &id)
208 sections_.resize(sections_.size() + 1);
209 sections_.back().setPublicId(id);
212 void CharsetDecl::swap(CharsetDecl &to)
214 sections_.swap(to.sections_);
215 declaredSet_.swap(to.declaredSet_);
218 void CharsetDecl::clear()
223 void CharsetDecl::addRange(WideChar min, Number count, WideChar baseMin)
226 declaredSet_.addRange(min, min + (count - 1));
227 CharsetDeclRange range(min, count, baseMin);
228 sections_.back().addRange(range);
231 void CharsetDecl::addRange(WideChar min, Number count)
234 declaredSet_.addRange(min, min + (count - 1));
235 CharsetDeclRange range(min, count);
236 sections_.back().addRange(range);
239 void CharsetDecl::addRange(WideChar min, Number count, const StringC &str)
242 declaredSet_.addRange(min, min + (count - 1));
243 CharsetDeclRange range(min, count, str);
244 sections_.back().addRange(range);
247 void CharsetDecl::rangeDeclared(WideChar min, Number count,
248 ISet<WideChar> &declared) const
250 for (size_t i = 0; i < sections_.size(); i++)
251 sections_[i].rangeDeclared(min, count, declared);
254 void CharsetDecl::usedSet(ISet<Char> &set) const
256 for (size_t i = 0; i < sections_.size(); i++)
257 sections_[i].usedSet(set);
260 Boolean CharsetDecl::getCharInfo(WideChar fromChar,
262 CharsetDeclRange::Type &type,
267 for (size_t i = 0; i < sections_.size(); i++)
268 if (sections_[i].getCharInfo(fromChar, id, type, n, str, count))
273 void CharsetDecl::stringToChar(const StringC &str, ISet<WideChar> &to) const
275 for (size_t i = 0; i < sections_.size(); i++)
276 sections_[i].stringToChar(str, to);
279 void CharsetDecl::numberToChar(const PublicId *id, Number n,
280 ISet<WideChar> &to, Number &count) const
282 for (size_t i = 0; i < sections_.size(); i++)
283 sections_[i].numberToChar(id, n, to, count);