Qt 4.8
Classes | Macros | Functions | Variables
qtexthtmlparser.cpp File Reference
#include "qtexthtmlparser_p.h"
#include <qbytearray.h>
#include <qtextcodec.h>
#include <qapplication.h>
#include <qstack.h>
#include <qdebug.h>
#include <qthread.h>
#include "qtextdocument.h"
#include "qtextformat_p.h"
#include "qtextdocument_p.h"
#include "qtextcursor.h"
#include "qfont_p.h"
#include "private/qfunctions_p.h"

Go to the source code of this file.

Classes

struct  QTextHtmlEntity
 
class  QTextHtmlStyleSelector
 

Macros

#define MAX_ENTITY   258
 

Functions

static int findAttribute (const QStringList &attributes, const QString &name)
 
static const QTextHtmlElementlookupElementHelper (const QString &element)
 
Q_STATIC_GLOBAL_OPERATOR bool operator< (const QString &entityStr, const QTextHtmlEntity &entity)
 
Q_STATIC_GLOBAL_OPERATOR bool operator< (const QTextHtmlEntity &entity, const QString &entityStr)
 
Q_STATIC_GLOBAL_OPERATOR bool operator< (const QString &str, const QTextHtmlElement &e)
 
Q_STATIC_GLOBAL_OPERATOR bool operator< (const QTextHtmlElement &e, const QString &str)
 
static QString quoteNewline (const QString &s)
 
static QChar resolveEntity (const QString &entity)
 
static bool setFloatAttribute (qreal *destination, const QString &value)
 
static bool setIntAttribute (int *destination, const QString &value)
 
static void setWidthAttribute (QTextLength *width, QString value)
 

Variables

static const QTextHtmlElement elements [Html_NumElements]
 
static const struct QTextHtmlEntity entities [MAX_ENTITY]
 
static const ushort windowsLatin1ExtendedCharacters [0xA0 - 0x80]
 

Macro Definition Documentation

◆ MAX_ENTITY

#define MAX_ENTITY   258

Definition at line 63 of file qtexthtmlparser.cpp.

Referenced by resolveEntity().

Function Documentation

◆ findAttribute()

static int findAttribute ( const QStringList attributes,
const QString name 
)
inlinestatic

Definition at line 1755 of file qtexthtmlparser.cpp.

Referenced by QTextHtmlStyleSelector::attribute().

1756 {
1757  int idx = -1;
1758  do {
1759  idx = attributes.indexOf(name, idx + 1);
1760  } while (idx != -1 && (idx % 2 == 1));
1761  return idx;
1762 }
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
Definition: qstringlist.h:195

◆ lookupElementHelper()

static const QTextHtmlElement* lookupElementHelper ( const QString element)
static

Definition at line 455 of file qtexthtmlparser.cpp.

Referenced by QTextHtmlParser::lookupElement(), and QTextHtmlParser::parseTag().

456 {
457  const QTextHtmlElement *start = &elements[0];
459  const QTextHtmlElement *e = qBinaryFind(start, end, element);
460  if (e == end)
461  return 0;
462  return e;
463 }
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:295
static const QTextHtmlElement elements[Html_NumElements]
static const KeyPair *const end

◆ operator<() [1/4]

Q_STATIC_GLOBAL_OPERATOR bool operator< ( const QString entityStr,
const QTextHtmlEntity entity 
)

Definition at line 325 of file qtexthtmlparser.cpp.

326 {
327  return entityStr < QLatin1String(entity.name);
328 }
const char * name
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ operator<() [2/4]

Q_STATIC_GLOBAL_OPERATOR bool operator< ( const QTextHtmlEntity entity,
const QString entityStr 
)

Definition at line 330 of file qtexthtmlparser.cpp.

331 {
332  return QLatin1String(entity.name) < entityStr;
333 }
const char * name
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ operator<() [3/4]

Q_STATIC_GLOBAL_OPERATOR bool operator< ( const QString str,
const QTextHtmlElement e 
)

