source: trunk/tools/qdoc3/atom.cpp@ 99

Last change on this file since 99 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 10.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <qregexp.h>
43#include "atom.h"
44#include "location.h"
45#include <stdio.h>
46
47QT_BEGIN_NAMESPACE
48
49QString Atom::BOLD_ ("bold");
50QString Atom::INDEX_ ("index");
51QString Atom::ITALIC_ ("italic");
52QString Atom::LINK_ ("link");
53QString Atom::PARAMETER_ ("parameter");
54QString Atom::SUBSCRIPT_ ("subscript");
55QString Atom::SUPERSCRIPT_ ("superscript");
56QString Atom::TELETYPE_ ("teletype");
57QString Atom::UNDERLINE_ ("underline");
58
59QString Atom::BULLET_ ("bullet");
60QString Atom::TAG_ ("tag");
61QString Atom::VALUE_ ("value");
62QString Atom::LOWERALPHA_ ("loweralpha");
63QString Atom::LOWERROMAN_ ("lowerroman");
64QString Atom::NUMERIC_ ("numeric");
65QString Atom::UPPERALPHA_ ("upperalpha");
66QString Atom::UPPERROMAN_ ("upperroman");
67
68/*! \class Atom
69 \brief The Atom class is the fundamental unit for representing
70 documents internally.
71
72 Atoms have a \i type and are completed by a \i string whose
73 meaning depends on the \i type. For example, the string
74 \quotation
75 \i italic text looks nicer than \bold bold text
76 \endquotation
77 is represented by the following atoms:
78 \quotation
79 (FormattingLeft, ATOM_FORMATTING_ITALIC)
80 (String, "italic")
81 (FormattingRight, ATOM_FORMATTING_ITALIC)
82 (String, " text is more attractive than ")
83 (FormattingLeft, ATOM_FORMATTING_BOLD)
84 (String, "bold")
85 (FormattingRight, ATOM_FORMATTING_BOLD)
86 (String, " text")
87 \endquotation
88
89 \also Text
90*/
91
92/*! \enum Atom::Type
93
94 \value AbstractLeft
95 \value AbstractRight
96 \value AutoLink
97 \value BaseName
98 \value BriefLeft
99 \value BriefRight
100 \value C
101 \value CaptionLeft
102 \value CaptionRight
103 \value Code
104 \value CodeBad
105 \value CodeNew
106 \value CodeOld
107 \value CodeQuoteArgument
108 \value CodeQuoteCommand
109 \value EndQmlText
110 \value FormatElse
111 \value FormatEndif
112 \value FormatIf
113 \value FootnoteLeft
114 \value FootnoteRight
115 \value FormattingLeft
116 \value FormattingRight
117 \value GeneratedList
118 \value Image
119 \value ImageText
120 \value InlineImage
121 \value LineBreak
122 \value Link
123 \value LinkNode
124 \value ListLeft
125 \value ListItemNumber
126 \value ListTagLeft
127 \value ListTagRight
128 \value ListItemLeft
129 \value ListItemRight
130 \value ListRight
131 \value Nop
132 \value ParaLeft
133 \value ParaRight
134 \value Qml
135 \value QmlText
136 \value QuotationLeft
137 \value QuotationRight
138 \value RawString
139 \value SectionLeft
140 \value SectionRight
141 \value SectionHeadingLeft
142 \value SectionHeadingRight
143 \value SidebarLeft
144 \value SidebarRight
145 \value String
146 \value TableLeft
147 \value TableRight
148 \value TableHeaderLeft
149 \value TableHeaderRight
150 \value TableRowLeft
151 \value TableRowRight
152 \value TableItemLeft
153 \value TableItemRight
154 \value TableOfContents
155 \value Target
156 \value UnhandledFormat
157 \value UnknownCommand
158*/
159
160static const struct {
161 const char *english;
162 int no;
163} atms[] = {
164 { "AbstractLeft", Atom::AbstractLeft },
165 { "AbstractRight", Atom::AbstractRight },
166 { "AutoLink", Atom::AutoLink },
167 { "BaseName", Atom::BaseName },
168 { "BriefLeft", Atom::BriefLeft },
169 { "BriefRight", Atom::BriefRight },
170 { "C", Atom::C },
171 { "CaptionLeft", Atom::CaptionLeft },
172 { "CaptionRight", Atom::CaptionRight },
173 { "Code", Atom::Code },
174 { "CodeBad", Atom::CodeBad },
175 { "CodeNew", Atom::CodeNew },
176 { "CodeOld", Atom::CodeOld },
177 { "CodeQuoteArgument", Atom::CodeQuoteArgument },
178 { "CodeQuoteCommand", Atom::CodeQuoteCommand },
179#ifdef QDOC_QML
180 { "EndQmlText", Atom::EndQmlText },
181#endif
182 { "FootnoteLeft", Atom::FootnoteLeft },
183 { "FootnoteRight", Atom::FootnoteRight },
184 { "FormatElse", Atom::FormatElse },
185 { "FormatEndif", Atom::FormatEndif },
186 { "FormatIf", Atom::FormatIf },
187 { "FormattingLeft", Atom::FormattingLeft },
188 { "FormattingRight", Atom::FormattingRight },
189 { "GeneratedList", Atom::GeneratedList },
190 { "Image", Atom::Image },
191 { "ImageText", Atom::ImageText },
192 { "InlineImage", Atom::InlineImage },
193 { "LegaleseLeft", Atom::LegaleseLeft },
194 { "LegaleseRight", Atom::LegaleseRight },
195 { "LineBreak", Atom::LineBreak },
196 { "Link", Atom::Link },
197 { "LinkNode", Atom::LinkNode },
198 { "ListLeft", Atom::ListLeft },
199 { "ListItemNumber", Atom::ListItemNumber },
200 { "ListTagLeft", Atom::ListTagLeft },
201 { "ListTagRight", Atom::ListTagRight },
202 { "ListItemLeft", Atom::ListItemLeft },
203 { "ListItemRight", Atom::ListItemRight },
204 { "ListRight", Atom::ListRight },
205 { "Nop", Atom::Nop },
206 { "ParaLeft", Atom::ParaLeft },
207 { "ParaRight", Atom::ParaRight },
208#ifdef QDOC_QML
209 { "Qml", Atom::Qml},
210 { "QmlText", Atom::QmlText },
211#endif
212 { "QuotationLeft", Atom::QuotationLeft },
213 { "QuotationRight", Atom::QuotationRight },
214 { "RawString", Atom::RawString },
215 { "SectionLeft", Atom::SectionLeft },
216 { "SectionRight", Atom::SectionRight },
217 { "SectionHeadingLeft", Atom::SectionHeadingLeft },
218 { "SectionHeadingRight", Atom::SectionHeadingRight },
219 { "SidebarLeft", Atom::SidebarLeft },
220 { "SidebarRight", Atom::SidebarRight },
221 { "SnippetCommand", Atom::SnippetCommand },
222 { "SnippetIdentifier", Atom::SnippetIdentifier },
223 { "SnippetLocation", Atom::SnippetLocation },
224 { "String", Atom::String },
225 { "TableLeft", Atom::TableLeft },
226 { "TableRight", Atom::TableRight },
227 { "TableHeaderLeft", Atom::TableHeaderLeft },
228 { "TableHeaderRight", Atom::TableHeaderRight },
229 { "TableRowLeft", Atom::TableRowLeft },
230 { "TableRowRight", Atom::TableRowRight },
231 { "TableItemLeft", Atom::TableItemLeft },
232 { "TableItemRight", Atom::TableItemRight },
233 { "TableOfContents", Atom::TableOfContents },
234 { "Target", Atom::Target },
235 { "UnhandledFormat", Atom::UnhandledFormat },
236 { "UnknownCommand", Atom::UnknownCommand },
237 { 0, 0 }
238};
239
240/*! \fn Atom::Atom( Type type, const QString& string )
241
242 Constructs an atom (\a type, \a string) outside of any atom list.
243*/
244
245/*! \fn Atom( Atom *prev, Type type, const QString& string )
246
247 Constructs an atom (\a type, \a string) that follows \a prev in \a
248 prev's atom list.
249*/
250
251/*! \fn void Atom::appendChar( QChar ch )
252
253 Appends \a ch to the string parameter of this atom.
254
255 \also string()
256*/
257
258/*! \fn void Atom::appendString( const QString& string )
259
260 Appends \a string to the string parameter of this atom.
261
262 \also string()
263*/
264
265/*! \fn void Atom::chopString()
266
267 \also string()
268*/
269
270/*! \fn Atom *Atom::next()
271 Return the next atom in the atom list.
272 \also type(), string()
273*/
274
275/*!
276 Return the next Atom in the list if it is of Type \a t.
277 Otherwise return 0.
278 */
279const Atom* Atom::next(Type t) const
280{
281 return (nxt && (nxt->type() == t)) ? nxt : 0;
282}
283
284/*!
285 Return the next Atom in the list if it is of Type \a t
286 and its string part is \a s. Otherwise return 0.
287 */
288const Atom* Atom::next(Type t, const QString& s) const
289{
290 return (nxt && (nxt->type() == t) && (nxt->string() == s)) ? nxt : 0;
291}
292
293/*! \fn const Atom *Atom::next() const
294 Return the next atom in the atom list.
295 \also type(), string()
296*/
297
298/*! \fn Type Atom::type() const
299 Return the type of this atom.
300 \also string(), next()
301*/
302
303/*!
304 Return the type of this atom as a string. Return "Invalid" if
305 type() returns an impossible value.
306
307 This is only useful for debugging.
308
309 \also type()
310*/
311QString Atom::typeString() const
312{
313 static bool deja = false;
314
315 if ( !deja ) {
316 int i = 0;
317 while ( atms[i].english != 0 ) {
318 if ( atms[i].no != i )
319 Location::internalError( tr("atom %1 missing").arg(i) );
320 i++;
321 }
322 deja = true;
323 }
324
325 int i = (int) type();
326 if ( i < 0 || i > (int) Last )
327 return QLatin1String("Invalid");
328 return QLatin1String(atms[i].english);
329}
330
331/*! \fn const QString& Atom::string() const
332
333 Returns the string parameter that together with the type
334 characterizes this atom.
335
336 \also type(), next()
337*/
338
339/*!
340 Dumps this Atom to stderr in printer friendly form.
341 */
342void Atom::dump() const
343{
344 QString str = string();
345 str.replace( "\\", "\\\\" );
346 str.replace( "\"", "\\\"" );
347 str.replace( "\n", "\\n" );
348 str.replace( QRegExp("[^\x20-\x7e]"), "?" );
349 if (!str.isEmpty())
350 str = " \"" + str + "\"";
351 fprintf(stderr,
352 " %-15s%s\n",
353 typeString().toLatin1().data(),
354 str.toLatin1().data());
355}
356
357QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.