Qt 4.8
Classes | Public Functions | Public Variables | Private Functions | Properties | List of all members
QXmlStreamReaderPrivate Class Reference

#include <qxmlstream_p.h>

Inheritance diagram for QXmlStreamReaderPrivate:
QXmlStreamReader_Table QXmlStreamPrivateTagStack

Classes

struct  Attribute
 
struct  DtdAttribute
 
struct  Entity
 
struct  EntityDeclaration
 
struct  NotationDeclaration
 
struct  Value
 

Public Functions

void checkPublicLiteral (const QStringRef &publicId)
 
bool checkStartDocument ()
 
void clearSym ()
 
void clearTextBuffer ()
 
void consumeRule (int)
 
bool entitiesMustBeDeclared () const
 
int fastScanContentCharList ()
 Used for text nodes essentially. More...
 
int fastScanLiteralContent ()
 
int fastScanName (int *prefix=0)
 
int fastScanNMTOKEN ()
 
int fastScanSpace ()
 
uint filterCarriageReturn ()
 
uint getChar ()
 
ushort getChar_helper ()
 
void init ()
 
void injectToken (ushort tokenToInject)
 
QStringRef namespaceForPrefix (const QStringRef &prefix)
 
bool parse ()
 
void parseEntity (const QString &value)
 
void parseError ()
 
uint peekChar ()
 
void putChar (uint c)
 
void putChar (QChar c)
 
void putReplacement (const QString &s)
 
void putReplacementInAttributeValue (const QString &s)
 
void putString (const QString &s, int from=0)
 
void putStringLiteral (const QString &s)
 
 QXmlStreamReaderPrivate (QXmlStreamReader *q)
 
void raiseError (QXmlStreamReader::Error error, const QString &message=QString())
 
void raiseWellFormedError (const QString &message)
 
void reallocateStack ()
 
bool referenceEntity (Entity &entity)
 
uint resolveCharRef (int symbolIndex)
 
void resolveDtd ()
 
void resolvePublicNamespaces ()
 
void resolveTag ()
 
QString resolveUndeclaredEntity (const QString &name)
 
void resume (int rule)
 
bool scanAfterDefaultDecl ()
 
bool scanAfterLangleBang ()
 
bool scanAttType ()
 
bool scanNData ()
 
bool scanPublicOrSystem ()
 
bool scanString (const char *str, short tokenToInject, bool requireSpace=true)
 
bool scanUntil (const char *str, short tokenToInject=-1)
 Scans characters until str is encountered, and validates the characters as according to the Char[2] production and do the line-ending normalization. More...
 
void startDocument ()
 
Valuesym (int index) const
 
QStringRef symName (int index)
 
QStringRef symName (const Value &symbol)
 
QStringRef symPrefix (int index)
 
QStringRef symPrefix (const Value &symbol)
 
QStringRef symString (int index)
 
QStringRef symString (int index, int offset)
 
QStringRef symString (const Value &symbol)
 
void write (const QString &)
 
void write (const char *)
 
 ~QXmlStreamReaderPrivate ()
 
- Public Functions inherited from QXmlStreamPrivateTagStack
QStringRef addToStringStorage (const QStringRef &s)
 
QStringRef addToStringStorage (const QString &s)
 
 QXmlStreamPrivateTagStack ()
 
TagtagStack_pop ()
 
TagtagStack_push ()
 

Public Variables

bool atEnd
 
QXmlStreamAttributes attributes
 
QXmlStreamSimpleStack< AttributeattributeStack
 
qint64 characterOffset
 
QTextCodeccodec
 
QByteArray dataBuffer
 
QTextDecoderdecoder
 
bool deleteDevice
 
QIODevicedevice
 
QStringRef documentEncoding
 
QStringRef documentVersion
 
QXmlStreamSimpleStack< DtdAttributedtdAttributes
 
QStringRef dtdName
 
QStringRef dtdPublicId
 
QStringRef dtdSystemId
 
QXmlStreamSimpleStack< EntityDeclarationentityDeclarations
 
QHash< QString, EntityentityHash
 
QXmlStreamReaderPrivateentityParser
 
QXmlStreamSimpleStack< Entity * > entityReferenceStack
 
QXmlStreamEntityResolverentityResolver
 
QXmlStreamReader::Error error
 
QString errorString
 
uchar firstByte
 
uint hasCheckedStartDocument: 1
 
uint hasExternalDtdSubset: 1
 
uint hasSeenTag: 1
 
uint inParseEntity: 1
 
uint isCDATA: 1
 
uint isEmptyElement: 1
 
uint isWhitespace: 1
 
bool lastAttributeIsCData
 
QStringRef lastAttributeValue
 
qint64 lastLineStart
 
qint64 lineNumber
 
uint lockEncoding: 1
 
QStringRef name
 
uint namespaceProcessing: 1
 
QStringRef namespaceUri
 
qint64 nbytesread
 
uint normalizeLiterals: 1
 
QXmlStreamSimpleStack< NotationDeclarationnotationDeclarations
 
QHash< QString, EntityparameterEntityHash
 
QStringRef prefix
 
QStringRef processingInstructionData
 
QStringRef processingInstructionTarget
 
QXmlStreamEntityDeclarations publicEntityDeclarations
 
QXmlStreamNamespaceDeclarations publicNamespaceDeclarations
 
QXmlStreamNotationDeclarations publicNotationDeclarations
 
QXmlStreamSimpleStack< uintputStack
 
QStringRef qualifiedName
 
QByteArray rawReadBuffer
 
QString readBuffer
 
int readBufferPos
 
uint referenceToParameterEntityDetected: 1
 
uint referenceToUnparsedEntityDetected: 1
 
int resumeReduction
 
bool scanDtd
 
int stack_size
 
uint standalone: 1
 
int * state_stack
 
Valuesym_stack
 
QStringRef text
 
QString textBuffer
 
short token
 
ushort token_char
 
int tos
 
QXmlStreamReader::TokenType type
 
QString unresolvedEntity
 
- Public Variables inherited from QXmlStreamPrivateTagStack
QXmlStreamSimpleStack< NamespaceDeclarationnamespaceDeclarations
 
bool tagsDone
 
QXmlStreamSimpleStack< TagtagStack
 
QString tagStackStringStorage
 
int tagStackStringStorageSize
 

Private Functions

void setType (const QXmlStreamReader::TokenType t)
 Never assign to variable type directly. More...
 

Properties

QXmlStreamReaderq_ptr
 

Additional Inherited Members

- Public Types inherited from QXmlStreamReader_Table
enum  VariousConstants {
  EOF_SYMBOL = 0, AMPERSAND = 5, ANY = 41, ATTLIST = 31,
  BANG = 25, CDATA = 47, CDATA_START = 28, COLON = 17,
  COMMA = 19, DASH = 20, DBLQUOTE = 8, DIGIT = 27,
  DOCTYPE = 29, DOT = 23, ELEMENT = 30, EMPTY = 40,
  ENTITIES = 51, ENTITY = 32, ENTITY_DONE = 45, EQ = 14,
  ERROR = 43, FIXED = 39, HASH = 6, ID = 48,
  IDREF = 49, IDREFS = 50, IMPLIED = 38, LANGLE = 3,
  LBRACK = 9, LETTER = 26, LPAREN = 11, NDATA = 36,
  NMTOKEN = 52, NMTOKENS = 53, NOTATION = 33, NOTOKEN = 1,
  PARSE_ENTITY = 44, PCDATA = 42, PERCENT = 15, PIPE = 13,
  PLUS = 21, PUBLIC = 35, QUESTIONMARK = 24, QUOTE = 7,
  RANGLE = 4, RBRACK = 10, REQUIRED = 37, RPAREN = 12,
  SEMICOLON = 18, SHIFT_THERE = 56, SLASH = 16, SPACE = 2,
  STAR = 22, SYSTEM = 34, UNRESOLVED_ENTITY = 46, VERSION = 55,
  XML = 54, ACCEPT_STATE = 416, RULE_COUNT = 270, STATE_COUNT = 427,
  TERMINAL_COUNT = 57, NON_TERMINAL_COUNT = 84, GOTO_INDEX_OFFSET = 427, GOTO_INFO_OFFSET = 1017,
  GOTO_CHECK_OFFSET = 1017
}
 
- Static Public Functions inherited from QXmlStreamReader_Table
static int nt_action (int state, int nt)
 
static int t_action (int state, int token)
 
- Static Public Variables inherited from QXmlStreamReader_Table
static const short action_check []
 
static const short action_default []
 
static const short action_index []
 
static const short action_info []
 
static const short goto_default []
 
static const short lhs []
 
static const short rhs []
 
static const char *const spell []
 

Detailed Description

Definition at line 742 of file qxmlstream_p.h.

Constructors and Destructors

◆ QXmlStreamReaderPrivate()

QXmlStreamReaderPrivate::QXmlStreamReaderPrivate ( QXmlStreamReader q)

Definition at line 819 of file qxmlstream.cpp.

Referenced by parseEntity().

820  :q_ptr(q)
821 {
822  device = 0;
823  deleteDevice = false;
824 #ifndef QT_NO_TEXTCODEC
825  decoder = 0;
826 #endif
827  stack_size = 64;
828  sym_stack = 0;
829  state_stack = 0;
830  reallocateStack();
831  entityResolver = 0;
832  init();
838 }
QHash< QString, Entity > entityHash
Definition: qxmlstream_p.h:770
QXmlStreamEntityResolver * entityResolver
Definition: qxmlstream_p.h:999
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QXmlStreamReader * q_ptr
Definition: qxmlstream_p.h:743
static Entity createLiteral(const QString &entity)
Definition: qxmlstream_p.h:761
QTextDecoder * decoder
Definition: qxmlstream_p.h:789

◆ ~QXmlStreamReaderPrivate()

QXmlStreamReaderPrivate::~QXmlStreamReaderPrivate ( )

Definition at line 927 of file qxmlstream.cpp.

928 {
929 #ifndef QT_NO_TEXTCODEC
930  delete decoder;
931 #endif
932  qFree(sym_stack);
934  delete entityParser;
935 }
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
QXmlStreamReaderPrivate * entityParser
Definition: qxmlstream_p.h:975
QTextDecoder * decoder
Definition: qxmlstream_p.h:789

Functions

◆ checkPublicLiteral()

void QXmlStreamReaderPrivate::checkPublicLiteral ( const QStringRef publicId)

Definition at line 1765 of file qxmlstream.cpp.

1766 {
1767 //#x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
1768 
1769  const ushort *data = reinterpret_cast<const ushort *>(publicId.constData());
1770  uchar c = 0;
1771  int i;
1772  for (i = publicId.size() - 1; i >= 0; --i) {
1773  if (data[i] < 256)
1774  switch ((c = data[i])) {
1775  case ' ': case '\n': case '\r': case '-': case '(': case ')':
1776  case '+': case ',': case '.': case '/': case ':': case '=':
1777  case '?': case ';': case '!': case '*': case '#': case '@':
1778  case '$': case '_': case '%': case '\'': case '\"':
1779  continue;
1780  default:
1781  if ((c >= 'a' && c <= 'z')
1782  || (c >= 'A' && c <= 'Z')
1783  || (c >= '0' && c <= '9'))
1784  continue;
1785  }
1786  break;
1787  }
1788  if (i >= 0)
1789  raiseWellFormedError(QXmlStream::tr("Unexpected character '%1' in public id literal.").arg(QChar(QLatin1Char(c))));
1790 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
unsigned char uchar
Definition: qglobal.h:994
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
static const char * data(const QByteArray &arr)
unsigned short ushort
Definition: qglobal.h:995
void raiseWellFormedError(const QString &message)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ checkStartDocument()

bool QXmlStreamReaderPrivate::checkStartDocument ( )

Definition at line 1797 of file qxmlstream.cpp.

1798 {
1799  hasCheckedStartDocument = true;
1800 
1801  if (scanString(spell[XML], XML))
1802  return true;
1803 
1805  if (atEnd) {
1806  hasCheckedStartDocument = false;
1808  }
1809  return false;
1810 }
bool scanString(const char *str, short tokenToInject, bool requireSpace=true)
void raiseError(QXmlStreamReader::Error error, const QString &message=QString())
QXmlStreamReader::TokenType type
Definition: qxmlstream_p.h:796
static const char *const spell[]
Definition: qxmlstream_p.h:134

◆ clearSym()

void QXmlStreamReaderPrivate::clearSym ( )
inline

Definition at line 950 of file qxmlstream_p.h.

950 { Value &val = sym(1); val.pos = textBuffer.size(); val.len = 0; }
Value & sym(int index) const
Definition: qxmlstream_p.h:905
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102

◆ clearTextBuffer()

void QXmlStreamReaderPrivate::clearTextBuffer ( )
inline

Definition at line 908 of file qxmlstream_p.h.

908  {
909  if (!scanDtd) {
910  textBuffer.resize(0);
911  textBuffer.reserve(256);
912  }
913  }
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353

◆ consumeRule()

void QXmlStreamReaderPrivate::consumeRule ( int  )
inline

◆ entitiesMustBeDeclared()

bool QXmlStreamReaderPrivate::entitiesMustBeDeclared ( ) const
inline

Definition at line 884 of file qxmlstream_p.h.

884  {
885  return (!inParseEntity
886  && (standalone
888  && !referenceToParameterEntityDetected // Errata 13 as of 2006-04-25
889  && !hasExternalDtdSubset)));
890  }

◆ fastScanContentCharList()

int QXmlStreamReaderPrivate::fastScanContentCharList ( )
inline

Used for text nodes essentially.

Warning
This function is not part of the public interface.

That is, characters appearing inside elements.

Definition at line 1263 of file qxmlstream.cpp.

