Qt 4.8
Public Functions | Private Functions | Properties | Related Functions | List of all members
StringSplitter Class Reference

Helper class for IdFN. More...

Inheritance diagram for StringSplitter:
QAbstractXmlForwardIterator< QString > QSharedData

Public Functions

virtual QString current () const
 Returns the current item in the sequence. More...
 
virtual QString next ()
 Returns the next item in the sequence, or a null object if the end has been reached. More...
 
virtual qint64 position () const
 Returns the current position in the sequence represented by this. More...
 
 StringSplitter (const Item::Iterator::Ptr &source)
 
- Public Functions inherited from QAbstractXmlForwardIterator< QString >
virtual QAbstractXmlForwardIterator< QString >::Ptr copy () const
 Copies this QAbstractXmlForwardIterator and returns the copy. More...
 
virtual qint64 count ()
 Determines the number of items this QAbstractXmlForwardIterator represents. More...
 
virtual bool isEmpty ()
 Returns true if the sequence is empty. More...
 
virtual QString last ()
 Returns the item at the end of this QAbstractXmlForwardIterator. More...
 
 QAbstractXmlForwardIterator ()
 Default constructor. More...
 
virtual qint64 sizeHint () const
 Gives a hint to the size of the contained sequence. More...
 
virtual QList< QStringtoList ()
 Performs a copy of this QAbstractXmlForwardIterator(with copy()), and returns its items in a QList. More...
 
virtual QAbstractXmlForwardIterator< QString >::Ptr toReversed ()
 Returns a reverse iterator for the sequence. More...
 
virtual ~QAbstractXmlForwardIterator ()
 Destructor. More...
 
- 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...
 

Private Functions

QString loadNext ()
 

Properties

QStack< QStringm_buffer
 
QString m_current
 
qint64 m_position
 
const Item::Iterator::Ptr m_source
 
bool m_sourceAtEnd
 

Related Functions

(Note that these are not member functions.)

template<>
bool qIsForwardIteratorEnd (const QString &unit)
 Helper class for StringSplitter. More...
 

Additional Inherited Members

- Public Types inherited from QAbstractXmlForwardIterator< QString >
typedef QList< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QString > > > List
 A QList containing QAbstractXmlForwardIterator::Ptr instances. More...
 
typedef QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QString > > Ptr
 A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass. More...
 
typedef QVector< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QString > > > Vector
 A QVector containing QAbstractXmlForwardIterator::Ptr instances. More...
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Helper class for IdFN.

StringSplitter takes an Iterator which delivers strings of this kind:

"a", "b c", "%invalidNCName", " ", "d"

and we deliver instead:

"a", "b", "c", "d"

That is, we:

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

Definition at line 89 of file qsequencegeneratingfns.cpp.

Constructors and Destructors

◆ StringSplitter()

StringSplitter::StringSplitter ( const Item::Iterator::Ptr source)

Definition at line 105 of file qsequencegeneratingfns.cpp.

Referenced by QPatternist::IdFN::evaluateSequence().

105  : m_source(source)
106  , m_position(0)
107  , m_sourceAtEnd(false)
108 {
111 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QStack< QString > m_buffer
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
const Item::Iterator::Ptr m_source

Functions

◆ current()

QString StringSplitter::current ( ) const
virtual

Returns the current item in the sequence.

If this function is called before the first call to next(), a null object is returned. If the end of the sequence has been reached, a null object is returned.

Implements QAbstractXmlForwardIterator< QString >.

Definition at line 158 of file qsequencegeneratingfns.cpp.

159 {
160  return m_current;
161 }

◆ loadNext()

QString StringSplitter::loadNext ( )
private

Definition at line 132 of file qsequencegeneratingfns.cpp.

Referenced by next(), and StringSplitter().

133 {
134  const Item sourceNext(m_source->next());
135 
136  if(sourceNext.isNull())
137  {
138  m_sourceAtEnd = true;
139  /* We might have strings in m_buffer, let's empty it. */
140  return next();
141  }
142 
143  const QStringList candidates(sourceNext.stringValue().simplified().split(QLatin1Char(' ')));
144  const int count = candidates.length();
145 
146  for(int i = 0; i < count; ++i)
147  {
148  const QString &at = candidates.at(i);
149 
150  if(QXmlUtils::isNCName(at))
151  m_buffer.push(at);
152  }
153 
154  /* So, now we have populated m_buffer, let's start from the beginning. */
155  return next();
156 }
#define at(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual QString next()
Returns the next item in the sequence, or a null object if the end has been reached.
QStack< QString > m_buffer
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual qint64 count()
Determines the number of items this QAbstractXmlForwardIterator represents.
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
const Item::Iterator::Ptr m_source
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

◆ next()

QString StringSplitter::next ( )
virtual

Returns the next item in the sequence, or a null object if the end has been reached.

Implements QAbstractXmlForwardIterator< QString >.

Definition at line 113 of file qsequencegeneratingfns.cpp.

Referenced by loadNext().

114 {
115  /* We also check m_position, we want to load on our first run. */
116  if(!m_buffer.isEmpty())
117  {
118  ++m_position;
119  m_current = m_buffer.pop();
120  return m_current;
121  }
122  else if(m_sourceAtEnd)
123  {
124  m_current.clear();
125  m_position = -1;
126  return QString();
127  }
128 
129  return loadNext();
130 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QStack< QString > m_buffer
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ position()

qint64 StringSplitter::position ( ) const
virtual

Returns the current position in the sequence represented by this.

The first position is 1, not 0. If next() hasn't been called, 0 is returned. If this has reached the end, -1 is returned.

Implements QAbstractXmlForwardIterator< QString >.

Definition at line 163 of file qsequencegeneratingfns.cpp.

164 {
165  return m_position;
166 }

Friends and Related Functions

◆ qIsForwardIteratorEnd()

bool qIsForwardIteratorEnd ( const QString unit)
related

Helper class for StringSplitter.

Needed by the QAbstractXmlForwardIterator sub-class.

Definition at line 85 of file qabstractxmlforwarditerator_p.h.

86 {
87  return unit.isNull();
88 }
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505

Properties

◆ m_buffer

QStack<QString> StringSplitter::m_buffer
private

Definition at line 99 of file qsequencegeneratingfns.cpp.

Referenced by loadNext(), next(), and StringSplitter().

◆ m_current

QString StringSplitter::m_current
private

Definition at line 100 of file qsequencegeneratingfns.cpp.

Referenced by current(), and next().

◆ m_position

qint64 StringSplitter::m_position
private

Definition at line 101 of file qsequencegeneratingfns.cpp.

Referenced by next(), and position().

◆ m_source

const Item::Iterator::Ptr StringSplitter::m_source
private

Definition at line 98 of file qsequencegeneratingfns.cpp.

Referenced by loadNext(), and StringSplitter().

◆ m_sourceAtEnd

bool StringSplitter::m_sourceAtEnd
private

Definition at line 102 of file qsequencegeneratingfns.cpp.

Referenced by loadNext(), and next().


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