Qt 4.8
Public Functions | Static Public Functions | Private Functions | Static Private Functions | Properties | List of all members
QPatternist::DerivedString< DerivedType > Class Template Reference

Represents instances of derived xs:string types, such as xs:normalizedString. More...

#include <qderivedstring_p.h>

Inheritance diagram for QPatternist::DerivedString< DerivedType >:
QPatternist::AtomicValue QSharedData QPatternist::CppCastingHelper< AtomicValue >

Public Functions

virtual bool evaluateEBV (const QExplicitlySharedDataPointer< DynamicContext > &) const
 
virtual QString stringValue () const
 
virtual ItemType::Ptr type () const
 
- Public Functions inherited from QPatternist::AtomicValue
virtual bool hasError () const
 
virtual ~AtomicValue ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 
- Public Functions inherited from QPatternist::CppCastingHelper< AtomicValue >
const TCastTarget * as () const
 
TCastTarget * as ()
 

Static Public Functions

static AtomicValue::Ptr fromLexical (const NamePool::Ptr &np, const QString &lexical)
 
static AtomicValue::Ptr fromValue (const QString &value)
 
- Static Public Functions inherited from QPatternist::AtomicValue
static ItemType::Ptr qtToXDMType (const QXmlItem &item)
 
static QVariant toQt (const AtomicValue *const value)
 
static QVariant toQt (const AtomicValue::Ptr &value)
 
static Item toXDM (const QVariant &value)
 

Private Functions

 DerivedString (const QString &value)
 

Static Private Functions

static QString attributeNormalize (const QString &input)
 Performs attribute value normalization as if input was not from a CDATA section. More...
 
static AtomicValue::Ptr error (const NamePool::Ptr &np, const QString &invalidValue)
 
static bool isNameChar (const QChar &ch)
 This is an incomplete test for whether ch conforms to the XML 1.0 NameChar production. More...
 
static bool isValidName (const QString &input)
 
static bool isValidNMTOKEN (const QString &input)
 
static ItemType::Ptr itemType ()
 

Properties

const QString m_value
 

Additional Inherited Members

- Public Types inherited from QPatternist::AtomicValue
typedef QList< AtomicValue::PtrList
 
typedef QExplicitlySharedDataPointer< AtomicValuePtr
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QPatternist::AtomicValue
 AtomicValue ()
 
- Protected Functions inherited from QPatternist::CppCastingHelper< AtomicValue >
 CppCastingHelper ()
 

Detailed Description

template<TypeOfDerivedString DerivedType>
class QPatternist::DerivedString< DerivedType >

Represents instances of derived xs:string types, such as xs:normalizedString.

Whitespace is a significant part for creating values from the lexical space. Of course the specification is tricky here. Here's some pointers:

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 95 of file qderivedstring_p.h.

Constructors and Destructors

◆ DerivedString()

template<TypeOfDerivedString DerivedType>
QPatternist::DerivedString< DerivedType >::DerivedString ( const QString value)
inlineprivate

Functions

◆ attributeNormalize()

template<TypeOfDerivedString DerivedType>
static QString QPatternist::DerivedString< DerivedType >::attributeNormalize ( const QString input)
inlinestaticprivate

Performs attribute value normalization as if input was not from a CDATA section.

Each whitespace character in input that's not a space, such as tab or new line character, is replaced with a space. This algorithm differs from QString::simplified() in that it doesn't collapse subsequent whitespace characters to a single one, or remove trailing and leading space.

See also
Extensible Markup Language (XML) 1.0 (Second Edition), 3.3.3 [E70]Attribute-Value Normalization

Definition at line 209 of file qderivedstring_p.h.

Referenced by QPatternist::DerivedString< TypeToken >::fromLexical().

210  {
211  QString retval(input);
212  const int len = retval.length();
213  const QLatin1Char space(' ');
214 
215  for(int i = 0; i < len; ++i)
216  {
217  const QChar ati(retval.at(i));
218 
219  if(ati.isSpace() && ati != space)
220  retval[i] = space;
221  }
222 
223  return retval;
224  }
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ error()

