xref: /onnv-gate/usr/src/cmd/man/src/util/nsgmls.src/include/Markup.h (revision 0:68f95e015346)
1 // Copyright (c) 1995 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident	"%Z%%M%	%I%	%E% SMI"
4 
5 #ifndef Markup_INCLUDED
6 #define Markup_INCLUDED 1
7 
8 #ifdef __GNUG__
9 #pragma interface
10 #endif
11 
12 #include "StringC.h"
13 #include "Syntax.h"
14 #include "Sd.h"
15 #include "Vector.h"
16 #include "Text.h"
17 #include "SdText.h"
18 
19 #ifdef SP_NAMESPACE
20 namespace SP_NAMESPACE {
21 #endif
22 
23 class EntityOrigin;
24 
25 struct SP_API MarkupItem {
26   MarkupItem();
27   MarkupItem(const MarkupItem &);
28   ~MarkupItem();
29   void operator=(const MarkupItem &);
30   unsigned char type;
31   unsigned char index;
32   union {
33     size_t nChars;
34     ConstPtr<Origin> *origin; // type == entityStart
35     Text *text;				  // type == literal
36     SdText *sdText;			  // type == sdLiteral
37   };
38 };
39 
40 class InputSource;
41 
42 class SP_API Markup {
43 public:
44   enum Type {
45     reservedName,
46     sdReservedName,
47     name,
48     nameToken,
49     attributeValue,
50     number,
51     comment,
52     s,
53     shortref,
54     delimiter,
55     refEndRe,
56     entityStart,
57     entityEnd,
58     literal,
59     sdLiteral
60   };
61   Markup();
62   size_t size() const;
63   void clear();
64   void resize(size_t);
65   void addDelim(Syntax::DelimGeneral);
66   void addReservedName(Syntax::ReservedName, const InputSource *);
67   void addReservedName(Syntax::ReservedName, const StringC &);
68   void addSdReservedName(Sd::ReservedName, const InputSource *);
69   void addSdReservedName(Sd::ReservedName, const Char *, size_t);
70   void addS(Char);
71   void addS(const InputSource *);
72   void addRefEndRe();
73   void addShortref(const InputSource *);
74   void addCommentStart();
75   void addCommentChar(Char);
76   void addName(const InputSource *);
77   void addName(const Char *, size_t);
78   void addNameToken(const InputSource *);
79   void addNumber(const InputSource *);
80   void addAttributeValue(const InputSource *);
81   void addEntityStart(const Ptr<EntityOrigin> &);
82   void addEntityEnd();
83   void addLiteral(const Text &);
84   void addSdLiteral(const SdText &);
85   void changeToAttributeValue(size_t index);
86   void changeToSdReservedName(size_t index, Sd::ReservedName);
87   void swap(Markup &);
88 private:
89   StringC chars_;
90   Vector<MarkupItem> items_;
91   friend class MarkupIter;
92 };
93 
94 class Location;
95 
96 class SP_API MarkupIter {
97 public:
98   MarkupIter(const Markup &);
99   Markup::Type type() const;
100   Boolean valid() const;
101   void advance();
102   // This updates a Location.
103   void advance(Location &, const ConstPtr<Syntax> &);
104   size_t index() const;
105   const Char *charsPointer() const;
106   size_t charsLength() const;
107   const Text &text() const;
108   const EntityOrigin *entityOrigin() const; // valid for type == entityStart
109   const SdText &sdText() const;
110   Syntax::DelimGeneral delimGeneral() const;
111   Syntax::ReservedName reservedName() const;
112   Sd::ReservedName sdReservedName() const;
113 private:
114   const Char *chars_;
115   Vector<MarkupItem>::const_iterator items_;
116   size_t nItems_;
117   size_t index_;
118   size_t charIndex_;
119 };
120 
121 inline
clear()122 void Markup::clear()
123 {
124   chars_.resize(0);
125   items_.resize(0);
126 }
127 
128 inline
size()129 size_t Markup::size() const
130 {
131   return items_.size();
132 }
133 
134 inline
valid()135 Boolean MarkupIter::valid() const
136 {
137   return index_ < nItems_;
138 }
139 
140 inline
index()141 size_t MarkupIter::index() const
142 {
143   return index_;
144 }
145 
146 inline
type()147 Markup::Type MarkupIter::type() const
148 {
149   return Markup::Type(items_[index_].type);
150 }
151 
152 inline
entityOrigin()153 const EntityOrigin *MarkupIter::entityOrigin() const
154 {
155   return (*items_[index_].origin)->asEntityOrigin();
156 }
157 
158 inline
charsPointer()159 const Char *MarkupIter::charsPointer() const
160 {
161   return chars_ + charIndex_;
162 }
163 
164 inline
charsLength()165 size_t MarkupIter::charsLength() const
166 {
167   return items_[index_].nChars;
168 }
169 
170 inline
text()171 const Text &MarkupIter::text() const
172 {
173   return *items_[index_].text;
174 }
175 
176 inline
sdText()177 const SdText &MarkupIter::sdText() const
178 {
179   return *items_[index_].sdText;
180 }
181 
182 inline
delimGeneral()183 Syntax::DelimGeneral MarkupIter::delimGeneral() const
184 {
185   return Syntax::DelimGeneral(items_[index_].index);
186 }
187 
188 inline
reservedName()189 Syntax::ReservedName MarkupIter::reservedName() const
190 {
191   return Syntax::ReservedName(items_[index_].index);
192 }
193 
194 inline
sdReservedName()195 Sd::ReservedName MarkupIter::sdReservedName() const
196 {
197   return Sd::ReservedName(items_[index_].index);
198 }
199 
200 #ifdef SP_NAMESPACE
201 }
202 #endif
203 
204 #endif /* not Markup_INCLUDED */
205