Qt 4.8
Classes | Macros | Typedefs | Enumerations | Functions | Variables
qxml.cpp File Reference
#include "qxml.h"
#include "qtextcodec.h"
#include "qbuffer.h"
#include "qregexp.h"
#include "qmap.h"
#include "qhash.h"
#include "qstack.h"
#include <qdebug.h>

Go to the source code of this file.

Classes

class  QXmlAttributesPrivate
 
class  QXmlDefaultHandlerPrivate
 
class  QXmlInputSourcePrivate
 
class  QXmlLocatorPrivate
 
class  QXmlNamespaceSupportPrivate
 
class  QXmlParseExceptionPrivate
 
class  QXmlSimpleReaderLocator
 
class  QXmlSimpleReaderPrivate
 
struct  QXmlSimpleReaderPrivate::ExternEntity
 
struct  QXmlSimpleReaderPrivate::ExternParameterEntity
 
struct  QXmlSimpleReaderPrivate::ParseState
 
struct  QXmlSimpleReaderPrivate::XmlRef
 

Macros

#define XMLERR_EDECLORSDDECLEXPECTED   QT_TRANSLATE_NOOP("QXml", "encoding declaration or standalone declaration expected while reading the XML declaration")
 
#define XMLERR_ERRORBYCONSUMER   QT_TRANSLATE_NOOP("QXml", "error triggered by consumer")
 
#define XMLERR_ERRORINTEXTDECL   QT_TRANSLATE_NOOP("QXml", "error in the text declaration of an external entity")
 
#define XMLERR_ERRORPARSINGCOMMENT   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing comment")
 
#define XMLERR_ERRORPARSINGCONTENT   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing content")
 
#define XMLERR_ERRORPARSINGDOCTYPE   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing document type definition")
 
#define XMLERR_ERRORPARSINGELEMENT   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing element")
 
#define XMLERR_ERRORPARSINGREFERENCE   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing reference")
 
#define XMLERR_EXTERNALGENERALENTITYINAV   QT_TRANSLATE_NOOP("QXml", "external parsed general entity reference not allowed in attribute value")
 
#define XMLERR_EXTERNALGENERALENTITYINDTD   QT_TRANSLATE_NOOP("QXml", "external parsed general entity reference not allowed in DTD")
 
#define XMLERR_INTERNALGENERALENTITYINDTD   QT_TRANSLATE_NOOP("QXml", "internal general entity reference not allowed in DTD")
 
#define XMLERR_INVALIDNAMEFORPI   QT_TRANSLATE_NOOP("QXml", "invalid name for processing instruction")
 
#define XMLERR_LETTEREXPECTED   QT_TRANSLATE_NOOP("QXml", "letter is expected")
 
#define XMLERR_MORETHANONEDOCTYPE   QT_TRANSLATE_NOOP("QXml", "more than one document type definition")
 
#define XMLERR_OK   QT_TRANSLATE_NOOP("QXml", "no error occurred")
 
#define XMLERR_RECURSIVEENTITIES   QT_TRANSLATE_NOOP("QXml", "recursive entities")
 
#define XMLERR_SDDECLEXPECTED   QT_TRANSLATE_NOOP("QXml", "standalone declaration expected while reading the XML declaration")
 
#define XMLERR_TAGMISMATCH   QT_TRANSLATE_NOOP("QXml", "tag mismatch")
 
#define XMLERR_UNEXPECTEDCHARACTER   QT_TRANSLATE_NOOP("QXml", "unexpected character")
 
#define XMLERR_UNEXPECTEDEOF   QT_TRANSLATE_NOOP("QXml", "unexpected end of file")
 
#define XMLERR_UNPARSEDENTITYREFERENCE   QT_TRANSLATE_NOOP("QXml", "unparsed entity reference in wrong context")
 
#define XMLERR_VERSIONEXPECTED   QT_TRANSLATE_NOOP("QXml", "version expected while reading the XML declaration")
 
#define XMLERR_WRONGVALUEFORSDECL   QT_TRANSLATE_NOOP("QXml", "wrong value for standalone declaration")
 

Typedefs

typedef QMap< QString, QStringNamespaceMap
 

Enumerations

enum  NameChar {
  NameBeginning, NameNotBeginning, NotName, NameBeginning,
  NameNotBeginning, NotName
}
 

Functions

static NameChar determineNameChar (QChar ch)
 
static QString extractEncodingDecl (const QString &text, bool *needMoreText)
 
static NameChar fastDetermineNameChar (QChar ch)
 
static bool is_S (QChar ch)
 
static bool stripTextDecl (QString &str)
 
