X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/886dd7d28e50c003cc88b81b968d487a3c17b0d7..a2c5db764c8450dda6e87fe58917b0a00ec2c74f:/include/wx/tokenzr.h diff --git a/include/wx/tokenzr.h b/include/wx/tokenzr.h index 9cdcffe072..d47d52c324 100644 --- a/include/wx/tokenzr.h +++ b/include/wx/tokenzr.h @@ -12,12 +12,9 @@ #ifndef _WX_TOKENZRH #define _WX_TOKENZRH -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma interface "tokenzr.h" -#endif - #include "wx/object.h" #include "wx/string.h" +#include "wx/arrstr.h" // ---------------------------------------------------------------------------- // constants @@ -41,7 +38,7 @@ enum wxStringTokenizerMode // wxStringTokenizer: replaces infamous strtok() and has some other features // ---------------------------------------------------------------------------- -class WXDLLEXPORT_BASE wxStringTokenizer : public wxObject +class WXDLLIMPEXP_BASE wxStringTokenizer : public wxObject { public: // ctors and initializers @@ -61,17 +58,21 @@ public: void Reinit(const wxString& str); // tokens access - // count them + // 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; } + 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 @@ -82,6 +83,9 @@ public: // 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 // ------------------------------------------- @@ -107,14 +111,14 @@ public: protected: bool IsOk() const { return m_mode != wxTOKEN_INVALID; } - wxString m_string, // the (rest of) string to tokenize - m_delims; // all delimiters + wxString m_string, // the string we tokenize + m_delims; // all possible delimiters - size_t m_pos; // the position in the original string + size_t m_pos; // the current position in m_string wxStringTokenizerMode m_mode; // see wxTOKEN_XXX values - bool m_hasMore; // do we have more (possible empty) tokens? + wxChar m_lastDelim; // delimiter after last token or '\0' }; // ---------------------------------------------------------------------------- @@ -123,7 +127,7 @@ protected: // the function takes the same parameters as wxStringTokenizer ctor and returns // the array containing all tokens -wxArrayString WXDLLEXPORT_BASE +wxArrayString WXDLLIMPEXP_BASE wxStringTokenize(const wxString& str, const wxString& delims = wxDEFAULT_DELIMITERS, wxStringTokenizerMode mode = wxTOKEN_DEFAULT);