]>
Commit | Line | Data |
---|---|---|
f4ada568 GL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tokenzr.h | |
3 | // Purpose: String tokenizer | |
4 | // Author: Guilhem Lavaux | |
bbf8fc53 | 5 | // Modified by: Vadim Zeitlin |
f4ada568 GL |
6 | // Created: 04/22/98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Guilhem Lavaux | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_TOKENZRH | |
13 | #define _WX_TOKENZRH | |
14 | ||
15 | #ifdef __GNUG__ | |
2224580a | 16 | #pragma interface "tokenzr.h" |
f4ada568 GL |
17 | #endif |
18 | ||
19 | #include "wx/object.h" | |
20 | #include "wx/string.h" | |
bbf8fc53 VZ |
21 | |
22 | // default: delimiters are usual white space characters | |
23 | #define wxDEFAULT_DELIMITERS (_T(" \t\r\n")) | |
f4ada568 | 24 | |
85833f5c VZ |
25 | class WXDLLEXPORT wxStringTokenizer : public wxObject |
26 | { | |
f4ada568 | 27 | public: |
bbf8fc53 VZ |
28 | // ctors and such |
29 | wxStringTokenizer() { m_retdelims = FALSE; m_pos = 0; } | |
85833f5c | 30 | wxStringTokenizer(const wxString& to_tokenize, |
bbf8fc53 | 31 | const wxString& delims = wxDEFAULT_DELIMITERS, |
85833f5c | 32 | bool ret_delim = FALSE); |
bbf8fc53 VZ |
33 | void SetString(const wxString& to_tokenize, |
34 | const wxString& delims = wxDEFAULT_DELIMITERS, | |
35 | bool ret_delim = FALSE); | |
85833f5c VZ |
36 | virtual ~wxStringTokenizer(); |
37 | ||
bbf8fc53 VZ |
38 | // count tokens/get next token |
39 | size_t CountTokens() const; | |
40 | bool HasMoreTokens() { return m_hasMore; } | |
41 | wxString GetNextToken(); | |
85833f5c | 42 | |
2224580a VZ |
43 | // One note about GetString -- it returns the string |
44 | // remaining after the previous tokens have been removed, | |
45 | // not the original string | |
bbf8fc53 | 46 | wxString GetString() const { return m_string; } |
85833f5c | 47 | |
bbf8fc53 VZ |
48 | // returns the current position (i.e. one index after the last returned |
49 | // token or 0 if GetNextToken() has never been called) in the original | |
50 | // string | |
51 | size_t GetPosition() const { return m_pos; } | |
dbdb39b2 | 52 | |
bbf8fc53 VZ |
53 | // for compatibility only, use GetNextToken() instead |
54 | wxString NextToken() { return GetNextToken(); } | |
85833f5c | 55 | |
2224580a | 56 | protected: |
bbf8fc53 VZ |
57 | wxString m_string, // the (rest of) string to tokenize |
58 | m_delims; // all delimiters | |
59 | ||
60 | size_t m_pos; // the position in the original string | |
61 | ||
62 | bool m_retdelims; // if TRUE, return delims with tokens | |
63 | bool m_hasMore; // do we have more tokens? | |
f4ada568 GL |
64 | }; |
65 | ||
85833f5c | 66 | #endif // _WX_TOKENZRH |