template<TypeOfDerivedString DerivedType>
static AtomicValue::Ptr QPatternist::DerivedString< DerivedType >::error ( const NamePool::Ptr np,
const QString invalidValue 
)
inlinestaticprivate

Definition at line 226 of file qderivedstring_p.h.

Referenced by QPatternist::DerivedString< TypeToken >::fromLexical().

227  {
228  return ValidationError::createError(QString::fromLatin1("%1 is not a valid value for "
229  "type %2.").arg(formatData(invalidValue))
230  .arg(formatType(np, itemType())));
231  }
static ItemType::Ptr itemType()
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
static AtomicValue::Ptr createError(const QString &description=QString(), const ReportContext::ErrorCode=ReportContext::FORG0001)
static QString formatData(const QString &data)
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

◆ evaluateEBV()

template<TypeOfDerivedString DerivedType>
virtual bool QPatternist::DerivedString< DerivedType >::evaluateEBV ( const QExplicitlySharedDataPointer< DynamicContext > &  context) const
inlinevirtual

Always fails by issuing the type error ReportContext::FORG0006. Sub-classes whose represented type do allow EBV to be extracted from, must thus re-implement this function.

Reimplemented from QPatternist::AtomicValue.

Definition at line 325 of file qderivedstring_p.h.

326  {
327  return m_value.length() > 0;
328  }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696

◆ fromLexical()

template<TypeOfDerivedString DerivedType>
static AtomicValue::Ptr QPatternist::DerivedString< DerivedType >::fromLexical ( const NamePool::Ptr np,
const QString lexical 
)
inlinestatic

Constructs an instance from the lexical representation lexical.

Definition at line 251 of file qderivedstring_p.h.

Referenced by QPatternist::ToStringCaster< DerivedType >::castFrom(), QPatternist::AnyToDerivedStringCaster< type >::castFrom(), QPatternist::XsdTypeChecker::checkConstrainingFacetsDouble(), QPatternist::XsdTypeChecker::checkConstrainingFacetsDuration(), QPatternist::XsdTypeChecker::checkConstrainingFacetsSignedInteger(), QPatternist::XsdTypeChecker::checkConstrainingFacetsString(), QPatternist::XsdTypeChecker::checkConstrainingFacetsUnion(), QPatternist::XsdTypeChecker::checkConstrainingFacetsUnsignedInteger(), QPatternist::FieldNode::isEqualTo(), QPatternist::XsdSchemaParser::parseEnumerationFacet(), QPatternist::XsdSchemaParser::parseMaxExclusiveFacet(), QPatternist::XsdSchemaParser::parseMaxInclusiveFacet(), QPatternist::XsdSchemaParser::parseMinExclusiveFacet(), QPatternist::XsdSchemaParser::parseMinInclusiveFacet(), QPatternist::XsdSchemaParser::parseNotation(), QPatternist::XsdSchemaParser::parsePatternFacet(), QPatternist::XsdSchemaParser::parseWhiteSpaceFacet(), QPatternist::XsdSchemaParser::validateIdAttribute(), and QPatternist::XsdTypeChecker::valuesAreEqual().

