Qt 4.8
Static Public Functions | Private Types | Static Private Functions | List of all members
QXmlUtils Class Reference

This class contains helper functions related to XML, for validating character classes, productions in the XML specification, and so on. More...

#include <qxmlutils_p.h>

Static Public Functions

static bool isChar (const QChar c)
 Determines whether c is a valid instance of production [2]Char in the XML 1.0 specification. More...
 
static bool isEncName (const QString &encName)
 Determines whether encName is a valid instance of production [81]EncName in the XML 1.0 specification. More...
 
static bool isLetter (const QChar c)
 Determines whether c is a valid instance of production [84]Letter in the XML 1.0 specification. More...
 
static bool isNameChar (const QChar c)
 Determines whether c is a valid instance of production [4]NameChar in the XML 1.0 specification. More...
 
static bool isNCName (const QStringRef &ncName)
 Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specification. More...
 
static bool isNCName (const QString &ncName)
 
static bool isPublicID (const QString &candidate)
 Determines whether c is a valid instance of production [12] PubidLiteral in the XML 1.0 specification. More...
 

Private Types

typedef const QXmlCharRangeRangeIter
 

Static Private Functions

static bool isBaseChar (const QChar c)
 
static bool isCombiningChar (const QChar c)
 
static bool isDigit (const QChar c)
 
static bool isExtender (const QChar c)
 
static bool isIdeographic (const QChar c)
 
static bool rangeContains (RangeIter begin, RangeIter end, const QChar c)
 Performs a binary search between begin and end inclusive, to check whether c is contained. More...
 

Detailed Description

This class contains helper functions related to XML, for validating character classes, productions in the XML specification, and so on.

Warning
This function is not part of the public interface.

Definition at line 69 of file qxmlutils_p.h.

Typedefs

◆ RangeIter

typedef const QXmlCharRange* QXmlUtils::RangeIter
private

Definition at line 81 of file qxmlutils_p.h.

Functions

◆ isBaseChar()

bool QXmlUtils::isBaseChar ( const QChar  c)
staticprivate

Definition at line 219 of file qxmlutils.cpp.

220 {
222 }
static bool rangeContains(RangeIter begin, RangeIter end, const QChar c)
Performs a binary search between begin and end inclusive, to check whether c is contained.
Definition: qxmlutils.cpp:67
static const RangeIter g_base_end
Definition: qxmlutils.cpp:149
static const QXmlCharRange g_base_begin[]
Definition: qxmlutils.cpp:105

◆ isChar()

bool QXmlUtils::isChar ( const QChar  c)
static

Determines whether c is a valid instance of production [2]Char in the XML 1.0 specification.

Warning
This function is not part of the public interface.

If it is, true is returned, otherwise false.

See also
http://www.w3.org/TR/REC-xml/#NT-Char {Extensible Markup Language (XML) 1.0 (Fourth Edition), [2] Char}

Definition at line 271 of file qxmlutils.cpp.

Referenced by fixedCharData(), and QPatternist::AccelTreeResourceLoader::retrieveUnparsedText().

272 {
273  return (c.unicode() >= 0x0020 && c.unicode() <= 0xD7FF)
274  || c.unicode() == 0x0009
275  || c.unicode() == 0x000A
276  || c.unicode() == 0x000D
277  || (c.unicode() >= 0xE000 && c.unicode() <= 0xFFFD);
278 }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251

◆ isCombiningChar()

bool QXmlUtils::isCombiningChar ( const QChar  c)
staticprivate

Definition at line 186 of file qxmlutils.cpp.

187 {
189 }
static bool rangeContains(RangeIter begin, RangeIter end, const QChar c)
Performs a binary search between begin and end inclusive, to check whether c is contained.
Definition: qxmlutils.cpp:67
static const QXmlCharRange g_combining_begin[]
Definition: qxmlutils.cpp:162
static const RangeIter g_combining_end
Definition: qxmlutils.cpp:184

◆ isDigit()

bool QXmlUtils::isDigit ( const QChar  c)
staticprivate

Definition at line 200 of file qxmlutils.cpp.

201 {
203 }
static bool rangeContains(RangeIter begin, RangeIter end, const QChar c)
Performs a binary search between begin and end inclusive, to check whether c is contained.
Definition: qxmlutils.cpp:67
static const QXmlCharRange g_digit_begin[]
Definition: qxmlutils.cpp:192
static const RangeIter g_digit_end
Definition: qxmlutils.cpp:198

◆ isEncName()

bool QXmlUtils::isEncName ( const QString encName)
static

Determines whether encName is a valid instance of production [81]EncName in the XML 1.0 specification.