static void updateValue (QString &value, const QChar *array, int &arrayPos, int &valueLen)
 

Variables

static const char Begi = (char)NameBeginning
 
static const signed char charLookupTable [256]
 
static const signed char cltAmp = 2
 
static const signed char cltCB = 9
 
static const signed char cltDash = 8
 
static const signed char cltDq = 12
 
static const signed char cltEm = 7
 
static const signed char cltEq = 11
 
static const signed char cltGt = 3
 
static const signed char cltLt = 4
 
static const signed char cltOB = 10
 
static const signed char cltPer = 1
 
static const signed char cltQm = 6
 
static const signed char cltSlash = 5
 
static const signed char cltSq = 13
 
static const signed char cltUnknown = 14
 
static const signed char cltWS = 0
 
static const char nameCharTable [128]
 
static const char NotN = (char)NotName
 
static const char NtBg = (char)NameNotBeginning
 
bool qt_xml_skipped_entity_in_content
 

Macro Definition Documentation

◆ XMLERR_EDECLORSDDECLEXPECTED

#define XMLERR_EDECLORSDDECLEXPECTED   QT_TRANSLATE_NOOP("QXml", "encoding declaration or standalone declaration expected while reading the XML declaration")

Definition at line 70 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parsePI().

◆ XMLERR_ERRORBYCONSUMER

#define XMLERR_ERRORBYCONSUMER   QT_TRANSLATE_NOOP("QXml", "error triggered by consumer")

Definition at line 60 of file qxml.cpp.

Referenced by QXmlDefaultHandler::errorString().

◆ XMLERR_ERRORINTEXTDECL

#define XMLERR_ERRORINTEXTDECL   QT_TRANSLATE_NOOP("QXml", "error in the text declaration of an external entity")

◆ XMLERR_ERRORPARSINGCOMMENT

#define XMLERR_ERRORPARSINGCOMMENT   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing comment")

Definition at line 74 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parseComment().

◆ XMLERR_ERRORPARSINGCONTENT

#define XMLERR_ERRORPARSINGCONTENT   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing content")

Definition at line 65 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parseContent().

◆ XMLERR_ERRORPARSINGDOCTYPE

#define XMLERR_ERRORPARSINGDOCTYPE   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing document type definition")

Definition at line 72 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parseDoctype().

◆ XMLERR_ERRORPARSINGELEMENT

#define XMLERR_ERRORPARSINGELEMENT   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing element")

◆ XMLERR_ERRORPARSINGREFERENCE

#define XMLERR_ERRORPARSINGREFERENCE   QT_TRANSLATE_NOOP("QXml", "error occurred while parsing reference")

Definition at line 75 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parseReference().

◆ XMLERR_EXTERNALGENERALENTITYINAV

#define XMLERR_EXTERNALGENERALENTITYINAV   QT_TRANSLATE_NOOP("QXml", "external parsed general entity reference not allowed in attribute value")

Definition at line 77 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::processReference().

◆ XMLERR_EXTERNALGENERALENTITYINDTD

#define XMLERR_EXTERNALGENERALENTITYINDTD   QT_TRANSLATE_NOOP("QXml", "external parsed general entity reference not allowed in DTD")

Definition at line 78 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::processReference().

◆ XMLERR_INTERNALGENERALENTITYINDTD

#define XMLERR_INTERNALGENERALENTITYINDTD   QT_TRANSLATE_NOOP("QXml", "internal general entity reference not allowed in DTD")

Definition at line 76 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::processReference().

◆ XMLERR_INVALIDNAMEFORPI

#define XMLERR_INVALIDNAMEFORPI   QT_TRANSLATE_NOOP("QXml", "invalid name for processing instruction")

Definition at line 67 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parsePI().

◆ XMLERR_LETTEREXPECTED

#define XMLERR_LETTEREXPECTED   QT_TRANSLATE_NOOP("QXml", "letter is expected")

◆ XMLERR_MORETHANONEDOCTYPE

#define XMLERR_MORETHANONEDOCTYPE   QT_TRANSLATE_NOOP("QXml", "more than one document type definition")

Definition at line 62 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parseProlog().

◆ XMLERR_OK

#define XMLERR_OK   QT_TRANSLATE_NOOP("QXml", "no error occurred")

Definition at line 59 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::reportParseError().

◆ XMLERR_RECURSIVEENTITIES

#define XMLERR_RECURSIVEENTITIES   QT_TRANSLATE_NOOP("QXml", "recursive entities")

Definition at line 80 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::insertXmlRef().

◆ XMLERR_SDDECLEXPECTED

