Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / nsgmls / Markup.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Markup.h /main/1 1996/07/29 16:56:43 cde-hp $ */
24 // Copyright (c) 1995 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Markup_INCLUDED
28 #define Markup_INCLUDED 1
29
30 #ifdef __GNUG__
31 #pragma interface
32 #endif
33
34 #include "StringC.h"
35 #include "Syntax.h"
36 #include "Sd.h"
37 #include "Vector.h"
38 #include "Text.h"
39 #include "SdText.h"
40
41 #ifdef SP_NAMESPACE
42 namespace SP_NAMESPACE {
43 #endif
44
45 class EntityOrigin;
46
47 struct SP_API MarkupItem {
48   MarkupItem();
49   MarkupItem(const MarkupItem &);
50   ~MarkupItem();
51   void operator=(const MarkupItem &);
52   unsigned char type;
53   unsigned char index;
54   union {
55     size_t nChars;
56     ConstPtr<Origin> *origin; // type == entityStart
57     Text *text;                           // type == literal
58     SdText *sdText;                       // type == sdLiteral
59   };
60 };
61
62 class InputSource;
63
64 class SP_API Markup {
65 public:
66   enum Type {
67     reservedName,
68     sdReservedName,
69     name,
70     nameToken,
71     attributeValue,
72     number,
73     comment,
74     s,
75     shortref,
76     delimiter,
77     refEndRe,
78     entityStart,
79     entityEnd,
80     literal,
81     sdLiteral
82   };
83   Markup();
84   size_t size() const;
85   void clear();
86   void resize(size_t);
87   void addDelim(Syntax::DelimGeneral);
88   void addReservedName(Syntax::ReservedName, const InputSource *);
89   void addReservedName(Syntax::ReservedName, const StringC &);
90   void addSdReservedName(Sd::ReservedName, const InputSource *);
91   void addSdReservedName(Sd::ReservedName, const Char *, size_t);
92   void addS(Char);
93   void addS(const InputSource *);
94   void addRefEndRe();
95   void addShortref(const InputSource *);
96   void addCommentStart();
97   void addCommentChar(Char);
98   void addName(const InputSource *);
99   void addName(const Char *, size_t);
100   void addNameToken(const InputSource *);
101   void addNumber(const InputSource *);
102   void addAttributeValue(const InputSource *);
103   void addEntityStart(const Ptr<EntityOrigin> &);
104   void addEntityEnd();
105   void addLiteral(const Text &);
106   void addSdLiteral(const SdText &);
107   void changeToAttributeValue(size_t index);
108   void swap(Markup &);
109 private:
110   StringC chars_;
111   Vector<MarkupItem> items_;
112   friend class MarkupIter;
113 };
114
115 class Location;
116
117 class SP_API MarkupIter {
118 public:
119   MarkupIter(const Markup &);
120   Markup::Type type() const;
121   Boolean valid() const;
122   void advance();
123   // This updates a Location.
124   void advance(Location &, const ConstPtr<Syntax> &);
125   size_t index() const;
126   const Char *charsPointer() const;
127   size_t charsLength() const;
128   const Text &text() const;
129   const EntityOrigin *entityOrigin() const; // valid for type == entityStart
130   const SdText &sdText() const;
131   Syntax::DelimGeneral delimGeneral() const;
132   Syntax::ReservedName reservedName() const;
133   Sd::ReservedName sdReservedName() const;
134 private:
135   const Char *chars_;
136   Vector<MarkupItem>::const_iterator items_;
137   size_t nItems_;
138   size_t index_;
139   size_t charIndex_;
140 };
141
142 inline
143 void Markup::clear()
144 {
145   chars_.resize(0);
146   items_.resize(0);
147 }
148
149 inline
150 size_t Markup::size() const
151 {
152   return items_.size();
153 }
154
155 inline
156 Boolean MarkupIter::valid() const
157 {
158   return index_ < nItems_;
159 }
160
161 inline
162 size_t MarkupIter::index() const
163 {
164   return index_;
165 }
166
167 inline
168 Markup::Type MarkupIter::type() const
169 {
170   return Markup::Type(items_[index_].type);
171 }
172
173 inline
174 const EntityOrigin *MarkupIter::entityOrigin() const
175 {
176   return (*items_[index_].origin)->asEntityOrigin();
177 }
178
179 inline
180 const Char *MarkupIter::charsPointer() const
181 {
182   return chars_ + charIndex_;
183 }
184
185 inline
186 size_t MarkupIter::charsLength() const
187 {
188   return items_[index_].nChars;
189 }
190
191 inline
192 const Text &MarkupIter::text() const
193 {
194   return *items_[index_].text;
195 }
196
197 inline
198 const SdText &MarkupIter::sdText() const
199 {
200   return *items_[index_].sdText;
201 }
202
203 inline
204 Syntax::DelimGeneral MarkupIter::delimGeneral() const
205 {
206   return Syntax::DelimGeneral(items_[index_].index);
207 }
208
209 inline
210 Syntax::ReservedName MarkupIter::reservedName() const
211 {
212   return Syntax::ReservedName(items_[index_].index);
213 }
214
215 inline
216 Sd::ReservedName MarkupIter::sdReservedName() const
217 {
218   return Sd::ReservedName(items_[index_].index);
219 }
220
221 #ifdef SP_NAMESPACE
222 }
223 #endif
224
225 #endif /* not Markup_INCLUDED */