252  {
253  switch(DerivedType)
254  {
255  case TypeString:
256  return AtomicValue::Ptr(new DerivedString(lexical));
258  return AtomicValue::Ptr(new DerivedString(attributeNormalize(lexical)));
259  case TypeToken:
260  return AtomicValue::Ptr(new DerivedString(lexical.simplified()));
261  case TypeLanguage:
262  {
263  const QString simplified(lexical.trimmed());
264 
265  const QRegExp validate(QLatin1String("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*"));
266  Q_ASSERT(validate.isValid());
267 
268  if(validate.exactMatch(simplified))
269  return AtomicValue::Ptr(new DerivedString(lexical.simplified()));
270  else
271  return error(np, simplified);
272  }
273  case TypeNMTOKEN:
274  {
275  const QString trimmed(lexical.trimmed());
276 
279  else
280  return error(np, trimmed);
281  }
282  case TypeName:
283  {
284  const QString simplified(lexical.simplified());
285 
286  if(isValidName(simplified))
287  return AtomicValue::Ptr(new DerivedString(simplified));
288  else
289  return error(np, simplified);
290  }
291  case TypeID:
292  /* Fallthrough. */
293  case TypeIDREF:
294  /* Fallthrough. */
295  case TypeENTITY:
296  /* Fallthrough. */
297  case TypeNCName:
298  {
299  /* We treat xs:ID, xs:ENTITY, xs:IDREF and xs:NCName in the exact same
300  * way, except for the type annotation.
301  *
302  * We use trimmed() instead of simplified() because it's
303  * faster and whitespace isn't allowed between
304  * non-whitespace characters anyway, for these types. */
305  const QString trimmed(lexical.trimmed());
306 
309  else
310  return error(np, trimmed);
311  }
312  default:
313  {
314  Q_ASSERT_X(false, Q_FUNC_INFO, "This line is not supposed to be reached.");
315  return AtomicValue::Ptr();
316  }
317  }
318  }
QExplicitlySharedDataPointer< AtomicValue > Ptr
Definition: qitem_p.h:127
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
static bool isValidName(const QString &input)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QString attributeNormalize(const QString &input)
Performs attribute value normalization as if input was not from a CDATA section.
DerivedString(const QString &value)
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QString trimmed(QString source)
Definition: generator.cpp:233
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
static bool isValidNMTOKEN(const QString &input)
static AtomicValue::Ptr error(const NamePool::Ptr &np, const QString &invalidValue)
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
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ fromValue()

template<TypeOfDerivedString DerivedType>
static AtomicValue::Ptr QPatternist::DerivedString< DerivedType >::fromValue ( const QString value)
inlinestatic
Note
This function doesn't perform any cleanup/normalizaiton of value. value must be a canonical value space of the type.

If you want cleanup to be performed and/or the lexical space checked, use fromLexical().

Definition at line 242 of file qderivedstring_p.h.

243  {
244  return AtomicValue::Ptr(new DerivedString(value));
245  }
QExplicitlySharedDataPointer< AtomicValue > Ptr
Definition: qitem_p.h:127
DerivedString(const QString &value)

◆ isNameChar()

template<TypeOfDerivedString DerivedType>
static bool QPatternist::DerivedString< DerivedType >::isNameChar ( const QChar ch)
inlinestaticprivate

This is an incomplete test for whether ch conforms to the XML 1.0 NameChar production.

Definition at line 128 of file qderivedstring_p.h.

Referenced by QPatternist::DerivedString< TypeToken >::isValidName(), and QPatternist::DerivedString< TypeToken >::isValidNMTOKEN().

129  {
130  return ch.isLetter() ||
131  ch.isDigit() ||
132  ch == QLatin1Char('.') ||
133  ch == QLatin1Char('-') ||
134  ch == QLatin1Char('_') ||
135  ch == QLatin1Char(':');
136  }
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
Definition: qchar.cpp:653
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isDigit() const
Returns true if the character is a decimal digit (Number_DecimalDigit); otherwise returns false...
Definition: qchar.cpp:699

◆ isValidName()

template<TypeOfDerivedString DerivedType>
static bool QPatternist::DerivedString< DerivedType >::isValidName ( const QString input)
inlinestaticprivate
Returns
true if input is a valid xs:Name.
See also
Extensible Markup Language (XML) 1.0 (Fourth Edition), [5] Name

Definition at line 143 of file qderivedstring_p.h.

Referenced by QPatternist::DerivedString< TypeToken >::fromLexical().

