- wxStringTokenizer(const wxString& to_tokenize,
- const wxString& delims = " \t\r\n",
- bool ret_delim = FALSE);
- wxStringTokenizer() { m_string = ""; m_delims = ""; m_retdelims = FALSE;}
- ~wxStringTokenizer();
-
- int CountTokens();
- bool HasMoreToken();
- wxString NextToken();
- wxString GetString() { return m_string; }
-
- void SetString(const wxString& to_tokenize,
- const wxString& delims = " \t\r\n",
- bool ret_delim = FALSE)
- {
- m_string = to_tokenize;
- m_delims = delims;
- m_retdelims = ret_delim;
- }
+ // ctors and initializers
+ // default ctor, call SetString() later
+ wxStringTokenizer() { m_mode = wxTOKEN_INVALID; }
+ // ctor which gives us the string
+ wxStringTokenizer(const wxString& str,
+ const wxString& delims = wxDEFAULT_DELIMITERS,
+ wxStringTokenizerMode mode = wxTOKEN_DEFAULT);
+
+ // args are same as for the non default ctor above
+ void SetString(const wxString& str,
+ const wxString& delims = wxDEFAULT_DELIMITERS,
+ wxStringTokenizerMode mode = wxTOKEN_DEFAULT);
+
+ // reinitialize the tokenizer with the same delimiters/mode
+ void Reinit(const wxString& str);
+
+ // tokens access
+ // return the number of remaining tokens
+ size_t CountTokens() const;
+ // did we reach the end of the string?
+ bool HasMoreTokens() const;
+ // get the next token, will return empty string if !HasMoreTokens()
+ wxString GetNextToken();
+ // get the delimiter which terminated the token last retrieved by
+ // GetNextToken() or NUL if there had been no tokens yet or the last
+ // one wasn't terminated (but ran to the end of the string)
+ wxChar GetLastDelimiter() const { return m_lastDelim; }
+
+ // get current tokenizer state
+ // returns the part of the string which remains to tokenize (*not* the
+ // initial string)
+ wxString GetString() const { return m_string.substr(m_pos); }
+
+ // returns the current position (i.e. one index after the last
+ // returned token or 0 if GetNextToken() has never been called) in the
+ // original string
+ size_t GetPosition() const { return m_pos; }
+
+ // misc
+ // get the current mode - can be different from the one passed to the
+ // ctor if it was wxTOKEN_DEFAULT
+ wxStringTokenizerMode GetMode() const { return m_mode; }
+ // do we return empty tokens?
+ bool AllowEmpty() const { return m_mode != wxTOKEN_STRTOK; }
+
+
+ // backwards compatibility section from now on
+ // -------------------------------------------
+
+ // for compatibility only, use GetNextToken() instead
+ wxString NextToken() { return GetNextToken(); }
+
+ // compatibility only, don't use
+ void SetString(const wxString& to_tokenize,
+ const wxString& delims,
+ bool WXUNUSED(ret_delim))
+ {
+ SetString(to_tokenize, delims, wxTOKEN_RET_DELIMS);
+ }
+
+ wxStringTokenizer(const wxString& to_tokenize,
+ const wxString& delims,
+ bool ret_delim)
+ {
+ SetString(to_tokenize, delims, ret_delim);
+ }