From bcb704366cb5e333a626c18c308c7e0448a8e69f Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- ksirc/stringparserstate.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 ksirc/stringparserstate.h (limited to 'ksirc/stringparserstate.h') diff --git a/ksirc/stringparserstate.h b/ksirc/stringparserstate.h new file mode 100644 index 00000000..cd9220a4 --- /dev/null +++ b/ksirc/stringparserstate.h @@ -0,0 +1,71 @@ +#ifndef __stringparserstate_h__ +#define __stringparserstate_h__ + +// ### optimize me: it's stupid to do a linear search for each +// atEnd() invocation. This should be done once in the ctor and +// end() should be set appropriately +template +class StringParserState +{ +public: + typedef CharType ValueType; + typedef const CharType * ConstIterator; + typedef _SizeType SizeType; + typedef QValueList ValueList; + + StringParserState( ConstIterator start, SizeType maxSteps, + const ValueList &optionalEndItems = ValueList() ) + { + m_begin = start; + m_current = start; + m_end = start + maxSteps; + m_endItems = optionalEndItems; + } + + void operator++() { ++m_current; } + + bool atBegin() const + { + return m_current == m_begin; + } + + bool atEnd() const + { + if ( m_current >= m_end ) + return true; + return m_endItems.findIndex( currentValue() ) != -1; + } + + ConstIterator current() const { return m_current; } + ValueType currentValue() const { return *current(); } + + ConstIterator begin() const { return m_begin; } + ConstIterator end() const { return m_end; } + + SizeType stepsLeft() const { return m_end - m_current; } + + SizeType advanceTo( ValueType val ) + { + ConstIterator start = m_current; + while ( !atEnd() && currentValue() != val ) + ++m_current; + return m_current - start; + } + + SizeType skip( ValueType valueToIgnore ) + { + ConstIterator start = m_current; + while ( !atEnd() && currentValue() == valueToIgnore ) + ++m_current; + return m_current - start; + } + +private: + ConstIterator m_begin; + ConstIterator m_current; + ConstIterator m_end; + ValueList m_endItems; +}; + +#endif + -- cgit v1.2.1