144  {
145  if(input.isEmpty())
146  return false;
147 
148  const QChar first(input.at(0));
149 
150  if(first.isLetter() ||
151  first == QLatin1Char('_') ||
152  first == QLatin1Char(':'))
153  {
154  const int len = input.length();
155 
156  if(len == 1)
157  return true;
158 
159  /* Since we've checked the first character above, we start at
160  * position 1. */
161  for(int i = 1; i < len; ++i)
162  {
163  if(!isNameChar(input.at(i)))
164  return false;
165  }
166 
167  return true;
168  }
169  else
170  return false;
171  }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static bool isNameChar(const QChar &ch)
This is an incomplete test for whether ch conforms to the XML 1.0 NameChar production.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isValidNMTOKEN()

template<TypeOfDerivedString DerivedType>
static bool QPatternist::DerivedString< DerivedType >::isValidNMTOKEN ( const QString input)
inlinestaticprivate
Returns
true if input conforms to the XML 1.0 Nmtoken product.
See also
Extensible Markup Language (XML) 1.0 (Second Edition), [7] Nmtoken

Definition at line 180 of file qderivedstring_p.h.

Referenced by QPatternist::DerivedString< TypeToken >::fromLexical().

181  {
182  const int len = input.length();
183 
184  if(len == 0)
185  return false;
186 
187  for(int i = 0; i < len; ++i)
188  {
189  if(!isNameChar(input.at(i)))
190  return false;
191  }
192 
193  return true;
194  }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static bool isNameChar(const QChar &ch)
This is an incomplete test for whether ch conforms to the XML 1.0 NameChar production.

◆ itemType()

template<TypeOfDerivedString DerivedType>
static ItemType::Ptr QPatternist::DerivedString< DerivedType >::itemType ( )
inlinestaticprivate

Definition at line 98 of file qderivedstring_p.h.

Referenced by QPatternist::DerivedString< TypeToken >::error(), and QPatternist::DerivedString< TypeToken >::type().

99  {
100  switch(DerivedType)
101  {
103  case TypeToken: return BuiltinTypes::xsToken;
106  case TypeName: return BuiltinTypes::xsName;
107  case TypeNCName: return BuiltinTypes::xsNCName;
108  case TypeID: return BuiltinTypes::xsID;
109  case TypeIDREF: return BuiltinTypes::xsIDREF;
110  case TypeENTITY: return BuiltinTypes::xsENTITY;
111  case TypeString: return BuiltinTypes::xsString;
112  }
113 
114  Q_ASSERT_X(false, Q_FUNC_INFO, "This line is not supposed to be reached.");
115  return ItemType::Ptr();
116  }
static const AtomicType::Ptr xsID
static const AtomicType::Ptr xsNormalizedString
static const AtomicType::Ptr xsName
static const AtomicType::Ptr xsIDREF
static const AtomicType::Ptr xsString
static const AtomicType::Ptr xsNMTOKEN
static const AtomicType::Ptr xsENTITY
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static const AtomicType::Ptr xsNCName
static const AtomicType::Ptr xsLanguage
static const AtomicType::Ptr xsToken
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ stringValue()

template<TypeOfDerivedString DerivedType>
virtual QString QPatternist::DerivedString< DerivedType >::stringValue ( ) const
inlinevirtual

Implements QPatternist::AtomicValue.

Definition at line 320 of file qderivedstring_p.h.

321  {
322  return m_value;
323  }

◆ type()

template<TypeOfDerivedString DerivedType>
virtual ItemType::Ptr QPatternist::DerivedString< DerivedType >::type ( ) const
inlinevirtual

Implements QPatternist::AtomicValue.

Definition at line 330 of file qderivedstring_p.h.

331  {
332  return itemType();
333  }
static ItemType::Ptr itemType()

Properties

◆ m_value

template<TypeOfDerivedString DerivedType>
const QString QPatternist::DerivedString< DerivedType >::m_value
private

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