1264 {
1265  int n = 0;
1266  uint c;
1267  while ((c = getChar())) {
1268  switch (ushort(c)) {
1269  case 0xfffe:
1270  case 0xffff:
1271  case 0:
1272  putChar(c);
1273  return n;
1274  case ']': {
1275  isWhitespace = false;
1276  int pos = textBuffer.size();
1277  textBuffer += QChar(ushort(c));
1278  ++n;
1279  while ((c = getChar()) == ']') {
1280  textBuffer += QChar(ushort(c));
1281  ++n;
1282  }
1283  if (c == 0) {
1284  putString(textBuffer, pos);
1285  textBuffer.resize(pos);
1286  } else if (c == '>' && textBuffer.at(textBuffer.size()-2) == QLatin1Char(']')) {
1287  raiseWellFormedError(QXmlStream::tr("Sequence ']]>' not allowed in content."));
1288  } else {
1289  putChar(c);
1290  break;
1291  }
1292  return n;
1293  } break;
1294  case '\r':
1295  if ((c = filterCarriageReturn()) == 0)
1296  return n;
1297  // fall through
1298  case '\n':
1299  ++lineNumber;
1301  // fall through
1302  case ' ':
1303  case '\t':
1304  textBuffer += QChar(ushort(c));
1305  ++n;
1306  break;
1307  case '&':
1308  case '<':
1309  if (!(c & 0xff0000)) {
1310  putChar(c);
1311  return n;
1312  }
1313  // fall through
1314  default:
1315  if (c < 0x20) {
1316  putChar(c);
1317  return n;
1318  }
1319  isWhitespace = false;
1320  textBuffer += QChar(ushort(c));
1321  ++n;
1322  }
1323  }
1324  return n;
1325 }
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
unsigned int uint
Definition: qglobal.h:996
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
unsigned short ushort
Definition: qglobal.h:995
void putString(const QString &s, int from=0)
void raiseWellFormedError(const QString &message)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ fastScanLiteralContent()

int QXmlStreamReaderPrivate::fastScanLiteralContent ( )
inline
Warning
This function is not part of the public interface.

Scan strings with quotes or apostrophes surround them. For instance, attributes, the version and encoding field in the XML prolog and entity declarations.

If normalizeLiterals is set to true, the function also normalizes whitespace. It is set to true when the first start tag is encountered.

Definition at line 1181 of file qxmlstream.cpp.

