1 #ifndef __stringparserstate_h__
2 #define __stringparserstate_h__
4 // ### optimize me: it's stupid to do a linear search for each
5 // atEnd() invocation. This should be done once in the ctor and
6 // end() should be set appropriately
7 template <typename CharType
, typename _SizeType
= size_t>
8 class StringParserState
11 typedef CharType ValueType
;
12 typedef const CharType
* ConstIterator
;
13 typedef _SizeType SizeType
;
14 typedef QList
<ValueType
> ValueList
;
16 StringParserState( ConstIterator start
, SizeType maxSteps
,
17 const ValueList
&optionalEndItems
= ValueList() )
21 m_end
= start
+ maxSteps
;
22 m_endItems
= optionalEndItems
;
25 void operator++() { ++m_current
; }
29 return m_current
== m_begin
;
34 if ( m_current
>= m_end
)
36 return m_endItems
.findIndex( currentValue() ) != -1;
39 ConstIterator
current() const { return m_current
; }
40 ValueType
currentValue() const { return *current(); }
42 ConstIterator
begin() const { return m_begin
; }
43 ConstIterator
end() const { return m_end
; }
45 SizeType
stepsLeft() const { return m_end
- m_current
; }
47 SizeType
advanceTo( ValueType val
)
49 ConstIterator start
= m_current
;
50 while ( !atEnd() && currentValue() != val
)
52 return m_current
- start
;
55 SizeType
skip( ValueType valueToIgnore
)
57 ConstIterator start
= m_current
;
58 while ( !atEnd() && currentValue() == valueToIgnore
)
60 return m_current
- start
;
64 ConstIterator m_begin
;
65 ConstIterator m_current
;