Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QPatternist::NormalizeUnicodeFN Class Reference

Implements the function fn:normalize-unicode(). More...

#include <qstringvaluefns_p.h>

Inheritance diagram for QPatternist::NormalizeUnicodeFN:
QPatternist::FunctionCall QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
 NormalizeUnicodeFN ()
 
- Public Functions inherited from QPatternist::FunctionCall
virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual ID id () const
 
virtual Expression::Properties properties () const
 
virtual void setSignature (const FunctionSignature::Ptr &sign)
 
virtual FunctionSignature::Ptr signature () const
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::UnlimitedContainer
virtual bool compressOperands (const StaticContext::Ptr &)
 
virtual Expression::List operands () const
 
virtual void setOperands (const Expression::List &list)
 
 UnlimitedContainer (const Expression::List &operands=Expression::List())
 
- Public Functions inherited from QPatternist::Expression
virtual const SourceLocationReflectionactualReflection () const
 Returns this. More...
 
virtual void announceFocusType (const ItemType::Ptr &itemType)
 
Properties deepProperties () const
 Computes the union of properties for this Expression and all its descending children. More...
 
virtual Properties dependencies () const
 
virtual QString description () const
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) const
 
virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &context) const
 
virtual void evaluateToSequenceReceiver (const DynamicContext::Ptr &context) const
 
virtual ItemType::Ptr expectedContextItemType () const
 
 Expression ()
 
bool has (const Property prop) const
 
bool hasDependency (const Property prop) const
 
bool is (const ID id) const
 
bool isEvaluated () const
 
virtual ItemType::Ptr newFocusType () const
 
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () const
 
virtual PatternPriority patternPriority () const
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
virtual ~Expression ()
 
- 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< Expression >
const TCastTarget * as () const
 
TCastTarget * as ()
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Private Functions

int determineNormalizationForm (const DynamicContext::Ptr &context) const
 

Properties

QString::NormalizationForm m_normForm
 

Additional Inherited Members

- Public Types inherited from QPatternist::FunctionCall
typedef QExplicitlySharedDataPointer< FunctionCallPtr
 
- Public Types inherited from QPatternist::UnlimitedContainer
enum  CardinalityComputation { ProductOfCardinality, UnionOfCardinality }
 
- Public Types inherited from QPatternist::Expression
typedef QExplicitlySharedDataPointer< const ExpressionConstPtr
 A smart pointer wrapping const Expression instances. More...
 
enum  ID {
  IDBooleanValue = 1, IDCountFN, IDEmptyFN, IDExistsFN,
  IDExpressionSequence, IDGeneralComparison, IDIfThenClause, IDIgnorableExpression,
  IDIntegerValue, IDPositionFN, IDStringValue, IDValueComparison,
  IDRangeVariableReference, IDContextItem, IDUserFunctionCallsite, IDExpressionVariableReference,
  IDAttributeConstructor, IDUpperCaseFN, IDLowerCaseFN, IDFirstItemPredicate,
  IDEmptySequence, IDReturnOrderBy, IDLetClause, IDForClause,
  IDPath, IDNamespaceConstructor, IDArgumentReference, IDGenericPredicate,
  IDAxisStep, IDFloat, IDCombineNodes, IDUnresolvedVariableReference,
  IDCardinalityVerifier
}
 
typedef QList< Expression::PtrList
 
typedef QFlags< PropertyProperties
 
enum  Property {
  UseContextItem = 1, DisableElimination = 1 << 1, IsEvaluated = 1 << 2, DisableTypingDeduction = 1 << 3,
  EmptynessFollowsChild = 1 << 4, RewriteToEmptyOnEmpty = 1 << 5, RequiresFocus = 1 << 6, AffectsOrderOnly = 1 << 7,
  RequiresContextItem = (1 << 8) | RequiresFocus, CreatesFocusForLast = 1 << 9, LastOperandIsCollation = 1 << 10, DependsOnLocalVariable = (1 << 11) | DisableElimination,
  EvaluationCacheRedundant = (1 << 12), IsNodeConstructor = 1 << 13, RequiresCurrentItem = 1 << 14
}
 
typedef QExplicitlySharedDataPointer< ExpressionPtr
 A smart pointer wrapping mutable Expression instances. More...
 
typedef ::QAbstractXmlForwardIterator< Expression::PtrQAbstractXmlForwardIterator
 
typedef QVector< Expression::PtrVector
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QPatternist::UnlimitedContainer
template<CardinalityComputation suppliedCard>
SequenceType::Ptr operandsUnionType () const
 
- Protected Functions inherited from QPatternist::Expression
void typeCheckOperands (const StaticContext::Ptr &context)
 
- Protected Functions inherited from QPatternist::CppCastingHelper< Expression >
 CppCastingHelper ()
 
- Protected Variables inherited from QPatternist::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

Implements the function fn:normalize-unicode().

What perhaps can be said significant with the implementation, is that it attempts to determine the normalization form at compile time, in order to reduce string work at runtime.

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

Definition at line 152 of file qstringvaluefns_p.h.

Constructors and Destructors

◆ NormalizeUnicodeFN()

NormalizeUnicodeFN::NormalizeUnicodeFN ( )