1182 {
1183  int n = 0;
1184  uint c;
1185  while ((c = getChar())) {
1186  switch (ushort(c)) {
1187  case 0xfffe:
1188  case 0xffff:
1189  case 0:
1190  /* The putChar() call is necessary so the parser re-gets
1191  * the character from the input source, when raising an error. */
1192  putChar(c);
1193  return n;
1194  case '\r':
1195  if (filterCarriageReturn() == 0)
1196  return n;
1197  // fall through
1198  case '\n':
1199  ++lineNumber;
1201  // fall through
1202  case ' ':
1203  case '\t':
1204  if (normalizeLiterals)
1205  textBuffer += QLatin1Char(' ');
1206  else
1207  textBuffer += QChar(c);
1208  ++n;
1209  break;
1210  case '&':
1211  case '<':
1212  case '\"':
1213  case '\'':
1214  if (!(c & 0xff0000)) {
1215  putChar(c);
1216  return n;
1217  }
1218  // fall through
1219  default:
1220  textBuffer += QChar(c);
1221  ++n;
1222  }
1223  }
1224  return n;
1225 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
unsigned int uint
Definition: qglobal.h:996
unsigned short ushort
Definition: qglobal.h:995
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ fastScanName()

int QXmlStreamReaderPrivate::fastScanName ( int *  prefix = 0)
inline

Definition at line 1327 of file qxmlstream.cpp.

1328 {
1329  int n = 0;
1330  ushort c;
1331  while ((c = getChar())) {
1332  switch (c) {
1333  case '\n':
1334  case ' ':
1335  case '\t':
1336  case '\r':
1337  case '&':
1338  case '#':
1339  case '\'':
1340  case '\"':
1341  case '<':
1342  case '>':
1343  case '[':
1344  case ']':
1345  case '=':
1346  case '%':
1347  case '/':
1348  case ';':
1349  case '?':
1350  case '!':
1351  case '^':
1352  case '|':
1353  case ',':
1354  case '(':
1355  case ')':
1356  case '+':
1357  case '*':
1358  putChar(c);
1359  if (prefix && *prefix == n+1) {
1360  *prefix = 0;
1361  putChar(':');
1362  --n;
1363  }
1364  return n;
1365  case ':':
1366  if (prefix) {
1367  if (*prefix == 0) {
1368  *prefix = n+2;
1369  } else { // only one colon allowed according to the namespace spec.
1370  putChar(c);
1371  return n;
1372  }
1373  } else {
1374  putChar(c);
1375  return n;
1376  }
1377  // fall through
1378  default:
1379  textBuffer += QChar(c);
1380  ++n;
1381  }
1382  }
1383 
1384  if (prefix)
1385  *prefix = 0;
1386  int pos = textBuffer.size() - n;
1387  putString(textBuffer, pos);
1388  textBuffer.resize(pos);
1389  return 0;
1390 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
unsigned short ushort
Definition: qglobal.h:995
void putString(const QString &s, int from=0)

◆ fastScanNMTOKEN()

int QXmlStreamReaderPrivate::fastScanNMTOKEN ( )
inline

Definition at line 1443 of file qxmlstream.cpp.

1444 {
1445  int n = 0;
1446  uint c;
1447  while ((c = getChar())) {
1448  if (fastDetermineNameChar(c) == NotName) {
1449  putChar(c);
1450  return n;
1451  } else {
1452  ++n;
1453  textBuffer += QChar(c);
1454  }
1455  }
1456 
1457  int pos = textBuffer.size() - n;
1458  putString(textBuffer, pos);
1459  textBuffer.resize(pos);
1460 
1461  return n;
1462 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
unsigned int uint
Definition: qglobal.h:996
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
void putString(const QString &s, int from=0)
static NameChar fastDetermineNameChar(QChar ch)

◆ fastScanSpace()

int QXmlStreamReaderPrivate::fastScanSpace ( )
inline

Definition at line 1227 of file qxmlstream.cpp.

Referenced by scanNData(), and scanString().

1228 {
1229  int n = 0;
1230  ushort c;
1231  while ((c = getChar())) {
1232  switch (c) {
1233  case '\r':
1234  if ((c = filterCarriageReturn()) == 0)
1235  return n;
1236  // fall through
1237  case '\n':
1238  ++lineNumber;
1240  // fall through
1241  case ' ':
1242  case '\t':
1243  textBuffer += QChar(c);
1244  ++n;
1245  break;
1246  default:
1247  putChar(c);
1248  return n;
1249  }
1250  }
1251  return n;
1252 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
unsigned short ushort
Definition: qglobal.h:995

◆ filterCarriageReturn()

uint QXmlStreamReaderPrivate::filterCarriageReturn ( )
inline

Definition at line 938 of file qxmlstream.cpp.

Referenced by fastScanContentCharList(), fastScanLiteralContent(), fastScanSpace(), and scanUntil().

939 {
940  uint peekc = peekChar();
941  if (peekc == '\n') {
942  if (putStack.size())
943  putStack.pop();
944  else
945  ++readBufferPos;
946  return peekc;
947  }
948  if (peekc == 0) {
949  putChar('\r');
950  return 0;
951  }
952  return '\n';
953 }
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756
unsigned int uint
Definition: qglobal.h:996

◆ getChar()

uint QXmlStreamReaderPrivate::getChar ( )
inline
Warning
This function is not part of the public interface. If the end of the file is encountered, 0 is returned.

Definition at line 959 of file qxmlstream.cpp.

Referenced by fastScanContentCharList(), fastScanLiteralContent(), fastScanName(), fastScanNMTOKEN(), fastScanSpace(), scanString(), and scanUntil().

960 {
961  uint c;
962  if (putStack.size()) {
963  c = atEnd ? 0 : putStack.pop();
964  } else {
965  if (readBufferPos < readBuffer.size())
967  else
968  c = getChar_helper();
969  }
970 
971  return c;
972 }
unsigned char c[8]
Definition: qnumeric_p.h:62
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
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
unsigned int uint
Definition: qglobal.h:996

◆ getChar_helper()

ushort QXmlStreamReaderPrivate::getChar_helper ( )

Definition at line 1503 of file qxmlstream.cpp.

Referenced by getChar(), and peekChar().

1504 {
1505  const int BUFFER_SIZE = 8192;
1507  readBufferPos = 0;
1508  readBuffer.resize(0);
1509 #ifndef QT_NO_TEXTCODEC
1510  if (decoder)
1511 #endif
1512  nbytesread = 0;
1513  if (device) {
1514  rawReadBuffer.resize(BUFFER_SIZE);
1515  int nbytesreadOrMinus1 = device->read(rawReadBuffer.data() + nbytesread, BUFFER_SIZE - nbytesread);
1516  nbytesread += qMax(nbytesreadOrMinus1, 0);
1517  } else {
1518  if (nbytesread)
1520  else
1523  dataBuffer.clear();
1524  }
1525  if (!nbytesread) {
1526  atEnd = true;
1527  return 0;
1528  }
1529 
1530 #ifndef QT_NO_TEXTCODEC
1531  if (!decoder) {
1532  if (nbytesread < 4) { // the 4 is to cover 0xef 0xbb 0xbf plus
1533  // one extra for the utf8 codec
1534  atEnd = true;
1535  return 0;
1536  }
1537  int mib = 106; // UTF-8
1538 
1539  // look for byte order mark
1540  uchar ch1 = rawReadBuffer.at(0);
1541  uchar ch2 = rawReadBuffer.at(1);
1542  uchar ch3 = rawReadBuffer.at(2);
1543  uchar ch4 = rawReadBuffer.at(3);
1544 
1545  if ((ch1 == 0 && ch2 == 0 && ch3 == 0xfe && ch4 == 0xff) ||
1546  (ch1 == 0xff && ch2 == 0xfe && ch3 == 0 && ch4 == 0))
1547  mib = 1017; // UTF-32 with byte order mark
1548  else if (ch1 == 0x3c && ch2 == 0x00 && ch3 == 0x00 && ch4 == 0x00)
1549  mib = 1019; // UTF-32LE
1550  else if (ch1 == 0x00 && ch2 == 0x00 && ch3 == 0x00 && ch4 == 0x3c)
1551  mib = 1018; // UTF-32BE
1552  else if ((ch1 == 0xfe && ch2 == 0xff) || (ch1 == 0xff && ch2 == 0xfe))
1553  mib = 1015; // UTF-16 with byte order mark
1554  else if (ch1 == 0x3c && ch2 == 0x00)
1555  mib = 1014; // UTF-16LE
1556  else if (ch1 == 0x00 && ch2 == 0x3c)
1557  mib = 1013; // UTF-16BE
1559  Q_ASSERT(codec);
1560  decoder = codec->makeDecoder();
1561  }
1562 
1564 
1565  if(lockEncoding && decoder->hasFailure()) {
1566  raiseWellFormedError(QXmlStream::tr("Encountered incorrectly encoded content."));
1567  readBuffer.clear();
1568  return 0;
1569  }
1570 #else
1572 #endif // QT_NO_TEXTCODEC
1573 
1574  readBuffer.reserve(1); // keep capacity when calling resize() next time
1575 
1576  if (readBufferPos < readBuffer.size()) {
1578  return c;
1579  }
1580 
1581  atEnd = true;
1582  return 0;
1583 }
unsigned char c[8]
Definition: qnumeric_p.h:62
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
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
QTextDecoder * makeDecoder() const
Creates a QTextDecoder which stores enough state to decode chunks of char * data to create chunks of ...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
unsigned char uchar
Definition: qglobal.h:994
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
int mib
static QTextCodec * codecForMib(int mib)
Returns the QTextCodec which matches the MIBenum mib.
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool hasFailure() const
Determines whether the decoder encountered a failure while decoding the input.
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
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
void resize(int size)
Sets the size of the byte array to size bytes.
QString toUnicode(const char *chars, int len)
Converts the first len bytes in chars to Unicode, returning the result.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
void raiseWellFormedError(const QString &message)
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
QTextDecoder * decoder
Definition: qxmlstream_p.h:789
void clear()
Clears the contents of the byte array and makes it empty.

◆ init()

void QXmlStreamReaderPrivate::init ( )

Definition at line 840 of file qxmlstream.cpp.

Referenced by parseEntity(), and QXmlStreamReaderPrivate().

841 {
842  tos = 0;
843  scanDtd = false;
844  token = -1;
845  token_char = 0;
846  isEmptyElement = false;
847  isWhitespace = true;
848  isCDATA = false;
849  standalone = false;
850  tos = 0;
851  resumeReduction = 0;
852  state_stack[tos++] = 0;
853  state_stack[tos] = 0;
854  putStack.clear();
855  putStack.reserve(32);
856  textBuffer.clear();
857  textBuffer.reserve(256);
858  tagStack.clear();
859  tagsDone = false;
860  attributes.clear();
861  attributes.reserve(16);
863  readBufferPos = 0;
864  nbytesread = 0;
865 #ifndef QT_NO_TEXTCODEC
866  codec = QTextCodec::codecForMib(106); // utf8
867  delete decoder;
868  decoder = 0;
869 #endif
870  attributeStack.clear();
871  attributeStack.reserve(16);
872  entityParser = 0;
873  hasCheckedStartDocument = false;
874  normalizeLiterals = false;
875  hasSeenTag = false;
876  atEnd = false;
877  inParseEntity = false;
880  hasExternalDtdSubset = false;
881  lockEncoding = false;
882  namespaceProcessing = true;
884  dataBuffer.clear();
885  readBuffer.clear();
886 
889 }
QXmlStreamAttributes attributes
Definition: qxmlstream_p.h:808
QXmlStreamSimpleStack< Attribute > attributeStack
Definition: qxmlstream_p.h:918
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756
static QTextCodec * codecForMib(int mib)
Returns the QTextCodec which matches the MIBenum mib.
QXmlStreamReader::Error error
Definition: qxmlstream_p.h:797
QXmlStreamReader::TokenType type
Definition: qxmlstream_p.h:796
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
void reserve(int extraCapacity)
Definition: qxmlstream_p.h:651
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
QXmlStreamReaderPrivate * entityParser
Definition: qxmlstream_p.h:975
QXmlStreamSimpleStack< Tag > tagStack
Definition: qxmlstream_p.h:721
QTextDecoder * decoder
Definition: qxmlstream_p.h:789
void clear()
Clears the contents of the byte array and makes it empty.

◆ injectToken()

void QXmlStreamReaderPrivate::injectToken ( ushort  tokenToInject)
inline

Definition at line 969 of file qxmlstream_p.h.

Referenced by parseEntity(), scanString(), and scanUntil().

969  {
970  putChar(int(tokenToInject) << 16);
971  }

◆ namespaceForPrefix()

QStringRef QXmlStreamReaderPrivate::namespaceForPrefix ( const QStringRef prefix)

Definition at line 1585 of file qxmlstream.cpp.

Referenced by resolveTag().

1586 {
1587  for (int j = namespaceDeclarations.size() - 1; j >= 0; --j) {
1588  const NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(j);
1589  if (namespaceDeclaration.prefix == prefix) {
1590  return namespaceDeclaration.namespaceUri;
1591  }
1592  }
1593 
1594 #if 1
1595  if (namespaceProcessing && !prefix.isEmpty())
1596  raiseWellFormedError(QXmlStream::tr("Namespace prefix '%1' not declared").arg(prefix.toString()));
1597 #endif
1598 
1599  return QStringRef();
1600 }
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
QXmlStreamSimpleStack< NamespaceDeclaration > namespaceDeclarations
Definition: qxmlstream_p.h:697
bool isEmpty() const
Returns true if the string reference has no characters; otherwise returns false.
Definition: qstring.h:1169
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
void raiseWellFormedError(const QString &message)

◆ parse()

bool QXmlStreamReaderPrivate::parse ( )

Definition at line 1017 of file qxmlstream_p.h.

Referenced by parseEntity().

1018 {
1019  // cleanup currently reported token
1020 
1021  switch (type) {
1023  name.clear();
1024  prefix.clear();
1025  qualifiedName.clear();
1026  namespaceUri.clear();
1029  if (attributes.size())
1030  attributes.resize(0);
1031  if (isEmptyElement) {
1033  Tag &tag = tagStack_pop();
1034  namespaceUri = tag.namespaceDeclaration.namespaceUri;
1035  name = tag.name;
1036  qualifiedName = tag.qualifiedName;
1037  isEmptyElement = false;
1038  return true;
1039  }
1040  clearTextBuffer();
1041  break;
1043  name.clear();
1044  prefix.clear();
1045  qualifiedName.clear();
1046  namespaceUri.clear();
1047  clearTextBuffer();
1048  break;
1049  case QXmlStreamReader::DTD:
1052  dtdName.clear();
1053  dtdPublicId.clear();
1054  dtdSystemId.clear();
1055  // fall through
1058  isCDATA = false;
1059  isWhitespace = true;
1060  text.clear();
1061  clearTextBuffer();
1062  break;
1064  text.clear();
1065  name.clear();
1066  clearTextBuffer();
1067  break;
1071  clearTextBuffer();
1072  break;
1075  break;
1077  lockEncoding = true;
1080 #ifndef QT_NO_TEXTCODEC
1081  if(decoder->hasFailure()) {
1082  raiseWellFormedError(QXmlStream::tr("Encountered incorrectly encoded content."));
1083  readBuffer.clear();
1084  return false;
1085  }
1086 #endif
1087  // fall through
1088  default:
1089  clearTextBuffer();
1090  ;
1091  }
1092 
1094 
1095 
1096  // the main parse loop
1097  int act, r;
1098 
1099  if (resumeReduction) {
1100  act = state_stack[tos-1];
1101  r = resumeReduction;
1102  resumeReduction = 0;
1103  goto ResumeReduction;
1104  }
1105 
1106  act = state_stack[tos];
1107 
1108  forever {
1109  if (token == -1 && - TERMINAL_COUNT != action_index[act]) {
1110  uint cu = getChar();
1111  token = NOTOKEN;
1112  token_char = cu;
1113  if (cu & 0xff0000) {
1114  token = cu >> 16;
1115  } else switch (token_char) {
1116  case 0xfffe:
1117  case 0xffff:
1118  token = ERROR;
1119  break;
1120  case '\r':
1121  token = SPACE;
1122  if (cu == '\r') {
1123  if ((token_char = filterCarriageReturn())) {
1124  ++lineNumber;
1126  break;
1127  }
1128  } else {
1129  break;
1130  }
1131  // fall through
1132  case '\0': {
1133  token = EOF_SYMBOL;
1134  if (!tagsDone && !inParseEntity) {
1135  int a = t_action(act, token);
1136  if (a < 0) {
1138  return false;
1139  }
1140  }
1141 
1142  } break;
1143  case '\n':
1144  ++lineNumber;
1146  case ' ':
1147  case '\t':
1148  token = SPACE;
1149  break;
1150  case '&':
1151  token = AMPERSAND;
1152  break;
1153  case '#':
1154  token = HASH;
1155  break;
1156  case '\'':
1157  token = QUOTE;
1158  break;
1159  case '\"':
1160  token = DBLQUOTE;
1161  break;
1162  case '<':
1163  token = LANGLE;
1164  break;
1165  case '>':
1166  token = RANGLE;
1167  break;
1168  case '[':
1169  token = LBRACK;
1170  break;
1171  case ']':
1172  token = RBRACK;
1173  break;
1174  case '(':
1175  token = LPAREN;
1176  break;
1177  case ')':
1178  token = RPAREN;
1179  break;
1180  case '|':
1181  token = PIPE;
1182  break;
1183  case '=':
1184  token = EQ;
1185  break;
1186  case '%':
1187  token = PERCENT;
1188  break;
1189  case '/':
1190  token = SLASH;
1191  break;
1192  case ':':
1193  token = COLON;
1194  break;
1195  case ';':
1196  token = SEMICOLON;
1197  break;
1198  case ',':
1199  token = COMMA;
1200  break;
1201  case '-':
1202  token = DASH;
1203  break;
1204  case '+':
1205  token = PLUS;
1206  break;
1207  case '*':
1208  token = STAR;
1209  break;
1210  case '.':
1211  token = DOT;
1212  break;
1213  case '?':
1214  token = QUESTIONMARK;
1215  break;
1216  case '!':
1217  token = BANG;
1218  break;
1219  case '0':
1220  case '1':
1221  case '2':
1222  case '3':
1223  case '4':
1224  case '5':
1225  case '6':
1226  case '7':
1227  case '8':
1228  case '9':
1229  token = DIGIT;
1230  break;
1231  default:
1232  if (cu < 0x20)
1233  token = NOTOKEN;
1234  else
1235  token = LETTER;
1236  break;
1237  }
1238  }
1239 
1240  act = t_action (act, token);
1241  if (act == ACCEPT_STATE) {
1242  // reset the parser in case someone resumes (process instructions can follow a valid document)
1243  tos = 0;
1244  state_stack[tos++] = 0;
1245  state_stack[tos] = 0;
1246  return true;
1247  } else if (act > 0) {
1248  if (++tos == stack_size-1)
1249  reallocateStack();
1250 
1251  Value &val = sym_stack[tos];
1252  val.c = token_char;
1253  val.pos = textBuffer.size();
1254  val.prefix = 0;
1255  val.len = 1;
1256  if (token_char)
1258 
1259  state_stack[tos] = act;
1260  token = -1;
1261 
1262 
1263  } else if (act < 0) {
1264  r = - act - 1;
1265 
1266 #if defined (QLALR_DEBUG)
1267  int ridx = rule_index[r];
1268  printf ("%3d) %s ::=", r + 1, spell[rule_info[ridx]]);
1269  ++ridx;
1270  for (int i = ridx; i < ridx + rhs[r]; ++i) {
1271  int symbol = rule_info[i];
1272  if (const char *name = spell[symbol])
1273  printf (" %s", name);
1274  else
1275  printf (" #%d", symbol);
1276  }
1277  printf ("\n");
1278 #endif
1279 
1280  tos -= rhs[r];
1281  act = state_stack[tos++];
1282  ResumeReduction:
1283  switch (r) {
1284 
1285  case 0:
1287  break;
1288 
1289  case 1:
1291  if (hasSeenTag || inParseEntity) {
1293  } else {
1294  raiseError(QXmlStreamReader::NotWellFormedError, QXmlStream::tr("Start tag expected."));
1295  // reset the parser
1296  tos = 0;
1297  state_stack[tos++] = 0;
1298  state_stack[tos] = 0;
1299  return false;
1300  }
1301  }
1302  break;
1303 
1304  case 10:
1305  entityReferenceStack.pop()->isCurrentlyReferenced = false;
1306  clearSym();
1307  break;
1308 
1309  case 11:
1310  if (!scanString(spell[VERSION], VERSION, false) && atEnd) {
1311  resume(11);
1312  return false;
1313  }
1314  break;
1315 
1316  case 12:
1319  startDocument();
1320  break;
1321 
1322  case 13:
1323  hasExternalDtdSubset = true;
1324  dtdSystemId = symString(2);
1325  break;
1326 
1327  case 14:
1329  dtdPublicId = symString(2);
1330  dtdSystemId = symString(4);
1331  hasExternalDtdSubset = true;
1332  break;
1333 
1334  case 16:
1335  if (!scanPublicOrSystem() && atEnd) {
1336  resume(16);
1337  return false;
1338  }
1339  dtdName = symString(3);
1340  break;
1341 
1342  case 17:
1343  case 18:
1344  dtdName = symString(3);
1345  // fall through
1346 
1347  case 19:
1348  case 20:
1350  text = &textBuffer;
1351  break;
1352 
1353  case 21:
1354  scanDtd = true;
1355  break;
1356 
1357  case 22:
1358  scanDtd = false;
1359  break;
1360 
1361  case 37:
1362  if (!scanString(spell[EMPTY], EMPTY, false)
1363  && !scanString(spell[ANY], ANY, false)
1364  && atEnd) {
1365  resume(37);
1366  return false;
1367  }
1368  break;
1369 
1370  case 43:
1371  if (!scanString(spell[PCDATA], PCDATA, false) && atEnd) {
1372  resume(43);
1373  return false;
1374  }
1375  break;
1376 
1377  case 68: {
1378  lastAttributeIsCData = true;
1379  } break;
1380 
1381  case 78:
1382  if (!scanAfterDefaultDecl() && atEnd) {
1383  resume(78);
1384  return false;
1385  }
1386  break;
1387 
1388  case 83:
1389  sym(1) = sym(2);
1391  lastAttributeIsCData = false;
1392  if (!scanAttType() && atEnd) {
1393  resume(83);
1394  return false;
1395  }
1396  break;
1397 
1398  case 84: {
1399  DtdAttribute &dtdAttribute = dtdAttributes.push();
1400  dtdAttribute.tagName.clear();
1401  dtdAttribute.isCDATA = lastAttributeIsCData;
1402  dtdAttribute.attributePrefix = addToStringStorage(symPrefix(1));
1403  dtdAttribute.attributeName = addToStringStorage(symString(1));
1404  dtdAttribute.attributeQualifiedName = addToStringStorage(symName(1));
1405  dtdAttribute.isNamespaceAttribute = (dtdAttribute.attributePrefix == QLatin1String("xmlns")
1406  || (dtdAttribute.attributePrefix.isEmpty()
1407  && dtdAttribute.attributeName == QLatin1String("xmlns")));
1408  if (lastAttributeValue.isNull()) {
1409  dtdAttribute.defaultValue.clear();
1410  } else {
1411  if (dtdAttribute.isCDATA)
1412  dtdAttribute.defaultValue = addToStringStorage(lastAttributeValue);
1413  else
1414  dtdAttribute.defaultValue = addToStringStorage(lastAttributeValue.toString().simplified());
1415 
1416  }
1417  } break;
1418 
1419  case 88: {
1421  break;
1422  int n = dtdAttributes.size();
1423  QStringRef tagName = addToStringStorage(symName(3));
1424  while (n--) {
1425  DtdAttribute &dtdAttribute = dtdAttributes[n];
1426  if (!dtdAttribute.tagName.isNull())
1427  break;
1428  dtdAttribute.tagName = tagName;
1429  for (int i = 0; i < n; ++i) {
1430  if ((dtdAttributes[i].tagName.isNull() || dtdAttributes[i].tagName == tagName)
1431  && dtdAttributes[i].attributeQualifiedName == dtdAttribute.attributeQualifiedName) {
1432  dtdAttribute.attributeQualifiedName.clear(); // redefined, delete it
1433  break;
1434  }
1435  }
1436  }
1437  } break;
1438 
1439  case 89: {
1440  if (!scanPublicOrSystem() && atEnd) {
1441  resume(89);
1442  return false;
1443  }
1444  EntityDeclaration &entityDeclaration = entityDeclarations.push();
1445  entityDeclaration.clear();
1446  entityDeclaration.name = symString(3);
1447  } break;
1448 
1449  case 90: {
1450  if (!scanPublicOrSystem() && atEnd) {
1451  resume(90);
1452  return false;
1453  }
1454  EntityDeclaration &entityDeclaration = entityDeclarations.push();
1455  entityDeclaration.clear();
1456  entityDeclaration.name = symString(5);
1457  entityDeclaration.parameter = true;
1458  } break;
1459 
1460  case 91: {
1461  if (!scanNData() && atEnd) {
1462  resume(91);
1463  return false;
1464  }
1465  EntityDeclaration &entityDeclaration = entityDeclarations.top();
1466  entityDeclaration.systemId = symString(3);
1467  entityDeclaration.external = true;
1468  } break;
1469 
1470  case 92: {
1471  if (!scanNData() && atEnd) {
1472  resume(92);
1473  return false;
1474  }
1475  EntityDeclaration &entityDeclaration = entityDeclarations.top();
1476  checkPublicLiteral((entityDeclaration.publicId = symString(3)));
1477  entityDeclaration.systemId = symString(5);
1478  entityDeclaration.external = true;
1479  } break;
1480 
1481  case 93: {
1482  EntityDeclaration &entityDeclaration = entityDeclarations.top();
1483  entityDeclaration.notationName = symString(3);
1484  if (entityDeclaration.parameter)
1485  raiseWellFormedError(QXmlStream::tr("NDATA in parameter entity declaration."));
1486  }
1487  //fall through
1488 
1489  case 94:
1490  case 95: {
1492  entityDeclarations.pop();
1493  break;
1494  }
1495  EntityDeclaration &entityDeclaration = entityDeclarations.top();
1496  if (!entityDeclaration.external)
1497  entityDeclaration.value = symString(2);
1498  QString entityName = entityDeclaration.name.toString();
1499  QHash<QString, Entity> &hash = entityDeclaration.parameter ? parameterEntityHash : entityHash;
1500  if (!hash.contains(entityName)) {
1501  Entity entity(entityDeclaration.value.toString());
1502  entity.unparsed = (!entityDeclaration.notationName.isNull());
1503  entity.external = entityDeclaration.external;
1504  hash.insert(entityName, entity);
1505  }
1506  } break;
1507 
1508  case 96: {
1510  int pos = sym(4).pos + sym(4).len;
1512  if (scanUntil("?>")) {
1514  const QString piTarget(processingInstructionTarget.toString());
1515  if (!piTarget.compare(QLatin1String("xml"), Qt::CaseInsensitive)) {
1516  raiseWellFormedError(QXmlStream::tr("XML declaration not at start of document."));
1517  }
1518  else if(!QXmlUtils::isNCName(piTarget))
1519  raiseWellFormedError(QXmlStream::tr("%1 is an invalid processing instruction name.").arg(piTarget));
1520  } else if (type != QXmlStreamReader::Invalid){
1521  resume(96);
1522  return false;
1523  }
1524  } break;
1525 
1526  case 97:
1530  raiseWellFormedError(QXmlStream::tr("Invalid processing instruction name."));
1531  break;
1532 
1533  case 98:
1534  if (!scanAfterLangleBang() && atEnd) {
1535  resume(98);
1536  return false;
1537  }
1538  break;
1539 
1540  case 99:
1541  if (!scanUntil("--")) {
1542  resume(99);
1543  return false;
1544  }
1545  break;
1546 
1547  case 100: {
1549  int pos = sym(1).pos + 4;
1550  text = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 3);
1551  } break;
1552 
1553  case 101: {
1555  isCDATA = true;
1556  isWhitespace = false;
1557  int pos = sym(2).pos;
1558  if (scanUntil("]]>", -1)) {
1559  text = QStringRef(&textBuffer, pos, textBuffer.size() - pos - 3);
1560  } else {
1561  resume(101);
1562  return false;
1563  }
1564  } break;
1565 
1566  case 102: {
1567  if (!scanPublicOrSystem() && atEnd) {
1568  resume(102);
1569  return false;
1570  }
1571  NotationDeclaration &notationDeclaration = notationDeclarations.push();
1572  notationDeclaration.name = symString(3);
1573  } break;
1574 
1575  case 103: {
1576  NotationDeclaration &notationDeclaration = notationDeclarations.top();
1577  notationDeclaration.systemId = symString(3);
1578  notationDeclaration.publicId.clear();
1579  } break;
1580 
1581  case 104: {
1582  NotationDeclaration &notationDeclaration = notationDeclarations.top();
1583  notationDeclaration.systemId.clear();
1584  checkPublicLiteral((notationDeclaration.publicId = symString(3)));
1585  } break;
1586 
1587  case 105: {
1588  NotationDeclaration &notationDeclaration = notationDeclarations.top();
1589  checkPublicLiteral((notationDeclaration.publicId = symString(3)));
1590  notationDeclaration.systemId = symString(5);
1591  } break;
1592 
1593  case 129:
1594  isWhitespace = false;
1595  // fall through
1596 
1597  case 130:
1599  if (atEnd && !inParseEntity) {
1600  resume(130);
1601  return false;
1602  }
1603  break;
1604 
1605  case 139:
1606  if (!textBuffer.isEmpty()) {
1608  text = &textBuffer;
1609  }
1610  break;
1611 
1612  case 140:
1613  case 141:
1614  clearSym();
1615  break;
1616 
1617  case 142:
1618  case 143:
1619  sym(1) = sym(2);
1620  break;
1621 
1622  case 144:
1623  case 145:
1624  case 146:
1625  case 147:
1626  sym(1).len += sym(2).len;
1627  break;
1628 
1629  case 173:
1630  if (normalizeLiterals)
1631  textBuffer.data()[textBuffer.size()-1] = QLatin1Char(' ');
1632  break;
1633 
1634  case 174:
1635  sym(1).len += fastScanLiteralContent();
1636  if (atEnd) {
1637  resume(174);
1638  return false;
1639  }
1640  break;
1641 
1642  case 175: {
1644  raiseWellFormedError(QXmlStream::tr("%1 is an invalid PUBLIC identifier.").arg(symString(1).toString()));
1645  resume(175);
1646  return false;
1647  }
1648  } break;
1649 
1650  case 176:
1651  case 177:
1652  clearSym();
1653  break;
1654 
1655  case 178:
1656  case 179:
1657  sym(1) = sym(2);
1658  break;
1659 
1660  case 180:
1661  case 181:
1662  case 182:
1663  case 183:
1664  sym(1).len += sym(2).len;
1665  break;
1666 
1667  case 213:
1668  case 214:
1669  clearSym();
1670  break;
1671 
1672  case 215:
1673  case 216:
1674  sym(1) = sym(2);
1676  break;
1677 
1678  case 217:
1679  case 218:
1680  case 219:
1681  case 220:
1682  sym(1).len += sym(2).len;
1683  break;
1684 
1685  case 229: {
1687  if (prefix.isEmpty() && symString(1) == QLatin1String("xmlns") && namespaceProcessing) {
1688  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
1689  namespaceDeclaration.prefix.clear();
1690 
1691  const QStringRef ns(symString(5));
1692  if(ns == QLatin1String("http://www.w3.org/2000/xmlns/") ||
1693  ns == QLatin1String("http://www.w3.org/XML/1998/namespace"))
1694  raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration."));
1695  else
1696  namespaceDeclaration.namespaceUri = addToStringStorage(ns);
1697  } else {
1698  Attribute &attribute = attributeStack.push();
1699  attribute.key = sym(1);
1700  attribute.value = sym(5);
1701 
1702  QStringRef attributeQualifiedName = symName(1);
1703  bool normalize = false;
1704  for (int a = 0; a < dtdAttributes.size(); ++a) {
1705  DtdAttribute &dtdAttribute = dtdAttributes[a];
1706  if (!dtdAttribute.isCDATA
1707  && dtdAttribute.tagName == qualifiedName
1708  && dtdAttribute.attributeQualifiedName == attributeQualifiedName
1709  ) {
1710  normalize = true;
1711  break;
1712  }
1713  }
1714  if (normalize) {
1715  // normalize attribute value (simplify and trim)
1716  int pos = textBuffer.size();
1717  int n = 0;
1718  bool wasSpace = true;
1719  for (int i = 0; i < attribute.value.len; ++i) {
1720  QChar c = textBuffer.at(attribute.value.pos + i);
1721  if (c.unicode() == ' ') {
1722  if (wasSpace)
1723  continue;
1724  wasSpace = true;
1725  } else {
1726  wasSpace = false;
1727  }
1728  textBuffer += textBuffer.at(attribute.value.pos + i);
1729  ++n;
1730  }
1731  if (wasSpace)
1732  while (n && textBuffer.at(pos + n - 1).unicode() == ' ')
1733  --n;
1734  attribute.value.pos = pos;
1735  attribute.value.len = n;
1736  }
1737  if (prefix == QLatin1String("xmlns") && namespaceProcessing) {
1738  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
1739  QStringRef namespacePrefix = symString(attribute.key);
1740  QStringRef namespaceUri = symString(attribute.value);
1741  attributeStack.pop();
1742  if (((namespacePrefix == QLatin1String("xml"))
1743  ^ (namespaceUri == QLatin1String("http://www.w3.org/XML/1998/namespace")))
1744  || namespaceUri == QLatin1String("http://www.w3.org/2000/xmlns/")
1745  || namespaceUri.isEmpty()
1746  || namespacePrefix == QLatin1String("xmlns"))
1747  raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration."));
1748 
1749  namespaceDeclaration.prefix = addToStringStorage(namespacePrefix);
1750  namespaceDeclaration.namespaceUri = addToStringStorage(namespaceUri);
1751  }
1752  }
1753  } break;
1754 
1755  case 235: {
1756  normalizeLiterals = true;
1757  Tag &tag = tagStack_push();
1758  prefix = tag.namespaceDeclaration.prefix = addToStringStorage(symPrefix(2));
1759  name = tag.name = addToStringStorage(symString(2));
1760  qualifiedName = tag.qualifiedName = addToStringStorage(symName(2));
1761  if ((!prefix.isEmpty() && !QXmlUtils::isNCName(prefix)) || !QXmlUtils::isNCName(name))
1762  raiseWellFormedError(QXmlStream::tr("Invalid XML name."));
1763  } break;
1764 
1765  case 236:
1766  isEmptyElement = true;
1767  // fall through
1768 
1769  case 237:
1771  resolveTag();
1772  if (tagStack.size() == 1 && hasSeenTag && !inParseEntity)
1773  raiseWellFormedError(QXmlStream::tr("Extra content at end of document."));
1774  hasSeenTag = true;
1775  break;
1776 
1777  case 238: {
1779  Tag &tag = tagStack_pop();
1780 
1781  namespaceUri = tag.namespaceDeclaration.namespaceUri;
1782  name = tag.name;
1783  qualifiedName = tag.qualifiedName;
1784  if (qualifiedName != symName(3))
1785  raiseWellFormedError(QXmlStream::tr("Opening and ending tag mismatch."));
1786  } break;
1787 
1788  case 239:
1789  if (entitiesMustBeDeclared()) {
1790  raiseWellFormedError(QXmlStream::tr("Entity '%1' not declared.").arg(unresolvedEntity));
1791  break;
1792  }
1795  break;
1796 
1797  case 240: {
1798  sym(1).len += sym(2).len + 1;
1799  QString reference = symString(2).toString();
1800  if (entityHash.contains(reference)) {
1801  Entity &entity = entityHash[reference];
1802  if (entity.unparsed) {
1803  raiseWellFormedError(QXmlStream::tr("Reference to unparsed entity '%1'.").arg(reference));
1804  } else {
1805  if (!entity.hasBeenParsed) {
1806  parseEntity(entity.value);
1807  entity.hasBeenParsed = true;
1808  }
1809  if (entity.literal)
1810  putStringLiteral(entity.value);
1811  else if (referenceEntity(entity))
1812  putReplacement(entity.value);
1813  textBuffer.chop(2 + sym(2).len);
1814  clearSym();
1815  }
1816  break;
1817  }
1818 
1819  if (entityResolver) {
1820  QString replacementText = resolveUndeclaredEntity(reference);
1821  if (!replacementText.isNull()) {
1822  putReplacement(replacementText);
1823  textBuffer.chop(2 + sym(2).len);
1824  clearSym();
1825  break;
1826  }
1827  }
1828 
1831  textBuffer.chop(2 + sym(2).len);
1832  clearSym();
1833 
1834  } break;
1835 
1836  case 241: {
1837  sym(1).len += sym(2).len + 1;
1838  QString reference = symString(2).toString();
1839  if (parameterEntityHash.contains(reference)) {
1841  Entity &entity = parameterEntityHash[reference];
1842  if (entity.unparsed || entity.external) {
1844  } else {
1845  if (referenceEntity(entity))
1846  putString(entity.value);
1847  textBuffer.chop(2 + sym(2).len);
1848  clearSym();
1849  }
1850  } else if (entitiesMustBeDeclared()) {
1851  raiseWellFormedError(QXmlStream::tr("Entity '%1' not declared.").arg(symString(2).toString()));
1852  }
1853  } break;
1854 
1855  case 242:
1856  sym(1).len += sym(2).len + 1;
1857  break;
1858 
1859  case 243: {
1860  sym(1).len += sym(2).len + 1;
1861  QString reference = symString(2).toString();
1862  if (entityHash.contains(reference)) {
1863  Entity &entity = entityHash[reference];
1864  if (entity.unparsed || entity.value.isNull()) {
1865  raiseWellFormedError(QXmlStream::tr("Reference to external entity '%1' in attribute value.").arg(reference));
1866  break;
1867  }
1868  if (!entity.hasBeenParsed) {
1869  parseEntity(entity.value);
1870  entity.hasBeenParsed = true;
1871  }
1872  if (entity.literal)
1873  putStringLiteral(entity.value);
1874  else if (referenceEntity(entity))
1875  putReplacementInAttributeValue(entity.value);
1876  textBuffer.chop(2 + sym(2).len);
1877  clearSym();
1878  break;
1879  }
1880 
1881  if (entityResolver) {
1882  QString replacementText = resolveUndeclaredEntity(reference);
1883  if (!replacementText.isNull()) {
1884  putReplacement(replacementText);
1885  textBuffer.chop(2 + sym(2).len);
1886  clearSym();
1887  break;
1888  }
1889  }
1890  if (entitiesMustBeDeclared()) {
1891  raiseWellFormedError(QXmlStream::tr("Entity '%1' not declared.").arg(reference));
1892  }
1893  } break;
1894 
1895  case 244: {
1896  if (uint s = resolveCharRef(3)) {
1897  if (s >= 0xffff)
1899  else
1900  putChar((LETTER << 16) | s);
1901 
1902  textBuffer.chop(3 + sym(3).len);
1903  clearSym();
1904  } else {
1905  raiseWellFormedError(QXmlStream::tr("Invalid character reference."));
1906  }
1907  } break;
1908 
1909  case 247:
1910  case 248:
1911  sym(1).len += sym(2).len;
1912  break;
1913 
1914  case 259:
1915  sym(1).len += fastScanSpace();
1916  if (atEnd) {
1917  resume(259);
1918  return false;
1919  }
1920  break;
1921 
1922  case 262: {
1923  sym(1).len += fastScanName(&sym(1).prefix);
1924  if (atEnd) {
1925  resume(262);
1926  return false;
1927  }
1928  } break;
1929 
1930  case 263:
1931  sym(1).len += fastScanName();
1932  if (atEnd) {
1933  resume(263);
1934  return false;
1935  }
1936  break;
1937 
1938  case 264:
1939  case 265:
1940  case 266:
1941  case 267:
1942  case 268:
1943  sym(1).len += fastScanNMTOKEN();
1944  if (atEnd) {
1945  resume(268);
1946  return false;
1947  }
1948 
1949  break;
1950 
1951  default:
1952  ;
1953  } // switch
1954  act = state_stack[tos] = nt_action (act, lhs[r] - TERMINAL_COUNT);
1956  return true;
1957  } else {
1958  parseError();
1959  break;
1960  }
1961  }
1962  return false;
1963 }
uint resolveCharRef(int symbolIndex)
Tag
Definition: qtranslator.cpp:86
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
static const short rhs[]
Definition: qxmlstream_p.h:136
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
void checkPublicLiteral(const QStringRef &publicId)
void clear()
Clears the contents of the string reference by making it null and empty.
Definition: qstring.h:1167
unsigned char c[8]
Definition: qnumeric_p.h:62
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
QXmlStreamSimpleStack< DtdAttribute > dtdAttributes
Definition: qxmlstream_p.h:831
QXmlStreamAttributes attributes
Definition: qxmlstream_p.h:808
QHash< QString, Entity > entityHash
Definition: qxmlstream_p.h:770
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
bool scanString(const char *str, short tokenToInject, bool requireSpace=true)
QString resolveUndeclaredEntity(const QString &name)
Definition: qxmlstream.cpp:224
QXmlStreamEntityResolver * entityResolver
Definition: qxmlstream_p.h:999
QXmlStreamSimpleStack< Attribute > attributeStack
Definition: qxmlstream_p.h:918
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
void parseEntity(const QString &value)
Definition: qxmlstream.cpp:895
void setType(const QXmlStreamReader::TokenType t)
Never assign to variable type directly.
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
void injectToken(ushort tokenToInject)
Definition: qxmlstream_p.h:969
bool scanUntil(const char *str, short tokenToInject=-1)
Scans characters until str is encountered, and validates the characters as according to the Char[2] p...
static const short lhs[]
Definition: qxmlstream_p.h:135
void putStringLiteral(const QString &s)
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
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 vector to size.
Definition: qvector.h:342
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
Value & sym(int index) const
Definition: qxmlstream_p.h:905
bool referenceEntity(Entity &entity)
Definition: qxmlstream_p.h:773
static QString toString(Register *reg, int type, bool *ok=0)
bool entitiesMustBeDeclared() const
Definition: qxmlstream_p.h:884
int fastScanContentCharList()
Used for text nodes essentially.
QStringRef processingInstructionTarget
Definition: qxmlstream_p.h:864
void raiseError(QXmlStreamReader::Error error, const QString &message=QString())
QHash< QString, Entity > parameterEntityHash
Definition: qxmlstream_p.h:771
QXmlStreamSimpleStack< NamespaceDeclaration > namespaceDeclarations
Definition: qxmlstream_p.h:697
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QStringRef processingInstructionData
Definition: qxmlstream_p.h:864
bool isEmpty() const
Returns true if the string reference has no characters; otherwise returns false.
Definition: qstring.h:1169
unsigned int uint
Definition: qglobal.h:996
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QXmlStreamNotationDeclarations publicNotationDeclarations
Definition: qxmlstream_p.h:838
QXmlStreamSimpleStack< Entity * > entityReferenceStack
Definition: qxmlstream_p.h:772
static const short action_index[]
Definition: qxmlstream_p.h:139
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
bool hasFailure() const
Determines whether the decoder encountered a failure while decoding the input.
static int nt_action(int state, int nt)
Definition: qxmlstream_p.h:143
QXmlStreamReader::TokenType type
Definition: qxmlstream_p.h:796
int compare(const QString &s) const
Definition: qstring.cpp:5037
QStringRef symName(int index)
Definition: qxmlstream_p.h:924
QStringRef lastAttributeValue
Definition: qxmlstream_p.h:820
void putReplacement(const QString &s)
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
int fastScanName(int *prefix=0)
QXmlStreamSimpleStack< NotationDeclaration > notationDeclarations
Definition: qxmlstream_p.h:837
void putString(const QString &s, int from=0)
static int t_action(int state, int token)
Definition: qxmlstream_p.h:152
QStringRef addToStringStorage(const QStringRef &s)
Definition: qxmlstream_p.h:702
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170
void raiseWellFormedError(const QString &message)
QXmlStreamSimpleStack< Tag > tagStack
Definition: qxmlstream_p.h:721
void putReplacementInAttributeValue(const QString &s)
QStringRef symString(int index)
Definition: qxmlstream_p.h:920
QTextDecoder * decoder
Definition: qxmlstream_p.h:789
static void normalize(double &x, double &y)
static bool isPublicID(const QString &candidate)
Determines whether c is a valid instance of production [12] PubidLiteral in the XML 1...
Definition: qxmlutils.cpp:316
QXmlStreamEntityDeclarations publicEntityDeclarations
Definition: qxmlstream_p.h:859
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
static bool isNCName(const QStringRef &ncName)
Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specificat...
Definition: qxmlutils.cpp:377
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QXmlStreamNamespaceDeclarations publicNamespaceDeclarations
Definition: qxmlstream_p.h:839
QXmlStreamSimpleStack< EntityDeclaration > entityDeclarations
Definition: qxmlstream_p.h:858
QStringRef symPrefix(int index)
Definition: qxmlstream_p.h:932
static const char *const spell[]
Definition: qxmlstream_p.h:134
static QString fromUcs4(const uint *, int size=-1)
Returns a QString initialized with the first size characters of the Unicode string unicode (ISO-10646...
Definition: qstring.cpp:4356
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ parseEntity()

void QXmlStreamReaderPrivate::parseEntity ( const QString value)

Definition at line 895 of file qxmlstream.cpp.

896 {
898 
899  if (value.isEmpty())
900  return;
901 
902 
903  if (!entityParser)
905  else
906  entityParser->init();
907  entityParser->inParseEntity = true;
908  entityParser->readBuffer = value;
911  entityParser->parse();
913  raiseWellFormedError(QXmlStream::tr("Invalid entity value."));
914 
915 }
void injectToken(ushort tokenToInject)
Definition: qxmlstream_p.h:969
#define Q_Q(Class)
Definition: qglobal.h:2483
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QXmlStreamReader::TokenType type
Definition: qxmlstream_p.h:796
The QXmlStreamReader class provides a fast parser for reading well-formed XML via a simple streaming ...
Definition: qxmlstream.h:290
QXmlStreamReaderPrivate(QXmlStreamReader *q)
Definition: qxmlstream.cpp:819
void raiseWellFormedError(const QString &message)
QXmlStreamReaderPrivate * entityParser
Definition: qxmlstream_p.h:975
QXmlStreamSimpleStack< Tag > tagStack
Definition: qxmlstream_p.h:721

◆ parseError()

void QXmlStreamReaderPrivate::parseError ( )

Definition at line 1896 of file qxmlstream.cpp.

1897 {
1898 
1899  if (token == EOF_SYMBOL) {
1901  return;
1902  }
1903  const int nmax = 4;
1904  QString error_message;
1905  int ers = state_stack[tos];
1906  int nexpected = 0;
1907  int expected[nmax];
1908  if (token != ERROR)
1909  for (int tk = 0; tk < TERMINAL_COUNT; ++tk) {
1910  int k = t_action(ers, tk);
1911  if (k <= 0)
1912  continue;
1913  if (spell[tk]) {
1914  if (nexpected < nmax)
1915  expected[nexpected++] = tk;
1916  }
1917  }
1918 
1919  error_message.clear ();
1920  if (nexpected && nexpected < nmax) {
1921  bool first = true;
1922 
1923  for (int s = 0; s < nexpected; ++s) {
1924  if (first)
1925  error_message += QXmlStream::tr ("Expected ");
1926  else if (s == nexpected - 1)
1927  error_message += QLatin1String (nexpected > 2 ? ", or " : " or ");
1928  else
1929  error_message += QLatin1String (", ");
1930 
1931  first = false;
1932  error_message += QLatin1String("\'");
1933  error_message += QLatin1String (spell [expected[s]]);
1934  error_message += QLatin1String("\'");
1935  }
1936  error_message += QXmlStream::tr(", but got \'");
1937  error_message += QLatin1String(spell [token]);
1938  error_message += QLatin1String("\'");
1939  } else {
1940  error_message += QXmlStream::tr("Unexpected \'");
1941  error_message += QLatin1String(spell [token]);
1942  error_message += QLatin1String("\'");
1943  }
1944  error_message += QLatin1Char('.');
1945 
1946  raiseWellFormedError(error_message);
1947 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void raiseError(QXmlStreamReader::Error error, const QString &message=QString())
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static int t_action(int state, int token)
Definition: qxmlstream_p.h:152
void raiseWellFormedError(const QString &message)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static const char *const spell[]
Definition: qxmlstream_p.h:134

◆ peekChar()

uint QXmlStreamReaderPrivate::peekChar ( )
inline

Definition at line 974 of file qxmlstream.cpp.

Referenced by filterCarriageReturn(), scanAfterDefaultDecl(), scanAfterLangleBang(), scanAttType(), and scanPublicOrSystem().

975 {
976  uint c;
977  if (putStack.size()) {
978  c = putStack.top();
979  } else if (readBufferPos < readBuffer.size()) {
981  } else {
982  if ((c = getChar_helper()))
983  --readBufferPos;
984  }
985 
986  return c;
987 }
const T & top() const
Definition: qxmlstream_p.h:661
unsigned char c[8]
Definition: qnumeric_p.h:62
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
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
unsigned int uint
Definition: qglobal.h:996

◆ putChar() [1/2]

void QXmlStreamReaderPrivate::putChar ( uint  c)
inline

◆ putChar() [2/2]

void QXmlStreamReaderPrivate::putChar ( QChar  c)
inline

Definition at line 960 of file qxmlstream_p.h.

960 { putStack.push() = c.unicode(); }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756

◆ putReplacement()

void QXmlStreamReaderPrivate::putReplacement ( const QString s)

Definition at line 1478 of file qxmlstream.cpp.

1479 {
1480  putStack.reserve(s.size());
1481  for (int i = s.size()-1; i >= 0; --i) {
1482  ushort c = s.at(i).unicode();
1483  if (c == '\n' || c == '\r')
1484  putStack.rawPush() = ((LETTER << 16) | c);
1485  else
1486  putStack.rawPush() = c;
1487  }
1488 }
unsigned char c[8]
Definition: qnumeric_p.h:62
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
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
unsigned short ushort
Definition: qglobal.h:995
void reserve(int extraCapacity)
Definition: qxmlstream_p.h:651

◆ putReplacementInAttributeValue()

void QXmlStreamReaderPrivate::putReplacementInAttributeValue ( const QString s)

Definition at line 1489 of file qxmlstream.cpp.

1490 {
1491  putStack.reserve(s.size());
1492  for (int i = s.size()-1; i >= 0; --i) {
1493  ushort c = s.at(i).unicode();
1494  if (c == '&' || c == ';')
1495  putStack.rawPush() = c;
1496  else if (c == '\n' || c == '\r')
1497  putStack.rawPush() = ' ';
1498  else
1499  putStack.rawPush() = ((LETTER << 16) | c);
1500  }
1501 }
unsigned char c[8]
Definition: qnumeric_p.h:62
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
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
unsigned short ushort
Definition: qglobal.h:995
void reserve(int extraCapacity)
Definition: qxmlstream_p.h:651

◆ putString()

void QXmlStreamReaderPrivate::putString ( const QString s,
int  from = 0 
)

Definition at line 1464 of file qxmlstream.cpp.

Referenced by fastScanContentCharList(), fastScanName(), fastScanNMTOKEN(), scanString(), and scanUntil().

1465 {
1466  putStack.reserve(s.size());
1467  for (int i = s.size()-1; i >= from; --i)
1468  putStack.rawPush() = s.at(i).unicode();
1469 }
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
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
void reserve(int extraCapacity)
Definition: qxmlstream_p.h:651

◆ putStringLiteral()

void QXmlStreamReaderPrivate::putStringLiteral ( const QString s)

Definition at line 1471 of file qxmlstream.cpp.

1472 {
1473  putStack.reserve(s.size());
1474  for (int i = s.size()-1; i >= 0; --i)
1475  putStack.rawPush() = ((LETTER << 16) | s.at(i).unicode());
1476 }
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
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
void reserve(int extraCapacity)
Definition: qxmlstream_p.h:651

◆ raiseError()

void QXmlStreamReaderPrivate::raiseError ( QXmlStreamReader::Error  error,
const QString message = QString() 
)

Definition at line 1877 of file qxmlstream.cpp.

Referenced by checkStartDocument(), parseError(), raiseWellFormedError(), and resume().

1878 {
1879  this->error = error;
1880  errorString = message;
1881  if (errorString.isNull()) {
1883  errorString = QXmlStream::tr("Premature end of document.");
1885  errorString = QXmlStream::tr("Invalid document.");
1886  }
1887 
1889 }
QXmlStreamReader::Error error
Definition: qxmlstream_p.h:797
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QXmlStreamReader::TokenType type
Definition: qxmlstream_p.h:796

◆ raiseWellFormedError()

void QXmlStreamReaderPrivate::raiseWellFormedError ( const QString message)

◆ reallocateStack()

void QXmlStreamReaderPrivate::reallocateStack ( )
inline

Definition at line 917 of file qxmlstream.cpp.

Referenced by QXmlStreamReaderPrivate().

918 {
919  stack_size <<= 1;
920  sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value)));
922  state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int)));
924 }
Q_CORE_EXPORT void * qRealloc(void *ptr, size_t size)
Definition: qmalloc.cpp:63
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853