#define XMLERR_SDDECLEXPECTED   QT_TRANSLATE_NOOP("QXml", "standalone declaration expected while reading the XML declaration")

Definition at line 71 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parsePI().

◆ XMLERR_TAGMISMATCH

#define XMLERR_TAGMISMATCH   QT_TRANSLATE_NOOP("QXml", "tag mismatch")

◆ XMLERR_UNEXPECTEDCHARACTER

#define XMLERR_UNEXPECTEDCHARACTER   QT_TRANSLATE_NOOP("QXml", "unexpected character")

◆ XMLERR_UNEXPECTEDEOF

#define XMLERR_UNEXPECTEDEOF   QT_TRANSLATE_NOOP("QXml", "unexpected end of file")

◆ XMLERR_UNPARSEDENTITYREFERENCE

#define XMLERR_UNPARSEDENTITYREFERENCE   QT_TRANSLATE_NOOP("QXml", "unparsed entity reference in wrong context")

Definition at line 79 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::processReference().

◆ XMLERR_VERSIONEXPECTED

#define XMLERR_VERSIONEXPECTED   QT_TRANSLATE_NOOP("QXml", "version expected while reading the XML declaration")

Definition at line 68 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parsePI().

◆ XMLERR_WRONGVALUEFORSDECL

#define XMLERR_WRONGVALUEFORSDECL   QT_TRANSLATE_NOOP("QXml", "wrong value for standalone declaration")

Definition at line 69 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parsePI().

Typedef Documentation

◆ NamespaceMap

Definition at line 721 of file qxml.cpp.

Enumeration Type Documentation

◆ NameChar

enum NameChar
Enumerator
NameBeginning 
NameNotBeginning 
NotName 
NameBeginning 
NameNotBeginning 
NotName 

Definition at line 3386 of file qxml.cpp.

Function Documentation

◆ determineNameChar()

static NameChar determineNameChar ( QChar  ch)
static

Definition at line 3437 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parseAttribute(), QXmlSimpleReaderPrivate::parseNmtoken(), and QXmlSimpleReaderPrivate::parsePI().

3438 {
3439  return fastDetermineNameChar(ch);
3440 }
static NameChar fastDetermineNameChar(QChar ch)
Definition: qxml.cpp:3420

◆ extractEncodingDecl()

static QString extractEncodingDecl ( const QString text,
bool *  needMoreText 
)
static

Definition at line 1596 of file qxml.cpp.

Referenced by QXmlInputSource::fromRawData().