Warning
This function is not part of the public interface.

If it is, true is returned, otherwise false.

See also
http://www.w3.org/TR/REC-xml/#NT-EncName {Extensible Markup Language (XML) 1.0 (Fourth Edition), [81] EncName}

Definition at line 234 of file qxmlutils.cpp.

Referenced by QXmlStreamReaderPrivate::startDocument().

235 {
236  /* Right, we here have a dependency on QRegExp. Writing a manual parser to
237  * replace that regexp is probably a 70 lines so I prioritize this to when
238  * the dependency is considered alarming, or when the rest of the bugs
239  * are fixed. */
240  const QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*"));
241  Q_ASSERT(encNameRegExp.isValid());
242 
243  return encNameRegExp.exactMatch(encName);
244 }
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ isExtender()

bool QXmlUtils::isExtender ( const QChar  c)
staticprivate

Definition at line 214 of file qxmlutils.cpp.

215 {
217 }
static bool rangeContains(RangeIter begin, RangeIter end, const QChar c)
Performs a binary search between begin and end inclusive, to check whether c is contained.
Definition: qxmlutils.cpp:67
static const QXmlCharRange g_extender_begin[]
Definition: qxmlutils.cpp:206
static const RangeIter g_extender_end
Definition: qxmlutils.cpp:212

◆ isIdeographic()

bool QXmlUtils::isIdeographic ( const QChar  c)
staticprivate

Definition at line 157 of file qxmlutils.cpp.

158 {
160 }
static bool rangeContains(RangeIter begin, RangeIter end, const QChar c)
Performs a binary search between begin and end inclusive, to check whether c is contained.
Definition: qxmlutils.cpp:67
static const QXmlCharRange g_ideographic_begin[]
Definition: qxmlutils.cpp:151
static const RangeIter g_ideographic_end
Definition: qxmlutils.cpp:155

◆ isLetter()

bool QXmlUtils::isLetter ( const QChar  c)
static

Determines whether c is a valid instance of production [84]Letter in the XML 1.0 specification.

Warning
This function is not part of the public interface.

If it is, true is returned, otherwise false.

See also
http://www.w3.org/TR/REC-xml/#NT-Letter {Extensible Markup Language (XML) 1.0 (Fourth Edition), [84] Letter}

Definition at line 256 of file qxmlutils.cpp.

Referenced by fixedXmlName(), and isNCName().

257 {
258  return isBaseChar(c) || isIdeographic(c);
259 }
static bool isBaseChar(const QChar c)
Definition: qxmlutils.cpp:219
static bool isIdeographic(const QChar c)
Definition: qxmlutils.cpp:157

◆ isNameChar()

bool QXmlUtils::isNameChar ( const QChar  c)
static

Determines whether c is a valid instance of production [4]NameChar in the XML 1.0 specification.

Warning
This function is not part of the public interface.

If it is, true is returned, otherwise false.

See also
http://www.w3.org/TR/REC-xml/#NT-NameChar {Extensible Markup Language (XML) 1.0 (Fourth Edition), [4] NameChar}

Definition at line 291 of file qxmlutils.cpp.

Referenced by fixedXmlName(), and isNCName().

292 {
293  return isBaseChar(c)
294  || isDigit(c)
295  || c.unicode() == '.'
296  || c.unicode() == '-'
297  || c.unicode() == '_'
298  || c.unicode() == ':'
299  || isCombiningChar(c)
300  || isIdeographic(c)
301  || isExtender(c);
302 }
static bool isBaseChar(const QChar c)
Definition: qxmlutils.cpp:219
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
static bool isExtender(const QChar c)
Definition: qxmlutils.cpp:214
static bool isIdeographic(const QChar c)
Definition: qxmlutils.cpp:157
static bool isDigit(const QChar c)
Definition: qxmlutils.cpp:200
static bool isCombiningChar(const QChar c)
Definition: qxmlutils.cpp:186

◆ isNCName() [1/2]

bool QXmlUtils::isNCName ( const QStringRef ncName)
static

Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specification.

Warning
This function is not part of the public interface.

If it is, true is returned, otherwise false.

See also
http://www.w3.org/TR/REC-xml-names/#NT-NCName {W3CNamespaces in XML 1.0 (Second Edition), [4] NCName}

Definition at line 377 of file qxmlutils.cpp.

