]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tokenizr.tex
document GetAnimation() (patch 1695722)
[wxWidgets.git] / docs / latex / wx / tokenizr.tex
CommitLineData
d134d2d4
JS
1\section{\class{wxStringTokenizer}}\label{wxstringtokenizer}
2
7c968cee
VZ
3wxStringTokenizer helps you to break a string up into a number of tokens. It
4replaces the standard C function {\tt strtok()} and also extends it in a
5number of ways.
d134d2d4 6
bbf8fc53
VZ
7To use this class, you should create a wxStringTokenizer object, give it the
8string to tokenize and also the delimiters which separate tokens in the string
9(by default, white space characters will be used).
10
11Then \helpref{GetNextToken}{wxstringtokenizergetnexttoken} may be called
12repeatedly until it \helpref{HasMoreTokens}{wxstringtokenizerhasmoretokens}
719ee7c4 13returns \false.
bbf8fc53
VZ
14
15For example:
16
17\begin{verbatim}
18
7e34b934 19wxStringTokenizer tkz(wxT("first:second:third:fourth"), wxT(":"));
bbf8fc53
VZ
20while ( tkz.HasMoreTokens() )
21{
22 wxString token = tkz.GetNextToken();
23
24 // process token here
25}
26\end{verbatim}
27
7c968cee
VZ
28By default, wxStringTokenizer will behave in the same way as {\tt strtok()} if
29the delimiters string only contains white space characters but, unlike the
30standard function, it will return empty tokens if this is not the case. This
31is helpful for parsing strictly formatted data where the number of fields is
32fixed but some of them may be empty (i.e. {\tt TAB} or comma delimited text
33files).
34
35The behaviour is governed by the last
36\helpref{constructor}{wxstringtokenizerwxstringtokenizer}/\helpref{SetString}{wxstringtokenizersetstring}
37parameter {\tt mode} which may be one of the following:
38
39\twocolwidtha{5cm}%
40\begin{twocollist}\itemsep=0pt
41\twocolitem{{\tt wxTOKEN\_DEFAULT}}{Default behaviour (as described above):
42same as {\tt wxTOKEN\_STRTOK} if the delimiter string contains only
43whitespaces, same as {\tt wxTOKEN\_RET\_EMPTY} otherwise}
44\twocolitem{{\tt wxTOKEN\_RET\_EMPTY}}{In this mode, the empty tokens in the
45middle of the string will be returned, i.e. {\tt "a::b:"} will be tokenized in
4626c57c
VZ
46three tokens `a', `' and `b'. Notice that all trailing delimiters are ignored
47in this mode, not just the last one, i.e. a string \texttt{"a::b::"} would
48still result in the same set of tokens.}
49\twocolitem{{\tt wxTOKEN\_RET\_EMPTY\_ALL}}{In this mode, empty trailing tokens
50(including the one after the last delimiter character) will be returned as
51well. The string \texttt{"a::b:"} will be tokenized in four tokens: the already
52mentioned ones and another empty one as the last one and a string
53\texttt{"a::b::"} will have five tokens.}
7c968cee
VZ
54\twocolitem{{\tt wxTOKEN\_RET\_DELIMS}}{In this mode, the delimiter character
55after the end of the current token (there may be none if this is the last
56token) is returned appended to the token. Otherwise, it is the same mode as
4626c57c
VZ
57\texttt{wxTOKEN\_RET\_EMPTY}. Notice that there is no mode like this one but
58behaving like \texttt{wxTOKEN\_RET\_EMPTY\_ALL} instead of
59\texttt{wxTOKEN\_RET\_EMPTY}, use \texttt{wxTOKEN\_RET\_EMPTY\_ALL} and
60\helpref{GetLastDelimiter()}{wxstringtokenizergetlastdelimiter} to emulate it.}
7c968cee 61\twocolitem{{\tt wxTOKEN\_STRTOK}}{In this mode the class behaves exactly like
4626c57c 62the standard {\tt strtok()} function: the empty tokens are never returned.}
7c968cee 63\end{twocollist}
bbf8fc53 64
d134d2d4
JS
65\wxheading{Derived from}
66
67\helpref{wxObject}{wxobject}
68
bf00c875
VZ
69\wxheading{See also}
70
71\helpref{wxStringTokenize}{wxstringtokenize}
72
954b8ae6
JS
73\wxheading{Include files}
74
75<wx/tokenzr.h>
76
d134d2d4
JS
77\latexignore{\rtfignore{\wxheading{Members}}}
78
719ee7c4 79
d134d2d4
JS
80\membersection{wxStringTokenizer::wxStringTokenizer}\label{wxstringtokenizerwxstringtokenizer}
81
dbdb39b2
JS
82\func{}{wxStringTokenizer}{\void}
83
7c968cee
VZ
84Default constructor. You must call
85\helpref{SetString}{wxstringtokenizersetstring} before calling any other
86methods.
dbdb39b2 87
7c968cee 88\func{}{wxStringTokenizer}{\param{const wxString\& }{str}, \param{const wxString\& }{delims = " $\backslash$t$\backslash$r$\backslash$n"}, \param{wxStringTokenizerMode }{mode = wxTOKEN\_DEFAULT}}
d134d2d4 89
7c968cee
VZ
90Constructor. Pass the string to tokenize, a string containing delimiters
91and the mode specifying how the string should be tokenized.
d134d2d4 92
719ee7c4 93
d134d2d4
JS
94\membersection{wxStringTokenizer::CountTokens}\label{wxstringtokenizercounttokens}
95
ad813b00 96\constfunc{int}{CountTokens}{\void}
d134d2d4 97
719ee7c4
VZ
98Returns the number of tokens remaining in the input string. The number of
99tokens returned by this function is decremented each time
100\helpref{GetNextToken}{wxstringtokenizergetnexttoken} is called and when it
101reaches $0$ \helpref{HasMoreTokens}{wxstringtokenizerhasmoretokens} returns
102\false.
103
d134d2d4 104
ad813b00 105\membersection{wxStringTokenizer::HasMoreTokens}\label{wxstringtokenizerhasmoretokens}
d134d2d4 106
ad813b00 107\constfunc{bool}{HasMoreTokens}{\void}
d134d2d4 108
719ee7c4
VZ
109Returns \true if the tokenizer has further tokens, \false if none are left.
110
d134d2d4 111
4626c57c
VZ
112\membersection{wxStringTokenizer::GetLastDelimiter}\label{wxstringtokenizergetlastdelimiter}
113
114\func{wxChar}{GetLastDelimiter}{\void}
115
116Returns the delimiter which ended scan for the last token returned by
117\helpref{GetNextToken()}{wxstringtokenizergetnexttoken} or \texttt{NUL} if
118there had been no calls to this function yet or if it returned the trailing
119empty token in \texttt{wxTOKEN\_RET\_EMPTY\_ALL} mode.
120
b2458f31
MR
121\newsince{2.7.0}
122
4626c57c 123
ad813b00 124\membersection{wxStringTokenizer::GetNextToken}\label{wxstringtokenizergetnexttoken}
d134d2d4 125
4626c57c 126\constfunc{wxString}{GetNextToken}{\void}
d134d2d4 127
bbf8fc53
VZ
128Returns the next token or empty string if the end of string was reached.
129
719ee7c4 130
bbf8fc53
VZ
131\membersection{wxStringTokenizer::GetPosition}\label{wxstringtokenizergetposition}
132
133\constfunc{size\_t}{GetPosition}{\void}
134
135Returns the current position (i.e. one index after the last returned
136token or 0 if GetNextToken() has never been called) in the original
137string.
d134d2d4 138
719ee7c4 139
d134d2d4
JS
140\membersection{wxStringTokenizer::GetString}\label{wxstringtokenizergetstring}
141
ad813b00 142\constfunc{wxString}{GetString}{\void}
d134d2d4 143
bbf8fc53 144Returns the part of the starting string without all token already extracted.
d134d2d4 145
719ee7c4 146
dbdb39b2
JS
147\membersection{wxStringTokenizer::SetString}\label{wxstringtokenizersetstring}
148
7c968cee 149\func{void}{SetString}{\param{const wxString\& }{to\_tokenize}, \param{const wxString\& }{delims = " $\backslash$t$\backslash$r$\backslash$n"}, \param{wxStringTokenizerMode }{mode = wxTOKEN\_DEFAULT}}
d134d2d4 150
dbdb39b2
JS
151Initializes the tokenizer.
152
153Pass the string to tokenize, a string containing delimiters,
7c968cee 154and the mode specifying how the string should be tokenized.
d134d2d4 155