summaryrefslogtreecommitdiffstats
path: root/ksirc/stringparserstate.h
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /ksirc/stringparserstate.h
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip
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
Diffstat (limited to 'ksirc/stringparserstate.h')
-rw-r--r--ksirc/stringparserstate.h71
1 files changed, 71 insertions, 0 deletions
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 <typename CharType, typename _SizeType = size_t>
+class StringParserState
+{
+public:
+ typedef CharType ValueType;
+ typedef const CharType * ConstIterator;
+ typedef _SizeType SizeType;
+ typedef QValueList<ValueType> 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
+