◆ referenceEntity()

bool QXmlStreamReaderPrivate::referenceEntity ( Entity entity)
inline

Definition at line 773 of file qxmlstream_p.h.

773  {
774  if (entity.isCurrentlyReferenced) {
775  raiseWellFormedError(QXmlStream::tr("Recursive entity detected."));
776  return false;
777  }
778  entity.isCurrentlyReferenced = true;
779  entityReferenceStack.push() = &entity;
781  return true;
782  }
void injectToken(ushort tokenToInject)
Definition: qxmlstream_p.h:969
QXmlStreamSimpleStack< Entity * > entityReferenceStack
Definition: qxmlstream_p.h:772
void raiseWellFormedError(const QString &message)

◆ resolveCharRef()

uint QXmlStreamReaderPrivate::resolveCharRef ( int  symbolIndex)

Definition at line 1748 of file qxmlstream.cpp.

1749 {
1750  bool ok = true;
1751  uint s;
1752  // ### add toXShort to QStringRef?
1753  if (sym(symbolIndex).c == 'x')
1754  s = symString(symbolIndex, 1).toString().toUInt(&ok, 16);
1755  else
1756  s = symString(symbolIndex).toString().toUInt(&ok, 10);
1757 
1758  ok &= (s == 0x9 || s == 0xa || s == 0xd || (s >= 0x20 && s <= 0xd7ff)
1759  || (s >= 0xe000 && s <= 0xfffd) || (s >= 0x10000 && s <= 0x10ffff));
1760 
1761  return ok ? s : 0;
1762 }
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
unsigned char c[8]
Definition: qnumeric_p.h:62
Value & sym(int index) const
Definition: qxmlstream_p.h:905
unsigned int uint
Definition: qglobal.h:996
uint toUInt(bool *ok=0, int base=10) const
Returns the string converted to an unsigned int using base base, which is 10 by default and must be b...
Definition: qstring.cpp:6120
QStringRef symString(int index)
Definition: qxmlstream_p.h:920