Referenced by QPatternist::NamePool::allocateBinding(), QPatternist::NamePool::allocateQName(), QPatternist::AccelTreeBuilder< true >::attribute(), QPatternist::ComputedNamespaceConstructor::evaluateToSequenceReceiver(), QPatternist::DerivedString< TypeToken >::fromLexical(), QXmlName::isNCName(), QPatternist::XPathHelper::isQName(), StringSplitter::loadNext(), QXmlStreamReaderPrivate::parse(), QXmlName::QXmlName(), QPatternist::XsdSchemaParser::readNameAttribute(), QPatternist::XPathHelper::splitQName(), QPatternist::NamePool::unlockedAllocateLocalName(), QPatternist::NCNameConstructor::validateTargetName(), and QPatternist::yyparse().

378 {
379  if(ncName.isEmpty())
380  return false;
381 
382  const QChar first(ncName.at(0));
383 
384  if(!QXmlUtils::isLetter(first) && first.unicode() != '_' && first.unicode() != ':')
385  return false;
386 
387  const int len = ncName.size();
388  for(int i = 0; i < len; ++i)
389  {
390  const QChar &at = ncName.at(i);
391  if(!QXmlUtils::isNameChar(at) || at == QLatin1Char(':'))
392  return false;
393  }
394 
395  return true;
396 }
#define at(className, varName)
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
static bool isNameChar(const QChar c)
Determines whether c is a valid instance of production [4]NameChar in the XML 1.0 specification...
Definition: qxmlutils.cpp:291
bool isEmpty() const
Returns true if the string reference has no characters; otherwise returns false.
Definition: qstring.h:1169
static bool isLetter(const QChar c)
Determines whether c is a valid instance of production [84]Letter in the XML 1.0 specification.
Definition: qxmlutils.cpp:256
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const QChar at(int i) const
Returns the character at the given index position in the string reference.
Definition: qstring.h:1174

◆ isNCName() [2/2]

static bool QXmlUtils::isNCName ( const QString ncName)
inlinestatic

Definition at line 77 of file qxmlutils_p.h.

Referenced by isNCName().

77 { return isNCName(&ncName); }
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

◆ isPublicID()

bool QXmlUtils::isPublicID ( const QString candidate)
static

Determines whether c is a valid instance of production [12] PubidLiteral in the XML 1.0 specification.

Warning
This function is not part of the public interface.

If it is, true is returned, otherwise false.

See also
http://www.w3.org/TR/REC-xml/#NT-PubidLiteral {Extensible Markup Language (XML) 1.0 (Fourth Edition), [12] PubidLiteral}

Definition at line 316 of file qxmlutils.cpp.

Referenced by fixedPubidLiteral(), and QXmlStreamReaderPrivate::parse().

317 {
318  const int len = candidate.length();
319 
320  for(int i = 0; i < len; ++i)
321  {
322  const ushort cp = candidate.at(i).unicode();
323 
324  if ((cp >= 'a' && cp <= 'z')
325  || (cp >= 'A' && cp <= 'Z')
326  || (cp >= '0' && cp <= '9'))
327  {
328  continue;
329  }
330 
331  switch (cp)
332  {
333  /* Fallthrough all these. */
334  case 0x20:
335  case 0x0D:
336  case 0x0A:
337  case '-':
338  case '\'':
339  case '(':
340  case ')':
341  case '+':
342  case ',':
343  case '.':
344  case '/':
345  case ':':
346  case '=':
347  case '?':
348  case ';':
349  case '!':
350  case '*':
351  case '#':
352  case '@':
353  case '$':
354  case '_':
355  case '%':
356  continue;
357  default:
358  return false;
359  }
360  }
361 
362  return true;
363 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
unsigned short ushort
Definition: qglobal.h:995

◆ rangeContains()

bool QXmlUtils::rangeContains ( RangeIter  begin,
RangeIter  end,
const QChar  c 
)
staticprivate

Performs a binary search between begin and end inclusive, to check whether c is contained.

Remember that the QXmlCharRange instances must be in numeric order.

Definition at line 67 of file qxmlutils.cpp.

68 {
69  const ushort cp(c.unicode());
70 
71  // check the first two ranges "manually" as characters in that
72  // range are checked very often and we avoid the binary search below.
73 
74  if (cp <= begin->max)
75  return cp >= begin->min;
76 
77  ++begin;
78 
79  if (begin == end)
80  return false;
81 
82  if (cp <= begin->max)
83  return cp >= begin->min;
84 
85  while (begin != end) {
86  int delta = (end - begin) / 2;
87  RangeIter mid = begin + delta;
88 
89  if (mid->min > cp)
90  end = mid;
91  else if (mid->max < cp)
92  begin = mid;
93  else
94  return true;
95 
96  if (delta == 0)
97  break;
98  }
99 
100  return false;
101 }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
unsigned short ushort
Definition: qglobal.h:995

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