1597 {
1598  *needMoreText = false;
1599 
1600  int l = text.length();
1601  QString snip = QString::fromLatin1("<?xml").left(l);
1602  if (l > 0 && !text.startsWith(snip))
1603  return QString();
1604 
1605  int endPos = text.indexOf(QLatin1Char('>'));
1606  if (endPos == -1) {
1607  *needMoreText = l < 255; // we won't look forever
1608  return QString();
1609  }
1610 
1611  int pos = text.indexOf(QLatin1String("encoding"));
1612  if (pos == -1 || pos >= endPos)
1613  return QString();
1614 
1615  while (pos < endPos) {
1616  ushort uc = text.at(pos).unicode();
1617  if (uc == '\'' || uc == '"')
1618  break;
1619  ++pos;
1620  }
1621 
1622  if (pos == endPos)
1623  return QString();
1624 
1625  QString encoding;
1626  ++pos;
1627  while (pos < endPos) {
1628  ushort uc = text.at(pos).unicode();
1629  if (uc == '\'' || uc == '"')
1630  break;
1631  encoding.append(uc);
1632  ++pos;
1633  }
1634 
1635  return encoding;
1636 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QString & append(QChar c)
Definition: qstring.cpp:1777
unsigned short ushort
Definition: qglobal.h:995
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QFactoryLoader * l
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ fastDetermineNameChar()

static NameChar fastDetermineNameChar ( QChar  ch)
inlinestatic

Definition at line 3420 of file qxml.cpp.

Referenced by determineNameChar(), QXmlSimpleReaderPrivate::parseElement(), and QXmlSimpleReaderPrivate::parseName().

3421 {
3422  ushort uc = ch.unicode();
3423  if (!(uc & ~0x7f)) // uc < 128
3424  return (NameChar)nameCharTable[uc];
3425 
3426  QChar::Category cat = ch.category();
3427  // ### some these categories might be slightly wrong
3428  if ((cat >= QChar::Letter_Uppercase && cat <= QChar::Letter_Other)
3429  || cat == QChar::Number_Letter)
3430  return NameBeginning;
3431  if ((cat >= QChar::Number_DecimalDigit && cat <= QChar::Number_Other)
3432  || (cat >= QChar::Mark_NonSpacing && cat <= QChar::Mark_Enclosing))
3433  return NameNotBeginning;
3434  return NotName;
3435 }
Category
This enum maps the Unicode character categories.
Definition: qchar.h:106
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
static const char nameCharTable[128]
Definition: qxml.cpp:3392
Category category() const
Returns the character&#39;s category.
Definition: qchar.cpp:853
NameChar
unsigned short ushort
Definition: qglobal.h:995

◆ is_S()

static bool is_S ( QChar  ch)
inlinestatic

◆ stripTextDecl()

static bool stripTextDecl ( QString str)
static

Definition at line 189 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parsePEReference(), and QXmlSimpleReaderPrivate::processReference().

190 {
191  QString textDeclStart(QLatin1String("<?xml"));
192  if (str.startsWith(textDeclStart)) {
193  QRegExp textDecl(QString::fromLatin1(
194  "^<\\?xml\\s+"
195  "(version\\s*=\\s*((['\"])[-a-zA-Z0-9_.:]+\\3))?"
196  "\\s*"
197  "(encoding\\s*=\\s*((['\"])[A-Za-z][-a-zA-Z0-9_.]*\\6))?"
198  "\\s*\\?>"
199  ));
200  QString strTmp = str.replace(textDecl, QLatin1String(""));
201  if (strTmp.length() != str.length())
202  return false; // external entity has wrong TextDecl
203  str = strTmp;
204  }
205  return true;
206 }
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ updateValue()

static void updateValue ( QString value,
const QChar array,
int &  arrayPos,
int &  valueLen 
)
inlinestatic

Definition at line 8481 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::name(), QXmlSimpleReaderPrivate::nameAddC(), QXmlSimpleReaderPrivate::ref(), QXmlSimpleReaderPrivate::refAddC(), QXmlSimpleReaderPrivate::string(), and QXmlSimpleReaderPrivate::stringAddC().

8482 {
8483  value.resize(valueLen + arrayPos);
8484  memcpy(value.data() + valueLen, array, arrayPos * sizeof(QChar));
8485  valueLen += arrayPos;
8486  arrayPos = 0;
8487 }
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353

Variable Documentation

◆ Begi

const char Begi = (char)NameBeginning
static

Definition at line 3388 of file qxml.cpp.

◆ charLookupTable

const signed char charLookupTable[256]
static

Definition at line 107 of file qxml.cpp.

Referenced by QXmlSimpleReaderPrivate::parseContent().

◆ cltAmp

const signed char cltAmp = 2
static

Definition at line 88 of file qxml.cpp.

◆ cltCB

const signed char cltCB = 9
static

Definition at line 95 of file qxml.cpp.

◆ cltDash

const signed char cltDash = 8
static

Definition at line 94 of file qxml.cpp.

◆ cltDq

const signed char cltDq = 12
static

Definition at line 98 of file qxml.cpp.

◆ cltEm

const signed char cltEm = 7
static

Definition at line 93 of file qxml.cpp.

◆ cltEq

const signed char cltEq = 11
static

Definition at line 97 of file qxml.cpp.

◆ cltGt

const signed char cltGt = 3
static

Definition at line 89 of file qxml.cpp.

◆ cltLt

const signed char cltLt = 4
static

Definition at line 90 of file qxml.cpp.

◆ cltOB

const signed char cltOB = 10
static

Definition at line 96 of file qxml.cpp.

◆ cltPer

const signed char cltPer = 1
static

Definition at line 87 of file qxml.cpp.

◆ cltQm

const signed char cltQm = 6
static

Definition at line 92 of file qxml.cpp.

◆ cltSlash

const signed char cltSlash = 5
static

Definition at line 91 of file qxml.cpp.

◆ cltSq

const signed char cltSq = 13
static

Definition at line 99 of file qxml.cpp.

◆ cltUnknown

const signed char cltUnknown = 14
static

Definition at line 100 of file qxml.cpp.

◆ cltWS

const signed char cltWS = 0
static

Definition at line 86 of file qxml.cpp.

◆ nameCharTable

const char nameCharTable[128]
static
Initial value:

Definition at line 3392 of file qxml.cpp.

◆ NotN

const char NotN = (char)NotName
static

Definition at line 3390 of file qxml.cpp.

◆ NtBg

const char NtBg = (char)NameNotBeginning
static

Definition at line 3389 of file qxml.cpp.

◆ qt_xml_skipped_entity_in_content

bool qt_xml_skipped_entity_in_content