◆ resolveDtd()

void QXmlStreamReaderPrivate::resolveDtd ( )

Definition at line 1722 of file qxmlstream.cpp.

1723 {
1725  for (int i = 0; i < notationDeclarations.size(); ++i) {
1726  const QXmlStreamReaderPrivate::NotationDeclaration &notationDeclaration = notationDeclarations.at(i);
1727  QXmlStreamNotationDeclaration &publicNotationDeclaration = publicNotationDeclarations[i];
1728  publicNotationDeclaration.m_name = QXmlStreamStringRef(notationDeclaration.name);
1729  publicNotationDeclaration.m_systemId = QXmlStreamStringRef(notationDeclaration.systemId);
1730  publicNotationDeclaration.m_publicId = QXmlStreamStringRef(notationDeclaration.publicId);
1731 
1732  }
1733  notationDeclarations.clear();
1735  for (int i = 0; i < entityDeclarations.size(); ++i) {
1736  const QXmlStreamReaderPrivate::EntityDeclaration &entityDeclaration = entityDeclarations.at(i);
1737  QXmlStreamEntityDeclaration &publicEntityDeclaration = publicEntityDeclarations[i];
1738  publicEntityDeclaration.m_name = QXmlStreamStringRef(entityDeclaration.name);
1739  publicEntityDeclaration.m_notationName = QXmlStreamStringRef(entityDeclaration.notationName);
1740  publicEntityDeclaration.m_systemId = QXmlStreamStringRef(entityDeclaration.systemId);
1741  publicEntityDeclaration.m_publicId = QXmlStreamStringRef(entityDeclaration.publicId);
1742  publicEntityDeclaration.m_value = QXmlStreamStringRef(entityDeclaration.value);
1743  }
1744  entityDeclarations.clear();
1745  parameterEntityHash.clear();
1746 }
QXmlStreamStringRef m_name
Definition: qxmlstream.h:228
The QXmlStreamEntityDeclaration class represents a DTD entity declaration.
Definition: qxmlstream.h:251
QXmlStreamStringRef m_notationName
Definition: qxmlstream.h:252
The QXmlStreamNotationDeclaration class represents a DTD notation declaration.
Definition: qxmlstream.h:227
QXmlStreamStringRef m_publicId
Definition: qxmlstream.h:228
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
QHash< QString, Entity > parameterEntityHash
Definition: qxmlstream_p.h:771
QXmlStreamStringRef m_systemId
Definition: qxmlstream.h:228
QXmlStreamStringRef m_systemId
Definition: qxmlstream.h:252
QXmlStreamStringRef m_name
Definition: qxmlstream.h:252
QXmlStreamNotationDeclarations publicNotationDeclarations
Definition: qxmlstream_p.h:838
QXmlStreamSimpleStack< NotationDeclaration > notationDeclarations
Definition: qxmlstream_p.h:837
QXmlStreamStringRef m_value
Definition: qxmlstream.h:252
QXmlStreamStringRef m_publicId
Definition: qxmlstream.h:252
QXmlStreamEntityDeclarations publicEntityDeclarations
Definition: qxmlstream_p.h:859
QXmlStreamSimpleStack< EntityDeclaration > entityDeclarations
Definition: qxmlstream_p.h:858

