+ wxCHECK_MSG( IsOk(), false, wxT("you should call SetString() first") );
+
+ if ( find_first_not_of(m_delims, m_delimsLen, m_pos, m_stringEnd)
+ != m_stringEnd )
+ {
+ // there are non delimiter characters left, so we do have more tokens
+ return true;
+ }
+
+ switch ( m_mode )
+ {
+ case wxTOKEN_RET_EMPTY:
+ case wxTOKEN_RET_DELIMS:
+ // special hack for wxTOKEN_RET_EMPTY: we should return the initial
+ // empty token even if there are only delimiters after it
+ return !m_string.empty() && m_pos == m_string.begin();
+
+ case wxTOKEN_RET_EMPTY_ALL:
+ // special hack for wxTOKEN_RET_EMPTY_ALL: we can know if we had
+ // already returned the trailing empty token after the last
+ // delimiter by examining m_lastDelim: it is set to NUL if we run
+ // up to the end of the string in GetNextToken(), but if it is not
+ // NUL yet we still have this last token to return even if m_pos is
+ // already at m_string.length()
+ return m_pos < m_stringEnd || m_lastDelim != wxT('\0');
+
+ case wxTOKEN_INVALID:
+ case wxTOKEN_DEFAULT:
+ wxFAIL_MSG( wxT("unexpected tokenizer mode") );
+ // fall through
+
+ case wxTOKEN_STRTOK:
+ // never return empty delimiters
+ break;
+ }
+
+ return false;
+}
+
+// count the number of (remaining) tokens in the string
+size_t wxStringTokenizer::CountTokens() const
+{
+ wxCHECK_MSG( IsOk(), 0, wxT("you should call SetString() first") );
+
+ // VZ: this function is IMHO not very useful, so it's probably not very
+ // important if its implementation here is not as efficient as it
+ // could be -- but OTOH like this we're sure to get the correct answer
+ // in all modes
+ wxStringTokenizer tkz(wxString(m_pos, m_stringEnd), m_delims, m_mode);
+
+ size_t count = 0;
+ while ( tkz.HasMoreTokens() )
+ {
+ count++;
+
+ (void)tkz.GetNextToken();
+ }
+
+ return count;
+}
+
+// ----------------------------------------------------------------------------
+// token extraction
+// ----------------------------------------------------------------------------
+
+wxString wxStringTokenizer::GetNextToken()
+{
+ wxString token;
+ do
+ {
+ if ( !HasMoreTokens() )
+ {
+ break;
+ }
+
+ m_hasMoreTokens = MoreTokens_Unknown;
+
+ // find the end of this token
+ wxString::const_iterator pos =
+ find_first_of(m_delims, m_delimsLen, m_pos, m_stringEnd);
+
+ // and the start of the next one
+ if ( pos == m_stringEnd )
+ {
+ // no more delimiters, the token is everything till the end of
+ // string
+ token.assign(m_pos, m_stringEnd);
+
+ // skip the token
+ m_pos = m_stringEnd;
+
+ // it wasn't terminated
+ m_lastDelim = wxT('\0');
+ }
+ else // we found a delimiter at pos
+ {
+ // in wxTOKEN_RET_DELIMS mode we return the delimiter character
+ // with token, otherwise leave it out
+ wxString::const_iterator tokenEnd(pos);
+ if ( m_mode == wxTOKEN_RET_DELIMS )
+ ++tokenEnd;
+
+ token.assign(m_pos, tokenEnd);
+
+ // skip the token and the trailing delimiter
+ m_pos = pos + 1;
+
+ m_lastDelim = (pos == m_stringEnd) ? wxT('\0') : (wxChar)*pos;
+ }
+ }
+ while ( !AllowEmpty() && token.empty() );
+
+ return token;