123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- /*
- * 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: Markup.h /main/1 1996/07/29 16:56:43 cde-hp $ */
- // Copyright (c) 1995 James Clark
- // See the file COPYING for copying permission.
- #ifndef Markup_INCLUDED
- #define Markup_INCLUDED 1
- #ifdef __GNUG__
- #pragma interface
- #endif
- #include "StringC.h"
- #include "Syntax.h"
- #include "Sd.h"
- #include "Vector.h"
- #include "Text.h"
- #include "SdText.h"
- #ifdef SP_NAMESPACE
- namespace SP_NAMESPACE {
- #endif
- class EntityOrigin;
- struct SP_API MarkupItem {
- MarkupItem();
- MarkupItem(const MarkupItem &);
- ~MarkupItem();
- void operator=(const MarkupItem &);
- unsigned char type;
- unsigned char index;
- union {
- size_t nChars;
- ConstPtr<Origin> *origin; // type == entityStart
- Text *text; // type == literal
- SdText *sdText; // type == sdLiteral
- };
- };
- class InputSource;
- class SP_API Markup {
- public:
- enum Type {
- reservedName,
- sdReservedName,
- name,
- nameToken,
- attributeValue,
- number,
- comment,
- s,
- shortref,
- delimiter,
- refEndRe,
- entityStart,
- entityEnd,
- literal,
- sdLiteral
- };
- Markup();
- size_t size() const;
- void clear();
- void resize(size_t);
- void addDelim(Syntax::DelimGeneral);
- void addReservedName(Syntax::ReservedName, const InputSource *);
- void addReservedName(Syntax::ReservedName, const StringC &);
- void addSdReservedName(Sd::ReservedName, const InputSource *);
- void addSdReservedName(Sd::ReservedName, const Char *, size_t);
- void addS(Char);
- void addS(const InputSource *);
- void addRefEndRe();
- void addShortref(const InputSource *);
- void addCommentStart();
- void addCommentChar(Char);
- void addName(const InputSource *);
- void addName(const Char *, size_t);
- void addNameToken(const InputSource *);
- void addNumber(const InputSource *);
- void addAttributeValue(const InputSource *);
- void addEntityStart(const Ptr<EntityOrigin> &);
- void addEntityEnd();
- void addLiteral(const Text &);
- void addSdLiteral(const SdText &);
- void changeToAttributeValue(size_t index);
- void swap(Markup &);
- private:
- StringC chars_;
- Vector<MarkupItem> items_;
- friend class MarkupIter;
- };
- class Location;
- class SP_API MarkupIter {
- public:
- MarkupIter(const Markup &);
- Markup::Type type() const;
- Boolean valid() const;
- void advance();
- // This updates a Location.
- void advance(Location &, const ConstPtr<Syntax> &);
- size_t index() const;
- const Char *charsPointer() const;
- size_t charsLength() const;
- const Text &text() const;
- const EntityOrigin *entityOrigin() const; // valid for type == entityStart
- const SdText &sdText() const;
- Syntax::DelimGeneral delimGeneral() const;
- Syntax::ReservedName reservedName() const;
- Sd::ReservedName sdReservedName() const;
- private:
- const Char *chars_;
- Vector<MarkupItem>::const_iterator items_;
- size_t nItems_;
- size_t index_;
- size_t charIndex_;
- };
- inline
- void Markup::clear()
- {
- chars_.resize(0);
- items_.resize(0);
- }
- inline
- size_t Markup::size() const
- {
- return items_.size();
- }
- inline
- Boolean MarkupIter::valid() const
- {
- return index_ < nItems_;
- }
- inline
- size_t MarkupIter::index() const
- {
- return index_;
- }
- inline
- Markup::Type MarkupIter::type() const
- {
- return Markup::Type(items_[index_].type);
- }
- inline
- const EntityOrigin *MarkupIter::entityOrigin() const
- {
- return (*items_[index_].origin)->asEntityOrigin();
- }
- inline
- const Char *MarkupIter::charsPointer() const
- {
- return chars_ + charIndex_;
- }
- inline
- size_t MarkupIter::charsLength() const
- {
- return items_[index_].nChars;
- }
- inline
- const Text &MarkupIter::text() const
- {
- return *items_[index_].text;
- }
- inline
- const SdText &MarkupIter::sdText() const
- {
- return *items_[index_].sdText;
- }
- inline
- Syntax::DelimGeneral MarkupIter::delimGeneral() const
- {
- return Syntax::DelimGeneral(items_[index_].index);
- }
- inline
- Syntax::ReservedName MarkupIter::reservedName() const
- {
- return Syntax::ReservedName(items_[index_].index);
- }
- inline
- Sd::ReservedName MarkupIter::sdReservedName() const
- {
- return Sd::ReservedName(items_[index_].index);
- }
- #ifdef SP_NAMESPACE
- }
- #endif
- #endif /* not Markup_INCLUDED */
|