◆ resolvePublicNamespaces()

void QXmlStreamReaderPrivate::resolvePublicNamespaces ( )

Definition at line 1709 of file qxmlstream.cpp.

1710 {
1711  const Tag &tag = tagStack.top();
1712  int n = namespaceDeclarations.size() - tag.namespaceDeclarationsSize;
1714  for (int i = 0; i < n; ++i) {
1715  const NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(tag.namespaceDeclarationsSize + i);
1716  QXmlStreamNamespaceDeclaration &publicNamespaceDeclaration = publicNamespaceDeclarations[i];
1717  publicNamespaceDeclaration.m_prefix = QXmlStreamStringRef(namespaceDeclaration.prefix);
1718  publicNamespaceDeclaration.m_namespaceUri = QXmlStreamStringRef(namespaceDeclaration.namespaceUri);
1719  }
1720 }
Tag
Definition: qtranslator.cpp:86
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
QXmlStreamSimpleStack< NamespaceDeclaration > namespaceDeclarations
Definition: qxmlstream_p.h:697
QXmlStreamStringRef m_namespaceUri
Definition: qxmlstream.h:205
The QXmlStreamNamespaceDeclaration class represents a namespace declaration.
Definition: qxmlstream.h:204
QXmlStreamStringRef m_prefix
Definition: qxmlstream.h:205
QXmlStreamSimpleStack< Tag > tagStack
Definition: qxmlstream_p.h:721
QXmlStreamNamespaceDeclarations publicNamespaceDeclarations
Definition: qxmlstream_p.h:839

◆ resolveTag()

void QXmlStreamReaderPrivate::resolveTag ( )

Definition at line 1605 of file qxmlstream.cpp.

1606 {
1607  int n = attributeStack.size();
1608 
1609  if (namespaceProcessing) {
1610  for (int a = 0; a < dtdAttributes.size(); ++a) {
1611  DtdAttribute &dtdAttribute = dtdAttributes[a];
1612  if (!dtdAttribute.isNamespaceAttribute
1613  || dtdAttribute.defaultValue.isNull()
1614  || dtdAttribute.tagName != qualifiedName
1615  || dtdAttribute.attributeQualifiedName.isNull())
1616  continue;
1617  int i = 0;
1618  while (i < n && symName(attributeStack[i].key) != dtdAttribute.attributeQualifiedName)
1619  ++i;
1620  if (i != n)
1621  continue;
1622  if (dtdAttribute.attributePrefix.isEmpty() && dtdAttribute.attributeName == QLatin1String("xmlns")) {
1623  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
1624  namespaceDeclaration.prefix.clear();
1625 
1626  const QStringRef ns(dtdAttribute.defaultValue);
1627  if(ns == QLatin1String("http://www.w3.org/2000/xmlns/") ||
1628  ns == QLatin1String("http://www.w3.org/XML/1998/namespace"))
1629  raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration."));
1630  else
1631  namespaceDeclaration.namespaceUri = ns;
1632  } else if (dtdAttribute.attributePrefix == QLatin1String("xmlns")) {
1633  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
1634  QStringRef namespacePrefix = dtdAttribute.attributeName;
1635  QStringRef namespaceUri = dtdAttribute.defaultValue;
1636  if (((namespacePrefix == QLatin1String("xml"))
1637  ^ (namespaceUri == QLatin1String("http://www.w3.org/XML/1998/namespace")))
1638  || namespaceUri == QLatin1String("http://www.w3.org/2000/xmlns/")
1639  || namespaceUri.isEmpty()
1640  || namespacePrefix == QLatin1String("xmlns"))
1641  raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration."));
1642 
1643  namespaceDeclaration.prefix = namespacePrefix;
1644  namespaceDeclaration.namespaceUri = namespaceUri;
1645  }
1646  }
1647  }
1648 
1649  tagStack.top().namespaceDeclaration.namespaceUri = namespaceUri = namespaceForPrefix(prefix);
1650 
1651  attributes.resize(n);
1652 
1653  for (int i = 0; i < n; ++i) {
1654  QXmlStreamAttribute &attribute = attributes[i];
1655  Attribute &attrib = attributeStack[i];
1656  QStringRef prefix(symPrefix(attrib.key));
1657  QStringRef name(symString(attrib.key));
1658  QStringRef qualifiedName(symName(attrib.key));
1659  QStringRef value(symString(attrib.value));
1660 
1661  attribute.m_name = QXmlStreamStringRef(name);
1663  attribute.m_value = QXmlStreamStringRef(value);
1664 
1665  if (!prefix.isEmpty()) {
1666  QStringRef attributeNamespaceUri = namespaceForPrefix(prefix);
1667  attribute.m_namespaceUri = QXmlStreamStringRef(attributeNamespaceUri);
1668  }
1669 
1670  for (int j = 0; j < i; ++j) {
1671  if (attributes[j].name() == attribute.name()
1672  && attributes[j].namespaceUri() == attribute.namespaceUri()
1673  && (namespaceProcessing || attributes[j].qualifiedName() == attribute.qualifiedName()))
1674  raiseWellFormedError(QXmlStream::tr("Attribute redefined."));
1675  }
1676  }
1677 
1678  for (int a = 0; a < dtdAttributes.size(); ++a) {
1679  DtdAttribute &dtdAttribute = dtdAttributes[a];
1680  if (dtdAttribute.isNamespaceAttribute
1681  || dtdAttribute.defaultValue.isNull()
1682  || dtdAttribute.tagName != qualifiedName
1683  || dtdAttribute.attributeQualifiedName.isNull())
1684  continue;
1685  int i = 0;
1686  while (i < n && symName(attributeStack[i].key) != dtdAttribute.attributeQualifiedName)
1687  ++i;
1688  if (i != n)
1689  continue;
1690 
1691 
1692 
1693  QXmlStreamAttribute attribute;
1694  attribute.m_name = QXmlStreamStringRef(dtdAttribute.attributeName);
1695  attribute.m_qualifiedName = QXmlStreamStringRef(dtdAttribute.attributeQualifiedName);
1696  attribute.m_value = QXmlStreamStringRef(dtdAttribute.defaultValue);
1697 
1698  if (!dtdAttribute.attributePrefix.isEmpty()) {
1699  QStringRef attributeNamespaceUri = namespaceForPrefix(dtdAttribute.attributePrefix);
1700  attribute.m_namespaceUri = QXmlStreamStringRef(attributeNamespaceUri);
1701  }
1702  attribute.m_isDefault = true;
1703  attributes.append(attribute);
1704  }
1705 
1706  attributeStack.clear();
1707 }
QXmlStreamStringRef m_namespaceUri
Definition: qxmlstream.h:136
QXmlStreamSimpleStack< DtdAttribute > dtdAttributes
Definition: qxmlstream_p.h:831
QXmlStreamAttributes attributes
Definition: qxmlstream_p.h:808
QXmlStreamSimpleStack< Attribute > attributeStack
Definition: qxmlstream_p.h:918
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
QStringRef qualifiedName() const
Returns the attribute&#39;s qualified name.
Definition: qxmlstream.h:150
QXmlStreamStringRef m_value
Definition: qxmlstream.h:136
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
QXmlStreamStringRef m_name
Definition: qxmlstream.h:136
The QXmlStreamAttribute class represents a single XML attribute.
Definition: qxmlstream.h:135
QXmlStreamSimpleStack< NamespaceDeclaration > namespaceDeclarations
Definition: qxmlstream_p.h:697
bool isEmpty() const
Returns true if the string reference has no characters; otherwise returns false.
Definition: qstring.h:1169
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QXmlStreamStringRef m_qualifiedName
Definition: qxmlstream.h:136
QStringRef name() const
Returns the attribute&#39;s local name.
Definition: qxmlstream.h:149
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
QStringRef namespaceForPrefix(const QStringRef &prefix)
QStringRef symName(int index)
Definition: qxmlstream_p.h:924
int key
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170
void raiseWellFormedError(const QString &message)
QXmlStreamSimpleStack< Tag > tagStack
Definition: qxmlstream_p.h:721
QStringRef symString(int index)
Definition: qxmlstream_p.h:920
void append(const QString &namespaceUri, const QString &name, const QString &value)
Appends a new attribute with name in the namespace described with namespaceUri, and value value...
QStringRef symPrefix(int index)
Definition: qxmlstream_p.h:932
QStringRef namespaceUri() const
Returns the attribute&#39;s resolved namespaceUri, or an empty string reference if the attribute does not...
Definition: qxmlstream.h:148