Initializes private data.

Definition at line 172 of file qstringvaluefns.cpp.

Functions

◆ compress()

Expression::Ptr NormalizeUnicodeFN::compress ( const StaticContext::Ptr context)
virtual

compress() is the last stage performs in compiling an expression, done after the initial AST build and calling typeCheck(). compress() performs crucial simplifications, either by having drastic performance implications or that some expressions depend on it for proper behavior.

The default implementation performs a sparse conditional constant propagation. In short, a recursive process is performed in the AST which examines if the Expression's operands are constant values, and if so, performs a const fold(AST rewrite) into the result of evaluating the expression in question. This default behavior can be disabled by letting properties() return DisableElimination.

This compress() stage can be relative effective due to the design of XPath, in part because intrinsic functions are heavily used. Many Expressions override compress() and do optimizations specific to what they do. Also, many Expressions performs optimizations in their typeCheck().

Parameters
contextthe static context. Supplies compile time information, and is the channel for communicating error messages.
See also
Wikipedia, the free encyclopedia, Sparse conditional constant propagation
Wikipedia, the free encyclopedia, Intrinsic function
Wikipedia, the free encyclopedia, Compiler optimization

Reimplemented from QPatternist::Expression.

Definition at line 209 of file qstringvaluefns.cpp.

210 {
211  const Expression::Ptr me(FunctionCall::compress(context));
212  if(me != this)
213  return me;
214 
215  Q_ASSERT(m_operands.count() == 1 || m_operands.count() == 2);
216 
217  if(m_operands.count() == 1)
219  else if(m_operands.last()->is(IDStringValue))
220  {
221  m_normForm = static_cast<QString::NormalizationForm>(
223 
224  if(m_normForm == -1)
225  return m_operands.first();
226 
227  /* Remove the operand since we don't need it anymore. */
229  }
230 
231  return me;
232 }
NormalizationForm
This enum describes the various normalized forms of Unicode text.
Definition: qstring.h:309
void removeLast()
Removes the last item in the list.
Definition: qlist.h:287
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QString::NormalizationForm m_normForm
int determineNormalizationForm(const DynamicContext::Ptr &context) const
virtual QExplicitlySharedDataPointer< DynamicContext > dynamicContext() const =0
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
bool is(const ID id) const

◆ determineNormalizationForm()

int NormalizeUnicodeFN::determineNormalizationForm ( const DynamicContext::Ptr context) const
private

Definition at line 234 of file qstringvaluefns.cpp.

Referenced by compress(), and evaluateSingleton().

235 {
236  const QString strRepr(m_operands.last()->evaluateSingleton(context).stringValue().trimmed().toUpper());
237 
238  /* TODO. Put these values in a QHash for faster lookup. Keep thread safety in mind. */
239  if(strRepr.isEmpty())
240  return -1;
241  else if(strRepr == QLatin1String("NFC"))
243  else if(strRepr == QLatin1String("NFD"))
245  else if(strRepr == QLatin1String("NFKC"))
247  else if(strRepr == QLatin1String("NFKD"))
249  else
250  {
251  /* What form is FULLY_NORMALIZED? Is a code path available for that somewhere? */
252  context->error(QtXmlPatterns::tr("The normalization form %1 is "
253  "unsupported. The supported forms are "
254  "%2, %3, %4, and %5, and none, i.e. "
255  "the empty string (no normalization).")
256  .arg(formatKeyword(strRepr))
257  .arg(formatKeyword("NFC"))
258  .arg(formatKeyword("NFD"))
259  .arg(formatKeyword("NFKC"))
260  .arg(formatKeyword("NFKD")),
262  this);
263  return QString::NormalizationForm_C; /* Silence compiler warning. */
264  }
265 }
QString formatKeyword(const QString &keyword)
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
QString stringValue() const
Returns the string value of this Item.
Definition: qitem_p.h:302
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ evaluateSingleton()

Item NormalizeUnicodeFN::evaluateSingleton ( const DynamicContext::Ptr context) const
virtual

Reimplemented from QPatternist::Expression.

Definition at line 186 of file qstringvaluefns.cpp.

187 {
188  const Item arg(m_operands.first()->evaluateSingleton(context));
189 
190  if(!arg)
192 
193  int normForm;
194 
195  /* The second argument has been removed, if we've already determined the form. */
196  if(m_operands.count() == 1)
197  normForm = m_normForm;
198  else
199  {
200  normForm = determineNormalizationForm(context);
201  if(normForm == -1)
202  return toItem(AtomicString::fromValue(arg.stringValue()));
203  }
204 
205  return AtomicString::fromValue(arg.stringValue().normalized(
206  static_cast<QString::NormalizationForm>(normForm)));
207 }
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static AtomicString::Ptr fromValue(const QString &value)
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QString::NormalizationForm m_normForm
int determineNormalizationForm(const DynamicContext::Ptr &context) const
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
static const AtomicValue::Ptr EmptyString
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

Properties

◆ m_normForm

QString::NormalizationForm QPatternist::NormalizeUnicodeFN::m_normForm
private

Definition at line 164 of file qstringvaluefns_p.h.

Referenced by compress(), and evaluateSingleton().


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