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: Location.C /main/1 1996/07/29 16:56:17 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
34 namespace SP_NAMESPACE {
41 Location::Location(Origin *origin, Index i)
42 : origin_(origin), index_(i)
46 Location::Location(ConstPtr<Origin> origin, Index i)
47 : origin_(origin), index_(i)
55 const EntityOrigin *Origin::asEntityOrigin() const
60 const InputSourceOrigin *Origin::asInputSourceOrigin() const
65 Index Origin::refLength() const
70 Boolean Origin::origChars(const Char *&) const
75 Boolean Origin::inBracketedTextOpenDelim() const
80 Boolean Origin::inBracketedTextCloseDelim() const
85 Boolean Origin::isNumericCharRef(const Markup *&) const
90 Boolean Origin::isNamedCharRef(Index, NamedCharRef &) const
95 const EntityDecl *Origin::entityDecl() const
100 BracketOrigin::BracketOrigin(const Location &loc, Position pos)
101 : loc_(loc), pos_(pos)
105 const Location &BracketOrigin::parent() const
110 Boolean BracketOrigin::inBracketedTextOpenDelim() const
115 Boolean BracketOrigin::inBracketedTextCloseDelim() const
117 return pos_ == close;
120 InputSourceOrigin::InputSourceOrigin()
124 InputSourceOrigin::InputSourceOrigin(const Location &refLocation)
125 : refLocation_(refLocation)
129 const InputSourceOrigin *InputSourceOrigin::asInputSourceOrigin() const
134 Boolean InputSourceOrigin::defLocation(Offset, Location &) const
139 const StringC *InputSourceOrigin::entityName() const
144 InputSourceOrigin *InputSourceOrigin::copy() const
146 return new InputSourceOrigin(refLocation_);
149 const Location &InputSourceOrigin::parent() const
154 void InputSourceOrigin::setExternalInfo(ExternalInfo *info)
156 externalInfo_ = info;
159 void InputSourceOrigin::noteCharRef(Index replacementIndex,
160 const NamedCharRef &ref)
162 charRefs_.resize(charRefs_.size() + 1);
163 charRefs_.back().replacementIndex = replacementIndex;
164 charRefs_.back().refStartIndex = ref.refStartIndex();
165 charRefs_.back().refEndType = ref.refEndType();
166 charRefs_.back().origNameOffset = charRefOrigNames_.size();
167 charRefOrigNames_ += ref.origName();
170 // Number of character references whose replacement index < ind.
172 size_t InputSourceOrigin::nPrecedingCharRefs(Index ind) const
176 // charRefs_[I].replacementIndex >= ind
177 // charRefs_[i - 1].replacementIndex < ind
178 if (charRefs_.size() == 0
179 || ind > charRefs_.back().replacementIndex)
180 // This will be a common case, so optimize it.
181 i = charRefs_.size();
185 // charRefs_ < i have replacementIndex < ind
186 // charRefs_ >= lim have replacementIndex >= ind
188 size_t lim = charRefs_.size();
190 size_t mid = i + (lim - i)/2;
191 if (charRefs_[mid].replacementIndex >= ind)
200 Offset InputSourceOrigin::startOffset(Index ind) const
202 size_t n = nPrecedingCharRefs(ind);
203 if (n < charRefs_.size()
204 && ind == charRefs_[n].replacementIndex) {
206 ind = charRefs_[n].refStartIndex;
207 if (n == 0 || charRefs_[n - 1].replacementIndex != ind)
212 // charRefs[n - 1].replacementIndex < ind
213 return Offset(ind - n);
216 Boolean InputSourceOrigin::isNamedCharRef(Index ind, NamedCharRef &ref) const
218 size_t n = nPrecedingCharRefs(ind);
219 if (n < charRefs_.size() && ind == charRefs_[n].replacementIndex) {
220 ref.set(charRefs_[n].refStartIndex,
221 charRefs_[n].refEndType,
222 charRefOrigNames_.data() + charRefs_[n].origNameOffset,
223 (n + 1 < charRefs_.size()
224 ? charRefs_[n + 1].origNameOffset
225 : charRefOrigNames_.size())
226 - charRefs_[n].origNameOffset);
232 ReplacementOrigin::ReplacementOrigin(const Location &loc, Char origChar)
233 : loc_(loc), origChar_(origChar)
237 const Location &ReplacementOrigin::parent() const
242 Boolean ReplacementOrigin::origChars(const Char *&s) const
244 if (loc_.origin().isNull() || !loc_.origin()->origChars(s))
249 MultiReplacementOrigin::MultiReplacementOrigin(const Location &loc,
253 origChars.swap(origChars_);
256 const Location &MultiReplacementOrigin::parent() const
261 Boolean MultiReplacementOrigin::origChars(const Char *&s) const
263 if (loc_.origin().isNull() || !loc_.origin()->origChars(s))
264 s = origChars_.data();
268 ExternalInfo::~ExternalInfo()
272 RTTI_DEF0(ExternalInfo)
274 NamedCharRef::NamedCharRef()
278 NamedCharRef::NamedCharRef(Index refStartIndex, RefEndType refEndType,
279 const StringC &origName)
280 : refStartIndex_(refStartIndex),
281 refEndType_(refEndType),
286 void NamedCharRef::set(Index refStartIndex, RefEndType refEndType,
287 const Char *s, size_t n)
289 refStartIndex_ = refStartIndex;
290 refEndType_ = refEndType;
291 origName_.assign(s, n);