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