]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tokenizr.tex
finished implementation for stencil and colored patterns
[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
46three tokens `a', `' and `b'.}
47\twocolitem{{\tt wxTOKEN\_RET\_EMPTY\_ALL}}{In this mode, empty trailing token
48(after the last delimiter character) will be returned as well. The string as
49above will contain four tokens: the already mentioned ones and another empty
50one as the last one.}
51\twocolitem{{\tt wxTOKEN\_RET\_DELIMS}}{In this mode, the delimiter character
52after the end of the current token (there may be none if this is the last
53token) is returned appended to the token. Otherwise, it is the same mode as
54{\tt wxTOKEN\_RET\_EMPTY}.}
55\twocolitem{{\tt wxTOKEN\_STRTOK}}{In this mode the class behaves exactly like
56the standard {\tt strtok()} function. The empty tokens are never returned.}
57\end{twocollist}
bbf8fc53 58
d134d2d4
JS
59\wxheading{Derived from}
60
61\helpref{wxObject}{wxobject}
62
bf00c875
VZ
63\wxheading{See also}
64
65\helpref{wxStringTokenize}{wxstringtokenize}
66
954b8ae6
JS
67\wxheading{Include files}
68
69<wx/tokenzr.h>
70
d134d2d4
JS
71\latexignore{\rtfignore{\wxheading{Members}}}
72
719ee7c4 73
d134d2d4
JS
74\membersection{wxStringTokenizer::wxStringTokenizer}\label{wxstringtokenizerwxstringtokenizer}
75
dbdb39b2
JS
76\func{}{wxStringTokenizer}{\void}
77
7c968cee
VZ
78Default constructor. You must call
79\helpref{SetString}{wxstringtokenizersetstring} before calling any other
80methods.
dbdb39b2 81
7c968cee 82\func{}{wxStringTokenizer}{\param{const wxString\& }{str}, \param{const wxString\& }{delims = " $\backslash$t$\backslash$r$\backslash$n"}, \param{wxStringTokenizerMode }{mode = wxTOKEN\_DEFAULT}}
d134d2d4 83
7c968cee
VZ
84Constructor. Pass the string to tokenize, a string containing delimiters
85and the mode specifying how the string should be tokenized.
d134d2d4 86
719ee7c4 87
d134d2d4
JS
88\membersection{wxStringTokenizer::CountTokens}\label{wxstringtokenizercounttokens}
89
ad813b00 90\constfunc{int}{CountTokens}{\void}
d134d2d4 91
719ee7c4
VZ
92Returns the number of tokens remaining in the input string. The number of
93tokens returned by this function is decremented each time
94\helpref{GetNextToken}{wxstringtokenizergetnexttoken} is called and when it
95reaches $0$ \helpref{HasMoreTokens}{wxstringtokenizerhasmoretokens} returns
96\false.
97
d134d2d4 98
ad813b00 99\membersection{wxStringTokenizer::HasMoreTokens}\label{wxstringtokenizerhasmoretokens}
d134d2d4 100
ad813b00 101\constfunc{bool}{HasMoreTokens}{\void}
d134d2d4 102
719ee7c4
VZ
103Returns \true if the tokenizer has further tokens, \false if none are left.
104
d134d2d4 105
ad813b00 106\membersection{wxStringTokenizer::GetNextToken}\label{wxstringtokenizergetnexttoken}
d134d2d4 107
7c968cee 108\func{wxString}{GetNextToken}{\void}
d134d2d4 109
bbf8fc53
VZ
110Returns the next token or empty string if the end of string was reached.
111
719ee7c4 112
bbf8fc53
VZ
113\membersection{wxStringTokenizer::GetPosition}\label{wxstringtokenizergetposition}
114
115\constfunc{size\_t}{GetPosition}{\void}
116
117Returns the current position (i.e. one index after the last returned
118token or 0 if GetNextToken() has never been called) in the original
119string.
d134d2d4 120
719ee7c4 121
d134d2d4
JS
122\membersection{wxStringTokenizer::GetString}\label{wxstringtokenizergetstring}
123
ad813b00 124\constfunc{wxString}{GetString}{\void}
d134d2d4 125
bbf8fc53 126Returns the part of the starting string without all token already extracted.
d134d2d4 127
719ee7c4 128
dbdb39b2
JS
129\membersection{wxStringTokenizer::SetString}\label{wxstringtokenizersetstring}
130
7c968cee 131\func{void}{SetString}{\param{const wxString\& }{to\_tokenize}, \param{const wxString\& }{delims = " $\backslash$t$\backslash$r$\backslash$n"}, \param{wxStringTokenizerMode }{mode = wxTOKEN\_DEFAULT}}
d134d2d4 132
dbdb39b2
JS
133Initializes the tokenizer.
134
135Pass the string to tokenize, a string containing delimiters,
7c968cee 136and the mode specifying how the string should be tokenized.
d134d2d4 137