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 librararies 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: Text.h /main/1 1996/07/29 17:06:13 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #define Text_INCLUDED 1
37 #include "SubstTable.h"
41 namespace SP_NAMESPACE {
46 struct SP_API TextItem {
60 // char that was ignored
62 // location of this item
63 // data - location of first char
64 // (c/sdata)entityStart - location of first char of entity
65 // (c/sdata)entityEnd - location of entity end in entity
66 // ignore - location of ignored character
67 // startDelim - location of first char of delimiter
68 // endDelim(A) - location of first char of delimiter
70 // index of character in chars_ to which this applies
74 // This is used to represent literals and attribute values.
81 void addChar(Char c, const Location &);
82 void addChars(const StringC &, const Location &);
83 void addChars(const Char *, size_t, const Location &);
84 void insertChars(const StringC &, const Location &);
85 void ignoreChar(Char, const Location &);
86 void ignoreLastChar();
87 void addEntityStart(const Location &);
88 void addEntityEnd(const Location &);
89 void addCdata(const InternalEntity *, const ConstPtr<Origin> &);
90 void addSdata(const InternalEntity *, const ConstPtr<Origin> &);
91 void addStartDelim(const Location &loc);
92 void addEndDelim(const Location &loc, Boolean lita);
93 void subst(const SubstTable<Char> &, Char space);
94 void addCharsTokenize(const Char *, size_t, const Location &loc, Char space);
95 void addCharsTokenize(const StringC &, const Location &loc, Char space);
96 void tokenize(Char space, Text &text) const;
97 Location charLocation(size_t i) const;
99 Char lastChar() const;
100 const StringC &string() const;
101 size_t nDataEntities() const;
102 Boolean fixedEqual(const Text &) const;
103 // Location of first char of start delimiter.
104 Boolean startDelimLocation(Location &) const;
105 // Location of first char of end delimiter
106 Boolean endDelimLocation(Location &) const;
107 // Is delimiter a lit or lita?
108 Boolean delimType(Boolean &lita) const;
110 void addSimple(TextItem::Type, const Location &);
112 Vector<TextItem> items_;
113 friend class TextIter;
116 class SP_API TextIter {
118 TextIter(const Text &);
120 Boolean next(TextItem::Type &, const Char *&, size_t &,
122 // Alternative interface to next()
123 Boolean valid() const;
125 TextItem::Type type() const;
126 const Location &location() const;
127 const Char *chars(size_t &length) const;
129 const TextItem *ptr_;
134 size_t Text::size() const
136 return chars_.size();
140 Char Text::lastChar() const
142 return chars_[chars_.size() - 1];
146 const StringC &Text::string() const
152 void Text::addEntityStart(const Location &loc)
154 addSimple(TextItem::entityStart, loc);
158 void Text::addEntityEnd(const Location &loc)
160 addSimple(TextItem::entityEnd, loc);
164 void Text::addChars(const StringC &s, const Location &loc)
166 addChars(s.data(), s.size(), loc);
170 void Text::addStartDelim(const Location &loc)
172 addSimple(TextItem::startDelim, loc);
176 void Text::addEndDelim(const Location &loc, Boolean lita)
178 addSimple(lita ? TextItem::endDelimA : TextItem::endDelim,
183 void Text::addCharsTokenize(const StringC &str, const Location &loc,
186 addCharsTokenize(str.data(), str.size(), loc, space);
190 void TextIter::rewind()
192 ptr_ = text_->items_.begin();
196 void TextIter::advance()
202 Boolean TextIter::valid() const
204 return ptr_ != (text_->items_.begin() + text_->items_.size());
208 const Location &TextIter::location() const
214 TextItem::Type TextIter::type() const
223 #endif /* not Text_INCLUDED */