X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f4ada568223b79c8a5769cc351c36a8e2ccd7841..8f06a017120fd765296f7e8cde414edea64153a9:/include/wx/tokenzr.h?ds=sidebyside diff --git a/include/wx/tokenzr.h b/include/wx/tokenzr.h index 7942996e29..9ff109d46d 100644 --- a/include/wx/tokenzr.h +++ b/include/wx/tokenzr.h @@ -2,7 +2,7 @@ // Name: tokenzr.h // Purpose: String tokenizer // Author: Guilhem Lavaux -// Modified by: +// Modified by: Vadim Zeitlin // Created: 04/22/98 // RCS-ID: $Id$ // Copyright: (c) Guilhem Lavaux @@ -13,28 +13,54 @@ #define _WX_TOKENZRH #ifdef __GNUG__ -#pragma interface + #pragma interface "tokenzr.h" #endif #include "wx/object.h" #include "wx/string.h" -class wxStringTokenizer : wxObject { +// default: delimiters are usual white space characters +#define wxDEFAULT_DELIMITERS (_T(" \t\r\n")) + +class WXDLLEXPORT wxStringTokenizer : public wxObject +{ public: - wxStringTokenizer(const wxString& to_tokenize, - const wxString& delims = " \t\r\n", - bool ret_delim = FALSE); - ~wxStringTokenizer(); - - int CountTokens(); - bool HasMoreToken(); - wxString NextToken(); - wxString GetString() { return m_string; } -protected: - off_t FindDelims(const wxString& str, const wxString& delims); + // ctors and such + wxStringTokenizer() { m_retdelims = FALSE; m_pos = 0; } + wxStringTokenizer(const wxString& to_tokenize, + const wxString& delims = wxDEFAULT_DELIMITERS, + bool ret_delim = FALSE); + void SetString(const wxString& to_tokenize, + const wxString& delims = wxDEFAULT_DELIMITERS, + bool ret_delim = FALSE); + virtual ~wxStringTokenizer(); + + // count tokens/get next token + size_t CountTokens() const; + bool HasMoreTokens() { return m_hasMore; } + wxString GetNextToken(); + + // One note about GetString -- it returns the string + // remaining after the previous tokens have been removed, + // not the original string + wxString GetString() const { return m_string; } + + // 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; } + + // for compatibility only, use GetNextToken() instead + wxString NextToken() { return GetNextToken(); } + protected: - wxString m_string, m_delims; - bool m_retdelims; + wxString m_string, // the (rest of) string to tokenize + m_delims; // all delimiters + + size_t m_pos; // the position in the original string + + bool m_retdelims; // if TRUE, return delims with tokens + bool m_hasMore; // do we have more tokens? }; -#endif +#endif // _WX_TOKENZRH