3
* TOra - An Oracle Toolkit for DBA's and developers
4
* Copyright (C) 2003-2005 Quest Software, Inc
5
* Portions Copyright (C) 2005 Other Contributors
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; only version 2 of
10
* the License is valid for this program.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
* As a special exception, you have permission to link this program
22
* with the Oracle Client libraries and distribute executables, as long
23
* as you follow the requirements of the GNU GPL in regard to all of the
24
* software in the executable aside from Oracle client libraries.
26
* Specifically you are not permitted to link this program with the
27
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
28
* And you are not permitted to distribute binaries compiled against
29
* these libraries without written consent from Quest Software, Inc.
30
* Observe that this does not disallow linking to the Qt Free Edition.
32
* You may link this product with any GPL'd Qt library such as Qt/Free
34
* All trademarks belong to their respective owners.
47
#include <qapplication.h>
50
toHtml::toHtml(const QCString &data)
52
Length = strlen(data);
53
Data = new char[Length + 1];
64
void toHtml::skipSpace(void)
66
if (Position >= Length)
75
while (Position < Length && isspace(Data[Position]))
80
bool toHtml::eof(void)
82
if (Position > Length)
83
throw qApp->translate("toHtml", "Invalidly went beyond end of file");
84
return Position == Length;
87
void toHtml::nextToken(void)
90
throw qApp->translate("toHtml", "Reading HTML after eof");
101
if (Position >= Length)
102
throw qApp->translate("toHtml", "Lone < at end");
103
if (Data[Position] != '/')
114
size_t start = Position;
115
while (Position < Length && !isspace(Data[Position]) && Data[Position] != '>')
117
Data[Position] = tolower(Data[Position]);
120
Tag = mid(start, Position - start);
125
if (Position >= Length)
126
throw qApp->translate("toHtml", "Unended tag at end");
138
// Must always be an empty char here, so LastChar not needed to be checked.
141
size_t start = Position;
143
while (Position < Length &&
144
!isspace(Data[Position]) &&
145
Data[Position] != '=' &&
146
Data[Position] != '>')
148
Data[Position] = tolower(Data[Position]);
151
Qualifiers[QualifierNum].Name = mid(start, Position - start);
154
if (Position >= Length)
155
throw qApp->translate("toHtml", "Unended tag qualifier at end");
164
if (Position >= Length)
165
throw qApp->translate("toHtml", "Unended tag qualifier data at end");
167
if (c == '\'' || c == '\"')
170
size_t start = Position;
171
while (Data[Position] != c)
174
if (Position >= Length)
175
throw qApp->translate("toHtml", "Unended quoted string at end");
177
Qualifiers[QualifierNum].Value = mid(start, Position - start);
183
size_t start = Position;
184
while (!isspace(Data[Position]) && Data[Position] != '>')
187
if (Position >= Length)
188
throw qApp->translate("toHtml", "Unended qualifier data at end");
190
Qualifiers[QualifierNum].Value = mid(start, Position - start);
194
if (QualifierNum >= TO_HTML_MAX_QUAL)
195
throw qApp->translate("toHtml", "Exceded qualifier max in toHtml");
201
size_t start = Position;
204
while (Position < Length)
206
if (Data[Position] == '<')
210
Text = mid(start, Position - start);
214
const char *toHtml::value(const QCString &q)
216
for (int i = 0;i < QualifierNum;i++)
218
if (q == Qualifiers[i].Name)
219
return Qualifiers[i].Value;
224
QCString toHtml::text()
227
for (const char *cur = Text;*cur;cur++)
232
const char *start = cur + 1;
233
while (*cur && *cur != ';')
235
QCString tmp(start, cur - start);
238
tmp = tmp.right(tmp.length() - 1);
239
ret += char(tmp.toInt());
241
else if (tmp == "auml")
243
// The rest of the & codes...
251
const char *toHtml::mid(size_t start, size_t size)
256
throw qApp->translate("toHtml", "Tried to access string out of bounds in mid (start=%1)").arg(start);
258
throw qApp->translate("toHtml", "Tried to access string out of bounds in mid (size=%1)").arg(size);
259
if (start + size > Length)
260
throw qApp->translate("toHtml", "Tried to access string out of bounds in mid (total=%1+%2>%3)").
265
LastChar = Data[start + size];
266
Data[start + size] = 0;
270
bool toHtml::search(const QCString &all, const QString &str)
272
QCString data(str.lower().latin1());
278
} lastState = beginning, state = beginning;
279
unsigned int pos = 0;
281
for (size_t i = 0;i < all.length();i++)
283
char c = tolower(all.at(i));
284
if (c == '\'' || c == '\"')
302
if (data.at(pos) != c)
310
if (pos >= data.length())
312
if (i + 1 >= all.length() || !isalnum(all.at(i + 1)))
318
// Intentionally no break here
333
QString toHtml::escape(const QString &html)
337
static QRegExp amp(QString::fromLatin1("\\&"));
338
static QRegExp lt(QString::fromLatin1("\\<"));
339
static QRegExp gt(QString::fromLatin1("\\>"));
343
ret.replace(amp, "&");
344
ret.replace(lt, "<");
345
ret.replace(gt, ">");