1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the tools applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 /*
43   atom.h
44 */
45 
46 #ifndef ATOM_H
47 #define ATOM_H
48 
49 #include <qstringlist.h>
50 
51 #define QDOC_QML
52 
53 QT_BEGIN_NAMESPACE
54 
55 class Atom
56 {
57  public:
58     enum Type {
59         AbstractLeft,
60         AbstractRight,
61         AnnotatedList,
62         AutoLink,
63         BaseName,
64         BriefLeft,
65         BriefRight,
66         C,
67         CaptionLeft,
68         CaptionRight,
69         Code,
70         CodeBad,
71         CodeNew,
72         CodeOld,
73         CodeQuoteArgument,
74         CodeQuoteCommand,
75         DivLeft,
76         DivRight,
77         EndQmlText,
78         FootnoteLeft,
79         FootnoteRight,
80         FormatElse,
81         FormatEndif,
82         FormatIf,
83         FormattingLeft,
84         FormattingRight,
85         GeneratedList,
86         GuidLink,
87         Image,
88         ImageText,
89         InlineImage,
90         JavaScript,
91         EndJavaScript,
92         LegaleseLeft,
93         LegaleseRight,
94         LineBreak,
95         Link,
96         LinkNode,
97         ListLeft,
98         ListItemNumber,
99         ListTagLeft,
100         ListTagRight,
101         ListItemLeft,
102         ListItemRight,
103         ListRight,
104         Nop,
105         ParaLeft,
106         ParaRight,
107         Qml,
108         QmlText,
109         QuotationLeft,
110         QuotationRight,
111         RawString,
112         SectionLeft,
113         SectionRight,
114         SectionHeadingLeft,
115         SectionHeadingRight,
116         SidebarLeft,
117         SidebarRight,
118         SinceList,
119         SnippetCommand,
120         SnippetIdentifier,
121         SnippetLocation,
122         String,
123         TableLeft,
124         TableRight,
125         TableHeaderLeft,
126         TableHeaderRight,
127         TableRowLeft,
128         TableRowRight,
129         TableItemLeft,
130         TableItemRight,
131         TableOfContents,
132         Target,
133         UnhandledFormat,
134         UnknownCommand,
135         Last = UnknownCommand
136     };
137 
138     Atom(Type type, const QString& string = "")
139 	: nxt(0), typ(type)
140     {
141         strs << string;
142     }
143 
Atom(Type type,const QString & p1,const QString & p2)144     Atom(Type type, const QString& p1, const QString& p2)
145 	: nxt(0), typ(type)
146     {
147         strs << p1;
148         if (!p2.isEmpty())
149             strs << p2;
150     }
151 
152     Atom(Atom* prev, Type type, const QString& string = "")
153 	: nxt(prev->nxt), typ(type)
154     {
155         strs << string;
156         prev->nxt = this;
157     }
158 
Atom(Atom * prev,Type type,const QString & p1,const QString & p2)159     Atom(Atom* prev, Type type, const QString& p1, const QString& p2)
160 	: nxt(prev->nxt), typ(type)
161     {
162         strs << p1;
163         if (!p2.isEmpty())
164             strs << p2;
165         prev->nxt = this;
166     }
167 
appendChar(QChar ch)168     void appendChar(QChar ch) { strs[0] += ch; }
appendString(const QString & string)169     void appendString(const QString& string) { strs[0] += string; }
chopString()170     void chopString() { strs[0].chop(1); }
setString(const QString & string)171     void setString(const QString& string) { strs[0] = string; }
next()172     Atom* next() { return nxt; }
setNext(Atom * newNext)173     void setNext(Atom* newNext) { nxt = newNext; }
174 
next()175     const Atom* next() const { return nxt; }
176     const Atom* next(Type t) const;
177     const Atom* next(Type t, const QString& s) const;
type()178     Type type() const { return typ; }
179     QString typeString() const;
string()180     const QString& string() const { return strs[0]; }
string(int i)181     const QString& string(int i) const { return strs[i]; }
count()182     int count() const { return strs.size(); }
183     void dump() const;
184 
185     static QString BOLD_;
186     static QString INDEX_;
187     static QString ITALIC_;
188     static QString LINK_;
189     static QString PARAMETER_;
190     static QString SPAN_;
191     static QString SUBSCRIPT_;
192     static QString SUPERSCRIPT_;
193     static QString TELETYPE_;
194     static QString UNDERLINE_;
195 
196     static QString BULLET_;
197     static QString TAG_;
198     static QString VALUE_;
199     static QString LOWERALPHA_;
200     static QString LOWERROMAN_;
201     static QString NUMERIC_;
202     static QString UPPERALPHA_;
203     static QString UPPERROMAN_;
204 
205  private:
206     Atom* nxt;
207     Type typ;
208     QStringList strs;
209 };
210 
211 #define ATOM_FORMATTING_BOLD            "bold"
212 #define ATOM_FORMATTING_INDEX           "index"
213 #define ATOM_FORMATTING_ITALIC          "italic"
214 #define ATOM_FORMATTING_LINK            "link"
215 #define ATOM_FORMATTING_PARAMETER       "parameter"
216 #define ATOM_FORMATTING_SPAN            "span "
217 #define ATOM_FORMATTING_SUBSCRIPT       "subscript"
218 #define ATOM_FORMATTING_SUPERSCRIPT     "superscript"
219 #define ATOM_FORMATTING_TELETYPE        "teletype"
220 #define ATOM_FORMATTING_UNDERLINE       "underline"
221 
222 #define ATOM_LIST_BULLET                "bullet"
223 #define ATOM_LIST_TAG                   "tag"
224 #define ATOM_LIST_VALUE                 "value"
225 #define ATOM_LIST_LOWERALPHA            "loweralpha"
226 #define ATOM_LIST_LOWERROMAN            "lowerroman"
227 #define ATOM_LIST_NUMERIC               "numeric"
228 #define ATOM_LIST_UPPERALPHA            "upperalpha"
229 #define ATOM_LIST_UPPERROMAN            "upperroman"
230 
231 QT_END_NAMESPACE
232 
233 #endif
234