◆ resolveUndeclaredEntity()

QString QXmlStreamReaderPrivate::resolveUndeclaredEntity ( const QString name)

Definition at line 224 of file qxmlstream.cpp.

225 {
226  if (entityResolver)
228  return QString();
229 }
QXmlStreamEntityResolver * entityResolver
Definition: qxmlstream_p.h:999
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual QString resolveUndeclaredEntity(const QString &name)
Resolves the undeclared entity name and returns its replacement text.
Definition: qxmlstream.cpp:217

◆ resume()

void QXmlStreamReaderPrivate::resume ( int  rule)

Definition at line 1949 of file qxmlstream.cpp.

1949  {
1950  resumeReduction = rule;
1953 }
void raiseError(QXmlStreamReader::Error error, const QString &message=QString())
QXmlStreamReader::Error error
Definition: qxmlstream_p.h:797

◆ scanAfterDefaultDecl()

bool QXmlStreamReaderPrivate::scanAfterDefaultDecl ( )

Definition at line 1127 of file qxmlstream.cpp.

1128 {
1129  switch (peekChar()) {
1130  case 'R':
1131  return scanString(spell[REQUIRED], REQUIRED, false);
1132  case 'I':
1133  return scanString(spell[IMPLIED], IMPLIED, false);
1134  case 'F':
1135  return scanString(spell[FIXED], FIXED, false);
1136  default:
1137  ;
1138  }
1139  return false;
1140 }
bool scanString(const char *str, short tokenToInject, bool requireSpace=true)
static const char *const spell[]
Definition: qxmlstream_p.h:134

◆ scanAfterLangleBang()

bool QXmlStreamReaderPrivate::scanAfterLangleBang ( )

Definition at line 1082 of file qxmlstream.cpp.

1083 {
1084  switch (peekChar()) {
1085  case '[':
1086  return scanString(spell[CDATA_START], CDATA_START, false);
1087  case 'D':
1088  return scanString(spell[DOCTYPE], DOCTYPE);
1089  case 'A':
1090  return scanString(spell[ATTLIST], ATTLIST);
1091  case 'N':
1092  return scanString(spell[NOTATION], NOTATION);
1093  case 'E':
1094  if (scanString(spell[ELEMENT], ELEMENT))
1095  return true;
1096  return scanString(spell[ENTITY], ENTITY);
1097 
1098  default:
1099  ;
1100  };
1101  return false;
1102 }
bool scanString(const char *str, short tokenToInject, bool requireSpace=true)
static const char *const spell[]
Definition: qxmlstream_p.h:134

◆ scanAttType()

bool QXmlStreamReaderPrivate::scanAttType ( )

Definition at line 1142 of file qxmlstream.cpp.

1143 {
1144  switch (peekChar()) {
1145  case 'C':
1146  return scanString(spell[CDATA], CDATA);
1147  case 'I':
1148  if (scanString(spell[ID], ID))
1149  return true;
1150  if (scanString(spell[IDREF], IDREF))
1151  return true;
1152  return scanString(spell[IDREFS], IDREFS);
1153  case 'E':
1154  if (scanString(spell[ENTITY], ENTITY))
1155  return true;
1156  return scanString(spell[ENTITIES], ENTITIES);
1157  case 'N':
1158  if (scanString(spell[NOTATION], NOTATION))
1159  return true;
1160  if (scanString(spell[NMTOKEN], NMTOKEN))
1161  return true;
1162  return scanString(spell[NMTOKENS], NMTOKENS);
1163  default:
1164  ;
1165  }
1166  return false;
1167 }
bool scanString(const char *str, short tokenToInject, bool requireSpace=true)
static const char *const spell[]
Definition: qxmlstream_p.h:134

◆ scanNData()

bool QXmlStreamReaderPrivate::scanNData ( )

Definition at line 1117 of file qxmlstream.cpp.

1118 {
1119  if (fastScanSpace()) {
1120  if (scanString(spell[NDATA], NDATA))
1121  return true;
1122  putChar(' ');
1123  }
1124  return false;
1125 }
bool scanString(const char *str, short tokenToInject, bool requireSpace=true)
static const char *const spell[]
Definition: qxmlstream_p.h:134

◆ scanPublicOrSystem()

bool QXmlStreamReaderPrivate::scanPublicOrSystem ( )

Definition at line 1104 of file qxmlstream.cpp.

1105 {
1106  switch (peekChar()) {
1107  case 'S':
1108  return scanString(spell[SYSTEM], SYSTEM);
1109  case 'P':
1110  return scanString(spell[PUBLIC], PUBLIC);
1111  default:
1112  ;
1113  }
1114  return false;
1115 }
bool scanString(const char *str, short tokenToInject, bool requireSpace=true)
static const char *const spell[]
Definition: qxmlstream_p.h:134

◆ scanString()

bool QXmlStreamReaderPrivate::scanString ( const char *  str,
short  tokenToInject,
bool  requireSpace = true 
)

Definition at line 1051 of file qxmlstream.cpp.

Referenced by checkStartDocument(), scanAfterDefaultDecl(), scanAfterLangleBang(), scanAttType(), scanNData(), scanPublicOrSystem(), and scanUntil().

1052 {
1053  int n = 0;
1054  while (str[n]) {
1055  ushort c = getChar();
1056  if (c != ushort(str[n])) {
1057  if (c)
1058  putChar(c);
1059  while (n--) {
1060  putChar(ushort(str[n]));
1061  }
1062  return false;
1063  }
1064  ++n;
1065  }
1066  for (int i = 0; i < n; ++i)
1067  textBuffer += QChar(ushort(str[i]));
1068  if (requireSpace) {
1069  int s = fastScanSpace();
1070  if (!s || atEnd) {
1071  int pos = textBuffer.size() - n - s;
1072  putString(textBuffer, pos);
1073  textBuffer.resize(pos);
1074  return false;
1075  }
1076  }
1077  if (tokenToInject >= 0)
1078  injectToken(tokenToInject);
1079  return true;
1080 }
unsigned char c[8]
Definition: qnumeric_p.h:62
void injectToken(ushort tokenToInject)
Definition: qxmlstream_p.h:969
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
unsigned short ushort
Definition: qglobal.h:995
void putString(const QString &s, int from=0)

◆ scanUntil()

bool QXmlStreamReaderPrivate::scanUntil ( const char *  str,
short  tokenToInject = -1 
)

Scans characters until str is encountered, and validates the characters as according to the Char[2] production and do the line-ending normalization.

Warning
This function is not part of the public interface.

If any character is invalid, false is returned, otherwise true upon success.

If tokenToInject is not less than zero, injectToken() is called with tokenToInject when str is found.

If any error occurred, false is returned, otherwise true.

Definition at line 1004 of file qxmlstream.cpp.

1005 {
1006  int pos = textBuffer.size();
1007  int oldLineNumber = lineNumber;
1008 
1009  while (uint c = getChar()) {
1010  /* First, we do the validation & normalization. */
1011  switch (c) {
1012  case '\r':
1013  if ((c = filterCarriageReturn()) == 0)
1014  break;
1015  // fall through
1016  case '\n':
1017  ++lineNumber;
1019  // fall through
1020  case '\t':
1021  textBuffer += QChar(c);
1022  continue;
1023  default:
1024  if(c < 0x20 || (c > 0xFFFD && c < 0x10000) || c > 0x10FFFF ) {
1025  raiseWellFormedError(QXmlStream::tr("Invalid XML character."));
1026  lineNumber = oldLineNumber;
1027  return false;
1028  }
1029  textBuffer += QChar(c);
1030  }
1031 
1032 
1033  /* Second, attempt to lookup str. */
1034  if (c == uint(*str)) {
1035  if (!*(str + 1)) {
1036  if (tokenToInject >= 0)
1037  injectToken(tokenToInject);
1038  return true;
1039  } else {
1040  if (scanString(str + 1, tokenToInject, false))
1041  return true;
1042  }
1043  }
1044  }
1045  putString(textBuffer, pos);
1046  textBuffer.resize(pos);
1047  lineNumber = oldLineNumber;
1048  return false;
1049 }
unsigned char c[8]
Definition: qnumeric_p.h:62
bool scanString(const char *str, short tokenToInject, bool requireSpace=true)
void injectToken(ushort tokenToInject)
Definition: qxmlstream_p.h:969
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
unsigned int uint
Definition: qglobal.h:996
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
void putString(const QString &s, int from=0)
void raiseWellFormedError(const QString &message)

◆ setType()

void QXmlStreamReaderPrivate::setType ( const QXmlStreamReader::TokenType  t)
inlineprivate

Never assign to variable type directly.

Warning
This function is not part of the public interface. Instead use this function.
  This prevents errors from being ignored.

Definition at line 1010 of file qxmlstream_p.h.

1011  {
1013  type = t;
1014  }
QXmlStreamReader::TokenType type
Definition: qxmlstream_p.h:796

◆ startDocument()

void QXmlStreamReaderPrivate::startDocument ( )

Definition at line 1812 of file qxmlstream.cpp.