Definition at line 445 of file qtexthtmlparser.cpp.

446 {
447  return str < QLatin1String(e.name);
448 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ operator<() [4/4]

Q_STATIC_GLOBAL_OPERATOR bool operator< ( const QTextHtmlElement e,
const QString str 
)

Definition at line 450 of file qtexthtmlparser.cpp.

451 {
452  return QLatin1String(e.name) < str;
453 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ quoteNewline()

static QString quoteNewline ( const QString s)
static

Definition at line 474 of file qtexthtmlparser.cpp.

Referenced by QTextHtmlParser::dumpHtml().

475 {
476  QString n = s;
477  n.replace(QLatin1Char('\n'), QLatin1String("\\n"));
478  return n;
479 }
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ resolveEntity()

static QChar resolveEntity ( const QString entity)
static

Definition at line 335 of file qtexthtmlparser.cpp.

Referenced by QTextHtmlParser::parseEntity(), QXmlDefaultHandler::~QXmlDefaultHandler(), and QXmlEntityResolver::~QXmlEntityResolver().

336 {
337  const QTextHtmlEntity *start = &entities[0];
339  const QTextHtmlEntity *e = qBinaryFind(start, end, entity);
340  if (e == end)
341  return QChar();
342  return e->code;
343 }
static const struct QTextHtmlEntity entities[MAX_ENTITY]
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:295
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
#define MAX_ENTITY
static const KeyPair *const end

◆ setFloatAttribute()

static bool setFloatAttribute ( qreal destination,
const QString value 
)
static

Definition at line 1449 of file qtexthtmlparser.cpp.

Referenced by QTextHtmlParser::applyAttributes().

1450 {
1451  bool ok = false;
1452  qreal val = value.toDouble(&ok);
1453  if (ok)
1454  *destination = val;
1455 
1456  return ok;
1457 }
double qreal
Definition: qglobal.h:1193
double toDouble(bool *ok=0) const
Returns the string converted to a double value.
Definition: qstring.cpp:6227

◆ setIntAttribute()

static bool setIntAttribute ( int *  destination,
const QString value 
)
static

Definition at line 1439 of file qtexthtmlparser.cpp.

Referenced by QTextHtmlParser::applyAttributes().

1440 {
1441  bool ok = false;
1442  int val = value.toInt(&ok);
1443  if (ok)
1444  *destination = val;
1445 
1446  return ok;
1447 }
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090

◆ setWidthAttribute()

static void setWidthAttribute ( QTextLength width,
QString  value 
)
static

Definition at line 1459 of file qtexthtmlparser.cpp.

Referenced by QTextHtmlParser::applyAttributes().

1460 {
1461  bool ok = false;
1462  qreal realVal = value.toDouble(&ok);
1463  if (ok) {
1464  *width = QTextLength(QTextLength::FixedLength, realVal);
1465  } else {
1466  value = value.trimmed();
1467  if (!value.isEmpty() && value.endsWith(QLatin1Char('%'))) {
1468  value.chop(1);
1469  realVal = value.toDouble(&ok);
1470  if (ok)
1471  *width = QTextLength(QTextLength::PercentageLength, realVal);
1472  }
1473  }
1474 }
double qreal
Definition: qglobal.h:1193
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
double toDouble(bool *ok=0) const
Returns the string converted to a double value.
Definition: qstring.cpp:6227
The QTextLength class encapsulates the different types of length used in a QTextDocument.
Definition: qtextformat.h:84
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Variable Documentation

◆ elements

const QTextHtmlElement elements[Html_NumElements]
static

◆ entities

const struct QTextHtmlEntity entities[MAX_ENTITY]
static

Referenced by resolveEntity().

◆ windowsLatin1ExtendedCharacters

const ushort windowsLatin1ExtendedCharacters[0xA0 - 0x80]
static

Definition at line 345 of file qtexthtmlparser.cpp.

Referenced by QTextHtmlParser::parseEntity().