123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: InputSource.h /main/1 1996/07/29 16:55:17 cde-hp $ */
- // Copyright (c) 1994 James Clark
- // See the file COPYING for copying permission.
- #ifndef InputSource_INCLUDED
- #define InputSource_INCLUDED 1
- #ifdef __GNUG__
- #pragma interface
- #endif
- #include "types.h"
- #include "Link.h"
- #include "Ptr.h"
- #include "Location.h"
- #include "XcharMap.h"
- #include <stddef.h>
- #ifdef SP_NAMESPACE
- namespace SP_NAMESPACE {
- #endif
- class Messenger;
- class NamedCharRef;
- class SP_API InputSource : public Link {
- public:
- enum { eE = -1 }; // end of entity signal
- virtual ~InputSource();
- Xchar get(Messenger &);
- virtual void pushCharRef(Char ch, const NamedCharRef &) = 0;
- const Location ¤tLocation() const;
- const Char *currentTokenStart() const;
- size_t currentTokenLength() const;
- const Char *currentTokenEnd() const;
- Index nextIndex() const;
- // Discard all but the last character of the current token.
- void discardInitial();
- void startToken();
- void startTokenNoMulticode();
- void endToken(size_t length);
- Xchar tokenChar(Messenger &);
- void ungetToken();
- void setMarkupScanTable(const XcharMap<unsigned char> &);
- Boolean scanSuppress() const;
- void extendToBufferEnd();
- virtual void willNotRewind();
- virtual Boolean rewind(Messenger &) = 0;
- Boolean accessError() const;
- protected:
- InputSource(InputSourceOrigin *origin, const Char *start, const Char *end);
- void reset(const Char *start, const Char *end);
- InputSourceOrigin *inputSourceOrigin();
- void noteCharRef(Index replacementIndex, const NamedCharRef &);
- const Char *cur();
- const Char *start();
- const Char *end();
- Index startIndex();
- void changeBuffer(const Char *newBase, const Char *oldBase);
- void advanceEnd(const Char *newEnd);
- void moveLeft();
- void moveStart(const Char *newStart);
- Char nextChar();
- void setAccessError();
- private:
- InputSource(const InputSource &); // undefined
- void operator=(const InputSource &); // undefined
- virtual Xchar fill(Messenger &) = 0;
- void advanceStart(const Char *to);
- void advanceStartMulticode(const Char *to);
-
- const Char *cur_;
- const Char *start_;
- const Char *end_;
- Location startLocation_;
- Ptr<InputSourceOrigin> origin_;
- Boolean accessError_;
- Boolean scanSuppress_;
- Boolean scanSuppressSingle_;
- Index scanSuppressIndex_;
- Boolean multicode_;
- XcharMap<unsigned char> markupScanTable_;
- };
- inline
- void InputSource::advanceStart(const Char *to)
- {
- if (multicode_)
- advanceStartMulticode(to);
- else {
- startLocation_ += to - start_;
- start_ = to;
- }
- }
- inline
- Xchar InputSource::get(Messenger &mgr)
- {
- advanceStart(cur_);
- return cur_ < end_ ? *cur_++ : fill(mgr);
- }
- inline
- void InputSource::startTokenNoMulticode()
- {
- startLocation_ += cur_ - start_;
- start_ = cur_;
- }
- inline
- void InputSource::startToken()
- {
- advanceStart(cur_);
- }
- inline
- void InputSource::endToken(size_t length)
- {
- cur_ = start_ + length;
- }
- inline
- Xchar InputSource::tokenChar(Messenger &mgr)
- {
- return cur_ < end_ ? *cur_++ : fill(mgr);
- }
- inline
- void InputSource::extendToBufferEnd()
- {
- cur_ = end_;
- }
- inline
- const Char *InputSource::cur()
- {
- return cur_;
- }
- inline
- const Char *InputSource::start()
- {
- return start_;
- }
- inline
- const Char *InputSource::end()
- {
- return end_;
- }
- inline
- void InputSource::changeBuffer(const Char *newBase, const Char *oldBase)
- {
- cur_ = newBase + (cur_ - oldBase);
- start_ = newBase + (start_ - oldBase);
- end_ = newBase + (end_ - oldBase);
- }
- inline
- void InputSource::moveStart(const Char *newStart)
- {
- cur_ = newStart + (cur_ - start_);
- end_ = newStart + (end_ - start_);
- start_ = newStart;
- }
- inline
- void InputSource::advanceEnd(const Char *newEnd)
- {
- end_ = newEnd;
- }
- inline
- Char InputSource::nextChar()
- {
- return *cur_++;
- }
- inline
- Index InputSource::startIndex()
- {
- return startLocation_.index();
- }
- inline
- void InputSource::moveLeft()
- {
- start_--;
- cur_--;
- }
- inline
- void InputSource::noteCharRef(Index replacementIndex, const NamedCharRef &ref)
- {
- origin_->noteCharRef(replacementIndex, ref);
- }
- inline
- const Location &InputSource::currentLocation() const
- {
- return startLocation_;
- }
- inline
- const Char *InputSource::currentTokenStart() const
- {
- return start_;
- }
- inline
- size_t InputSource::currentTokenLength() const
- {
- return cur_ - start_;
- }
- inline
- Index InputSource::nextIndex() const
- {
- return startLocation_.index() + (cur_ - start_);
- }
- inline
- const Char *InputSource::currentTokenEnd() const
- {
- return cur_;
- }
- inline
- void InputSource::discardInitial()
- {
- advanceStart(cur_ - 1);
- }
- inline
- void InputSource::ungetToken()
- {
- cur_ = start_;
- }
- inline
- void InputSource::setMarkupScanTable(const XcharMap<unsigned char> &table)
- {
- markupScanTable_ = table;
- multicode_ = 1;
- }
- inline
- Boolean InputSource::scanSuppress() const
- {
- return scanSuppress_ && (!scanSuppressSingle_
- || startLocation_.index() == scanSuppressIndex_);
- }
- inline
- InputSourceOrigin *InputSource::inputSourceOrigin()
- {
- return origin_.pointer();
- }
- inline
- void InputSource::setAccessError()
- {
- accessError_ = 1;
- }
- inline
- Boolean InputSource::accessError() const
- {
- return accessError_;
- }
- #ifdef SP_NAMESPACE
- }
- #endif
- #endif /* not InputSource_INCLUDED */
|