1813 {
1814  QString err;
1815  if (documentVersion != QLatin1String("1.0")) {
1817  err = QXmlStream::tr("Invalid XML version string.");
1818  else
1819  err = QXmlStream::tr("Unsupported XML version.");
1820  }
1821  int n = attributeStack.size();
1822 
1823  /* We use this bool to ensure that the pesudo attributes are in the
1824  * proper order:
1825  *
1826  * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' */
1827  bool hasStandalone = false;
1828 
1829  for (int i = 0; err.isNull() && i < n; ++i) {
1830  Attribute &attrib = attributeStack[i];
1831  QStringRef prefix(symPrefix(attrib.key));
1832  QStringRef key(symString(attrib.key));
1833  QStringRef value(symString(attrib.value));
1834 
1835  if (prefix.isEmpty() && key == QLatin1String("encoding")) {
1836  const QString name(value.toString());
1837  documentEncoding = value;
1838 
1839  if(hasStandalone)
1840  err = QXmlStream::tr("The standalone pseudo attribute must appear after the encoding.");
1842  err = QXmlStream::tr("%1 is an invalid encoding name.").arg(name);
1843  else {
1844 #ifdef QT_NO_TEXTCODEC
1846 #else
1847  QTextCodec *const newCodec = QTextCodec::codecForName(name.toLatin1());
1848  if (!newCodec)
1849  err = QXmlStream::tr("Encoding %1 is unsupported").arg(name);
1850  else if (newCodec != codec && !lockEncoding) {
1851  codec = newCodec;
1852  delete decoder;
1853  decoder = codec->makeDecoder();
1855  }
1856 #endif // QT_NO_TEXTCODEC
1857  }
1858  } else if (prefix.isEmpty() && key == QLatin1String("standalone")) {
1859  hasStandalone = true;
1860  if (value == QLatin1String("yes"))
1861  standalone = true;
1862  else if (value == QLatin1String("no"))
1863  standalone = false;
1864  else
1865  err = QXmlStream::tr("Standalone accepts only yes or no.");
1866  } else {
1867  err = QXmlStream::tr("Invalid attribute in XML declaration.");
1868  }
1869  }
1870 
1871  if (!err.isNull())
1872  raiseWellFormedError(err);
1873  attributeStack.clear();
1874 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QTextDecoder * makeDecoder() const
Creates a QTextDecoder which stores enough state to decode chunks of char * data to create chunks of ...
QXmlStreamSimpleStack< Attribute > attributeStack
Definition: qxmlstream_p.h:918
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string reference has no characters; otherwise returns false.
Definition: qstring.h:1169
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
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
int key
QString toUnicode(const char *chars, int len)
Converts the first len bytes in chars to Unicode, returning the result.
static QTextCodec * codecForName(const QByteArray &name)
Searches all installed QTextCodec objects and returns the one which best matches name; the match is c...
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:9788
void raiseWellFormedError(const QString &message)
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62
QStringRef symString(int index)
Definition: qxmlstream_p.h:920
QTextDecoder * decoder
Definition: qxmlstream_p.h:789
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QStringRef symPrefix(int index)
Definition: qxmlstream_p.h:932
static bool isEncName(const QString &encName)
Determines whether encName is a valid instance of production [81]EncName in the XML 1...
Definition: qxmlutils.cpp:234

◆ sym()

Value& QXmlStreamReaderPrivate::sym ( int  index) const
inline

Definition at line 905 of file qxmlstream_p.h.

Referenced by resolveCharRef().

906  { return sym_stack[tos + index - 1]; }
quint16 index

◆ symName() [1/2]

QStringRef QXmlStreamReaderPrivate::symName ( int  index)
inline

Definition at line 924 of file qxmlstream_p.h.

Referenced by resolveTag().

924  {
925  const Value &symbol = sym(index);
926  return QStringRef(&textBuffer, symbol.pos, symbol.len);
927  }
Value & sym(int index) const
Definition: qxmlstream_p.h:905
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
quint16 index

◆ symName() [2/2]

QStringRef QXmlStreamReaderPrivate::symName ( const Value symbol)
inline

Definition at line 941 of file qxmlstream_p.h.

941  {
942  return QStringRef(&textBuffer, symbol.pos, symbol.len);
943  }
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099

◆ symPrefix() [1/2]

QStringRef QXmlStreamReaderPrivate::symPrefix ( int  index)
inline

Definition at line 932 of file qxmlstream_p.h.

Referenced by resolveTag(), and startDocument().

932  {
933  const Value &symbol = sym(index);
934  if (symbol.prefix)
935  return QStringRef(&textBuffer, symbol.pos, symbol.prefix - 1);
936  return QStringRef();
937  }
Value & sym(int index) const
Definition: qxmlstream_p.h:905
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
quint16 index

◆ symPrefix() [2/2]

QStringRef QXmlStreamReaderPrivate::symPrefix ( const Value symbol)
inline

Definition at line 944 of file qxmlstream_p.h.

944  {
945  if (symbol.prefix)
946  return QStringRef(&textBuffer, symbol.pos, symbol.prefix - 1);
947  return QStringRef();
948  }
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099

◆ symString() [1/3]

QStringRef QXmlStreamReaderPrivate::symString ( int  index)
inline

Definition at line 920 of file qxmlstream_p.h.

Referenced by resolveCharRef(), resolveTag(), and startDocument().

920  {
921  const Value &symbol = sym(index);
922  return QStringRef(&textBuffer, symbol.pos + symbol.prefix, symbol.len - symbol.prefix);
923  }
Value & sym(int index) const
Definition: qxmlstream_p.h:905
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
quint16 index

◆ symString() [2/3]

QStringRef QXmlStreamReaderPrivate::symString ( int  index,
int  offset 
)
inline

Definition at line 928 of file qxmlstream_p.h.

928  {
929  const Value &symbol = sym(index);
930  return QStringRef(&textBuffer, symbol.pos + symbol.prefix + offset, symbol.len - symbol.prefix - offset);
931  }
Value & sym(int index) const
Definition: qxmlstream_p.h:905
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
quint16 index

◆ symString() [3/3]

QStringRef QXmlStreamReaderPrivate::symString ( const Value symbol)
inline

Definition at line 938 of file qxmlstream_p.h.

938  {
939  return QStringRef(&textBuffer, symbol.pos + symbol.prefix, symbol.len - symbol.prefix);
940  }
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099

◆ write() [1/2]

void QXmlStreamReaderPrivate::write ( const QString )

◆ write() [2/2]

void QXmlStreamReaderPrivate::write ( const char *  )

Properties

◆ atEnd

bool QXmlStreamReaderPrivate::atEnd

◆ attributes

QXmlStreamAttributes QXmlStreamReaderPrivate::attributes

Definition at line 808 of file qxmlstream_p.h.

Referenced by init(), and resolveTag().

◆ attributeStack

QXmlStreamSimpleStack<Attribute> QXmlStreamReaderPrivate::attributeStack

Definition at line 918 of file qxmlstream_p.h.

Referenced by init(), resolveTag(), and startDocument().

◆ characterOffset

qint64 QXmlStreamReaderPrivate::characterOffset

◆ codec

QTextCodec* QXmlStreamReaderPrivate::codec

Definition at line 788 of file qxmlstream_p.h.

Referenced by getChar_helper(), init(), and startDocument().

◆ dataBuffer

QByteArray QXmlStreamReaderPrivate::dataBuffer

Definition at line 751 of file qxmlstream_p.h.

Referenced by getChar_helper(), and init().

◆ decoder

QTextDecoder* QXmlStreamReaderPrivate::decoder

◆ deleteDevice

bool QXmlStreamReaderPrivate::deleteDevice

◆ device

QIODevice* QXmlStreamReaderPrivate::device

◆ documentEncoding

QStringRef QXmlStreamReaderPrivate::documentEncoding

Definition at line 866 of file qxmlstream_p.h.

Referenced by startDocument().

◆ documentVersion

QStringRef QXmlStreamReaderPrivate::documentVersion

Definition at line 866 of file qxmlstream_p.h.

Referenced by startDocument().

◆ dtdAttributes

QXmlStreamSimpleStack<DtdAttribute> QXmlStreamReaderPrivate::dtdAttributes

Definition at line 831 of file qxmlstream_p.h.

Referenced by resolveTag().

◆ dtdName

QStringRef QXmlStreamReaderPrivate::dtdName

Definition at line 865 of file qxmlstream_p.h.

◆ dtdPublicId

QStringRef QXmlStreamReaderPrivate::dtdPublicId

Definition at line 865 of file qxmlstream_p.h.

◆ dtdSystemId

QStringRef QXmlStreamReaderPrivate::dtdSystemId

Definition at line 865 of file qxmlstream_p.h.

◆ entityDeclarations

QXmlStreamSimpleStack<EntityDeclaration> QXmlStreamReaderPrivate::entityDeclarations

Definition at line 858 of file qxmlstream_p.h.

Referenced by resolveDtd().

◆ entityHash

QHash<QString, Entity> QXmlStreamReaderPrivate::entityHash

Definition at line 770 of file qxmlstream_p.h.

Referenced by QXmlStreamReaderPrivate().

◆ entityParser

QXmlStreamReaderPrivate* QXmlStreamReaderPrivate::entityParser

Definition at line 975 of file qxmlstream_p.h.

Referenced by init(), parseEntity(), and ~QXmlStreamReaderPrivate().

◆ entityReferenceStack

QXmlStreamSimpleStack<Entity *> QXmlStreamReaderPrivate::entityReferenceStack

Definition at line 772 of file qxmlstream_p.h.

◆ entityResolver

QXmlStreamEntityResolver* QXmlStreamReaderPrivate::entityResolver

Definition at line 999 of file qxmlstream_p.h.

Referenced by QXmlStreamReaderPrivate().

◆ error

QXmlStreamReader::Error QXmlStreamReaderPrivate::error

Definition at line 797 of file qxmlstream_p.h.

Referenced by init(), raiseError(), and resume().

◆ errorString

QString QXmlStreamReaderPrivate::errorString

Definition at line 798 of file qxmlstream_p.h.

Referenced by raiseError().

◆ firstByte

uchar QXmlStreamReaderPrivate::firstByte

Definition at line 752 of file qxmlstream_p.h.

◆ hasCheckedStartDocument

uint QXmlStreamReaderPrivate::hasCheckedStartDocument

Definition at line 871 of file qxmlstream_p.h.

Referenced by checkStartDocument(), and init().

◆ hasExternalDtdSubset

uint QXmlStreamReaderPrivate::hasExternalDtdSubset

Definition at line 877 of file qxmlstream_p.h.

Referenced by init().

◆ hasSeenTag

uint QXmlStreamReaderPrivate::hasSeenTag

Definition at line 873 of file qxmlstream_p.h.

Referenced by init().

◆ inParseEntity

uint QXmlStreamReaderPrivate::inParseEntity

Definition at line 874 of file qxmlstream_p.h.

Referenced by init(), and parseEntity().

◆ isCDATA

uint QXmlStreamReaderPrivate::isCDATA

Definition at line 869 of file qxmlstream_p.h.

Referenced by init().

◆ isEmptyElement

uint QXmlStreamReaderPrivate::isEmptyElement

Definition at line 867 of file qxmlstream_p.h.

Referenced by init().

◆ isWhitespace

uint QXmlStreamReaderPrivate::isWhitespace

Definition at line 868 of file qxmlstream_p.h.

Referenced by fastScanContentCharList(), and init().

◆ lastAttributeIsCData

bool QXmlStreamReaderPrivate::lastAttributeIsCData

Definition at line 821 of file qxmlstream_p.h.

◆ lastAttributeValue

QStringRef QXmlStreamReaderPrivate::lastAttributeValue

Definition at line 820 of file qxmlstream_p.h.

◆ lastLineStart

qint64 QXmlStreamReaderPrivate::lastLineStart

◆ lineNumber

qint64 QXmlStreamReaderPrivate::lineNumber

◆ lockEncoding

uint QXmlStreamReaderPrivate::lockEncoding

Definition at line 878 of file qxmlstream_p.h.

Referenced by getChar_helper(), init(), and startDocument().

◆ name

QStringRef QXmlStreamReaderPrivate::name

Definition at line 863 of file qxmlstream_p.h.

Referenced by resolveTag(), startDocument(), and QXmlStreamWriterPrivate::write().

◆ namespaceProcessing

uint QXmlStreamReaderPrivate::namespaceProcessing

Definition at line 879 of file qxmlstream_p.h.

Referenced by init(), namespaceForPrefix(), and resolveTag().

◆ namespaceUri

QStringRef QXmlStreamReaderPrivate::namespaceUri

◆ nbytesread

qint64 QXmlStreamReaderPrivate::nbytesread

Definition at line 753 of file qxmlstream_p.h.

Referenced by getChar_helper(), init(), and startDocument().

◆ normalizeLiterals

uint QXmlStreamReaderPrivate::normalizeLiterals

Definition at line 872 of file qxmlstream_p.h.

Referenced by fastScanLiteralContent(), and init().

◆ notationDeclarations

QXmlStreamSimpleStack<NotationDeclaration> QXmlStreamReaderPrivate::notationDeclarations

Definition at line 837 of file qxmlstream_p.h.

Referenced by resolveDtd().

◆ parameterEntityHash

QHash<QString, Entity> QXmlStreamReaderPrivate::parameterEntityHash

Definition at line 771 of file qxmlstream_p.h.

Referenced by resolveDtd().

◆ prefix

QStringRef QXmlStreamReaderPrivate::prefix

◆ processingInstructionData

QStringRef QXmlStreamReaderPrivate::processingInstructionData

Definition at line 864 of file qxmlstream_p.h.

◆ processingInstructionTarget

QStringRef QXmlStreamReaderPrivate::processingInstructionTarget

Definition at line 864 of file qxmlstream_p.h.

◆ publicEntityDeclarations

QXmlStreamEntityDeclarations QXmlStreamReaderPrivate::publicEntityDeclarations

Definition at line 859 of file qxmlstream_p.h.

Referenced by resolveDtd().

◆ publicNamespaceDeclarations

QXmlStreamNamespaceDeclarations QXmlStreamReaderPrivate::publicNamespaceDeclarations

Definition at line 839 of file qxmlstream_p.h.

Referenced by resolvePublicNamespaces().

◆ publicNotationDeclarations

QXmlStreamNotationDeclarations QXmlStreamReaderPrivate::publicNotationDeclarations

Definition at line 838 of file qxmlstream_p.h.

Referenced by resolveDtd().

◆ putStack

QXmlStreamSimpleStack<uint> QXmlStreamReaderPrivate::putStack

◆ q_ptr

QXmlStreamReader* QXmlStreamReaderPrivate::q_ptr
private

Definition at line 743 of file qxmlstream_p.h.

◆ qualifiedName

QStringRef QXmlStreamReaderPrivate::qualifiedName

Definition at line 863 of file qxmlstream_p.h.

Referenced by resolveTag(), and QXmlStreamAttributes::value().

◆ rawReadBuffer

QByteArray QXmlStreamReaderPrivate::rawReadBuffer

Definition at line 750 of file qxmlstream_p.h.

Referenced by getChar_helper(), init(), and startDocument().

◆ readBuffer

QString QXmlStreamReaderPrivate::readBuffer

Definition at line 754 of file qxmlstream_p.h.

Referenced by getChar(), getChar_helper(), init(), parseEntity(), peekChar(), and startDocument().

◆ readBufferPos

int QXmlStreamReaderPrivate::readBufferPos

◆ referenceToParameterEntityDetected

uint QXmlStreamReaderPrivate::referenceToParameterEntityDetected

Definition at line 876 of file qxmlstream_p.h.

Referenced by init().

◆ referenceToUnparsedEntityDetected

uint QXmlStreamReaderPrivate::referenceToUnparsedEntityDetected

Definition at line 875 of file qxmlstream_p.h.

Referenced by init().

◆ resumeReduction

int QXmlStreamReaderPrivate::resumeReduction

Definition at line 881 of file qxmlstream_p.h.

Referenced by init(), and resume().

◆ scanDtd

bool QXmlStreamReaderPrivate::scanDtd

Definition at line 819 of file qxmlstream_p.h.

Referenced by init().

◆ stack_size

int QXmlStreamReaderPrivate::stack_size

Definition at line 894 of file qxmlstream_p.h.

Referenced by QXmlStreamReaderPrivate(), and reallocateStack().

◆ standalone

uint QXmlStreamReaderPrivate::standalone

Definition at line 870 of file qxmlstream_p.h.

Referenced by init(), and startDocument().

◆ state_stack

int* QXmlStreamReaderPrivate::state_stack

◆ sym_stack

Value* QXmlStreamReaderPrivate::sym_stack

◆ text

QStringRef QXmlStreamReaderPrivate::text

Definition at line 861 of file qxmlstream_p.h.

◆ textBuffer

QString QXmlStreamReaderPrivate::textBuffer

◆ token

short QXmlStreamReaderPrivate::token

Definition at line 953 of file qxmlstream_p.h.

Referenced by init(), and parseError().

◆ token_char

ushort QXmlStreamReaderPrivate::token_char

Definition at line 954 of file qxmlstream_p.h.

Referenced by init().

◆ tos

int QXmlStreamReaderPrivate::tos

Definition at line 893 of file qxmlstream_p.h.

Referenced by init(), and parseError().

◆ type

QXmlStreamReader::TokenType QXmlStreamReaderPrivate::type
See also
setType()

Definition at line 796 of file qxmlstream_p.h.

Referenced by checkStartDocument(), init(), parseEntity(), and raiseError().

◆ unresolvedEntity

QString QXmlStreamReaderPrivate::unresolvedEntity

Definition at line 799 of file qxmlstream_p.h.


The documentation for this class was generated from the following files: