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: InputSource.h /main/1 1996/07/29 16:55:17 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef InputSource_INCLUDED
28 #define InputSource_INCLUDED 1
41 namespace SP_NAMESPACE {
47 class SP_API InputSource : public Link {
49 enum { eE = -1 }; // end of entity signal
51 virtual ~InputSource();
52 Xchar get(Messenger &);
53 virtual void pushCharRef(Char ch, const NamedCharRef &) = 0;
54 const Location ¤tLocation() const;
55 const Char *currentTokenStart() const;
56 size_t currentTokenLength() const;
57 const Char *currentTokenEnd() const;
58 Index nextIndex() const;
59 // Discard all but the last character of the current token.
60 void discardInitial();
62 void startTokenNoMulticode();
63 void endToken(size_t length);
64 Xchar tokenChar(Messenger &);
66 void setMarkupScanTable(const XcharMap<unsigned char> &);
67 Boolean scanSuppress() const;
68 void extendToBufferEnd();
69 virtual void willNotRewind();
70 virtual Boolean rewind(Messenger &) = 0;
71 Boolean accessError() const;
73 InputSource(InputSourceOrigin *origin, const Char *start, const Char *end);
74 void reset(const Char *start, const Char *end);
75 InputSourceOrigin *inputSourceOrigin();
76 void noteCharRef(Index replacementIndex, const NamedCharRef &);
81 void changeBuffer(const Char *newBase, const Char *oldBase);
82 void advanceEnd(const Char *newEnd);
84 void moveStart(const Char *newStart);
86 void setAccessError();
88 InputSource(const InputSource &); // undefined
89 void operator=(const InputSource &); // undefined
90 virtual Xchar fill(Messenger &) = 0;
91 void advanceStart(const Char *to);
92 void advanceStartMulticode(const Char *to);
97 Location startLocation_;
98 Ptr<InputSourceOrigin> origin_;
100 Boolean scanSuppress_;
101 Boolean scanSuppressSingle_;
102 Index scanSuppressIndex_;
104 XcharMap<unsigned char> markupScanTable_;
108 void InputSource::advanceStart(const Char *to)
111 advanceStartMulticode(to);
113 startLocation_ += to - start_;
119 Xchar InputSource::get(Messenger &mgr)
122 return cur_ < end_ ? *cur_++ : fill(mgr);
126 void InputSource::startTokenNoMulticode()
128 startLocation_ += cur_ - start_;
133 void InputSource::startToken()
139 void InputSource::endToken(size_t length)
141 cur_ = start_ + length;
145 Xchar InputSource::tokenChar(Messenger &mgr)
147 return cur_ < end_ ? *cur_++ : fill(mgr);
151 void InputSource::extendToBufferEnd()
157 const Char *InputSource::cur()
163 const Char *InputSource::start()
169 const Char *InputSource::end()
175 void InputSource::changeBuffer(const Char *newBase, const Char *oldBase)
177 cur_ = newBase + (cur_ - oldBase);
178 start_ = newBase + (start_ - oldBase);
179 end_ = newBase + (end_ - oldBase);
183 void InputSource::moveStart(const Char *newStart)
185 cur_ = newStart + (cur_ - start_);
186 end_ = newStart + (end_ - start_);
191 void InputSource::advanceEnd(const Char *newEnd)
197 Char InputSource::nextChar()
203 Index InputSource::startIndex()
205 return startLocation_.index();
209 void InputSource::moveLeft()
216 void InputSource::noteCharRef(Index replacementIndex, const NamedCharRef &ref)
218 origin_->noteCharRef(replacementIndex, ref);
222 const Location &InputSource::currentLocation() const
224 return startLocation_;
228 const Char *InputSource::currentTokenStart() const
234 size_t InputSource::currentTokenLength() const
236 return cur_ - start_;
240 Index InputSource::nextIndex() const
242 return startLocation_.index() + (cur_ - start_);
246 const Char *InputSource::currentTokenEnd() const
252 void InputSource::discardInitial()
254 advanceStart(cur_ - 1);
258 void InputSource::ungetToken()
264 void InputSource::setMarkupScanTable(const XcharMap<unsigned char> &table)
266 markupScanTable_ = table;
271 Boolean InputSource::scanSuppress() const
273 return scanSuppress_ && (!scanSuppressSingle_
274 || startLocation_.index() == scanSuppressIndex_);
278 InputSourceOrigin *InputSource::inputSourceOrigin()
280 return origin_.pointer();
284 void InputSource::setAccessError()
290 Boolean InputSource::accessError() const
299 #endif /* not InputSource_INCLUDED */