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: 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 {
42 Location::Location(Origin *origin, Index i)
43 : origin_(origin), index_(i)
47 Location::Location(ConstPtr<Origin> origin, Index i)
48 : origin_(origin), index_(i)
56 const EntityOrigin *Origin::asEntityOrigin() const
61 const InputSourceOrigin *Origin::asInputSourceOrigin() const
66 Index Origin::refLength() const
71 Boolean Origin::origChars(const Char *&) const
76 Boolean Origin::inBracketedTextOpenDelim() const
81 Boolean Origin::inBracketedTextCloseDelim() const
86 Boolean Origin::isNumericCharRef(const Markup *&) const
91 Boolean Origin::isNamedCharRef(Index, NamedCharRef &) const
96 const EntityDecl *Origin::entityDecl() const
101 BracketOrigin::BracketOrigin(const Location &loc, Position pos)
102 : loc_(loc), pos_(pos)
106 const Location &BracketOrigin::parent() const
111 Boolean BracketOrigin::inBracketedTextOpenDelim() const
116 Boolean BracketOrigin::inBracketedTextCloseDelim() const
118 return pos_ == close;
121 InputSourceOrigin::InputSourceOrigin()
125 InputSourceOrigin::InputSourceOrigin(const Location &refLocation)
126 : refLocation_(refLocation)
130 const InputSourceOrigin *InputSourceOrigin::asInputSourceOrigin() const
135 Boolean InputSourceOrigin::defLocation(Offset, Location &) const
140 const StringC *InputSourceOrigin::entityName() const
145 InputSourceOrigin *InputSourceOrigin::copy() const
147 return new InputSourceOrigin(refLocation_);
150 const Location &InputSourceOrigin::parent() const
155 void InputSourceOrigin::setExternalInfo(ExternalInfo *info)
157 externalInfo_ = info;
160 void InputSourceOrigin::noteCharRef(Index replacementIndex,
161 const NamedCharRef &ref)
163 charRefs_.resize(charRefs_.size() + 1);
164 charRefs_.back().replacementIndex = replacementIndex;
165 charRefs_.back().refStartIndex = ref.refStartIndex();
166 charRefs_.back().refEndType = ref.refEndType();
167 charRefs_.back().origNameOffset = charRefOrigNames_.size();
168 charRefOrigNames_ += ref.origName();
171 // Number of character references whose replacement index < ind.
173 size_t InputSourceOrigin::nPrecedingCharRefs(Index ind) const
177 // charRefs_[I].replacementIndex >= ind
178 // charRefs_[i - 1].replacementIndex < ind
179 if (charRefs_.size() == 0
180 || ind > charRefs_.back().replacementIndex)
181 // This will be a common case, so optimize it.
182 i = charRefs_.size();
186 // charRefs_ < i have replacementIndex < ind
187 // charRefs_ >= lim have replacementIndex >= ind
189 size_t lim = charRefs_.size();
191 size_t mid = i + (lim - i)/2;
192 if (charRefs_[mid].replacementIndex >= ind)
201 Offset InputSourceOrigin::startOffset(Index ind) const
203 size_t n = nPrecedingCharRefs(ind);
204 if (n < charRefs_.size()
205 && ind == charRefs_[n].replacementIndex) {
207 ind = charRefs_[n].refStartIndex;
208 if (n == 0 || charRefs_[n - 1].replacementIndex != ind)
213 // charRefs[n - 1].replacementIndex < ind
214 return Offset(ind - n);
217 Boolean InputSourceOrigin::isNamedCharRef(Index ind, NamedCharRef &ref) const
219 size_t n = nPrecedingCharRefs(ind);
220 if (n < charRefs_.size() && ind == charRefs_[n].replacementIndex) {
221 ref.set(charRefs_[n].refStartIndex,
222 charRefs_[n].refEndType,
223 charRefOrigNames_.data() + charRefs_[n].origNameOffset,
224 (n + 1 < charRefs_.size()
225 ? charRefs_[n + 1].origNameOffset
226 : charRefOrigNames_.size())
227 - charRefs_[n].origNameOffset);
233 ReplacementOrigin::ReplacementOrigin(const Location &loc, Char origChar)
234 : loc_(loc), origChar_(origChar)
238 const Location &ReplacementOrigin::parent() const
243 Boolean ReplacementOrigin::origChars(const Char *&s) const
245 if (loc_.origin().isNull() || !loc_.origin()->origChars(s))
250 MultiReplacementOrigin::MultiReplacementOrigin(const Location &loc,
254 origChars.swap(origChars_);
257 const Location &MultiReplacementOrigin::parent() const
262 Boolean MultiReplacementOrigin::origChars(const Char *&s) const
264 if (loc_.origin().isNull() || !loc_.origin()->origChars(s))
265 s = origChars_.data();
269 ExternalInfo::~ExternalInfo()
273 RTTI_DEF0(ExternalInfo)
275 NamedCharRef::NamedCharRef()
276 : refStartIndex_(0), refEndType_(endOmitted)
280 NamedCharRef::NamedCharRef(Index refStartIndex, RefEndType refEndType,
281 const StringC &origName)
282 : refStartIndex_(refStartIndex),
283 refEndType_(refEndType),
288 void NamedCharRef::set(Index refStartIndex, RefEndType refEndType,
289 const Char *s, size_t n)
291 refStartIndex_ = refStartIndex;
292 refEndType_ = refEndType;
293 origName_.assign(s, n);