1999-01-24 10:23:54 -05:00
|
|
|
\section{\class{wxStringTokenizer}}\label{wxstringtokenizer}
|
|
|
|
|
2000-02-04 13:31:26 -05:00
|
|
|
wxStringTokenizer helps you to break a string up into a number of tokens. It
|
|
|
|
replaces the standard C function {\tt strtok()} and also extends it in a
|
|
|
|
number of ways.
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2000-01-31 15:46:49 -05:00
|
|
|
To use this class, you should create a wxStringTokenizer object, give it the
|
|
|
|
string to tokenize and also the delimiters which separate tokens in the string
|
|
|
|
(by default, white space characters will be used).
|
|
|
|
|
|
|
|
Then \helpref{GetNextToken}{wxstringtokenizergetnexttoken} may be called
|
|
|
|
repeatedly until it \helpref{HasMoreTokens}{wxstringtokenizerhasmoretokens}
|
2004-04-23 15:22:19 -04:00
|
|
|
returns \false.
|
2000-01-31 15:46:49 -05:00
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
|
2003-08-13 08:16:50 -04:00
|
|
|
wxStringTokenizer tkz(wxT("first:second:third:fourth"), wxT(":"));
|
2000-01-31 15:46:49 -05:00
|
|
|
while ( tkz.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
wxString token = tkz.GetNextToken();
|
|
|
|
|
|
|
|
// process token here
|
|
|
|
}
|
|
|
|
\end{verbatim}
|
|
|
|
|
2000-02-04 13:31:26 -05:00
|
|
|
By default, wxStringTokenizer will behave in the same way as {\tt strtok()} if
|
|
|
|
the delimiters string only contains white space characters but, unlike the
|
|
|
|
standard function, it will return empty tokens if this is not the case. This
|
|
|
|
is helpful for parsing strictly formatted data where the number of fields is
|
|
|
|
fixed but some of them may be empty (i.e. {\tt TAB} or comma delimited text
|
|
|
|
files).
|
|
|
|
|
|
|
|
The behaviour is governed by the last
|
|
|
|
\helpref{constructor}{wxstringtokenizerwxstringtokenizer}/\helpref{SetString}{wxstringtokenizersetstring}
|
|
|
|
parameter {\tt mode} which may be one of the following:
|
|
|
|
|
|
|
|
\twocolwidtha{5cm}%
|
|
|
|
\begin{twocollist}\itemsep=0pt
|
|
|
|
\twocolitem{{\tt wxTOKEN\_DEFAULT}}{Default behaviour (as described above):
|
|
|
|
same as {\tt wxTOKEN\_STRTOK} if the delimiter string contains only
|
|
|
|
whitespaces, same as {\tt wxTOKEN\_RET\_EMPTY} otherwise}
|
|
|
|
\twocolitem{{\tt wxTOKEN\_RET\_EMPTY}}{In this mode, the empty tokens in the
|
|
|
|
middle of the string will be returned, i.e. {\tt "a::b:"} will be tokenized in
|
|
|
|
three tokens `a', `' and `b'.}
|
|
|
|
\twocolitem{{\tt wxTOKEN\_RET\_EMPTY\_ALL}}{In this mode, empty trailing token
|
|
|
|
(after the last delimiter character) will be returned as well. The string as
|
|
|
|
above will contain four tokens: the already mentioned ones and another empty
|
|
|
|
one as the last one.}
|
|
|
|
\twocolitem{{\tt wxTOKEN\_RET\_DELIMS}}{In this mode, the delimiter character
|
|
|
|
after the end of the current token (there may be none if this is the last
|
|
|
|
token) is returned appended to the token. Otherwise, it is the same mode as
|
|
|
|
{\tt wxTOKEN\_RET\_EMPTY}.}
|
|
|
|
\twocolitem{{\tt wxTOKEN\_STRTOK}}{In this mode the class behaves exactly like
|
|
|
|
the standard {\tt strtok()} function. The empty tokens are never returned.}
|
|
|
|
\end{twocollist}
|
2000-01-31 15:46:49 -05:00
|
|
|
|
1999-01-24 10:23:54 -05:00
|
|
|
\wxheading{Derived from}
|
|
|
|
|
|
|
|
\helpref{wxObject}{wxobject}
|
|
|
|
|
1999-02-15 15:41:29 -05:00
|
|
|
\wxheading{Include files}
|
|
|
|
|
|
|
|
<wx/tokenzr.h>
|
|
|
|
|
1999-01-24 10:23:54 -05:00
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
|
2004-04-23 15:22:19 -04:00
|
|
|
|
1999-01-24 10:23:54 -05:00
|
|
|
\membersection{wxStringTokenizer::wxStringTokenizer}\label{wxstringtokenizerwxstringtokenizer}
|
|
|
|
|
1999-02-16 15:17:02 -05:00
|
|
|
\func{}{wxStringTokenizer}{\void}
|
|
|
|
|
2000-02-04 13:31:26 -05:00
|
|
|
Default constructor. You must call
|
|
|
|
\helpref{SetString}{wxstringtokenizersetstring} before calling any other
|
|
|
|
methods.
|
1999-02-16 15:17:02 -05:00
|
|
|
|
2000-02-04 13:31:26 -05:00
|
|
|
\func{}{wxStringTokenizer}{\param{const wxString\& }{str}, \param{const wxString\& }{delims = " $\backslash$t$\backslash$r$\backslash$n"}, \param{wxStringTokenizerMode }{mode = wxTOKEN\_DEFAULT}}
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2000-02-04 13:31:26 -05:00
|
|
|
Constructor. Pass the string to tokenize, a string containing delimiters
|
|
|
|
and the mode specifying how the string should be tokenized.
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2004-04-23 15:22:19 -04:00
|
|
|
|
1999-01-24 10:23:54 -05:00
|
|
|
\membersection{wxStringTokenizer::CountTokens}\label{wxstringtokenizercounttokens}
|
|
|
|
|
1999-02-24 03:02:28 -05:00
|
|
|
\constfunc{int}{CountTokens}{\void}
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2004-04-23 15:22:19 -04:00
|
|
|
Returns the number of tokens remaining in the input string. The number of
|
|
|
|
tokens returned by this function is decremented each time
|
|
|
|
\helpref{GetNextToken}{wxstringtokenizergetnexttoken} is called and when it
|
|
|
|
reaches $0$ \helpref{HasMoreTokens}{wxstringtokenizerhasmoretokens} returns
|
|
|
|
\false.
|
|
|
|
|
1999-01-24 10:23:54 -05:00
|
|
|
|
1999-02-24 03:02:28 -05:00
|
|
|
\membersection{wxStringTokenizer::HasMoreTokens}\label{wxstringtokenizerhasmoretokens}
|
1999-01-24 10:23:54 -05:00
|
|
|
|
1999-02-24 03:02:28 -05:00
|
|
|
\constfunc{bool}{HasMoreTokens}{\void}
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2004-04-23 15:22:19 -04:00
|
|
|
Returns \true if the tokenizer has further tokens, \false if none are left.
|
|
|
|
|
1999-01-24 10:23:54 -05:00
|
|
|
|
1999-02-24 03:02:28 -05:00
|
|
|
\membersection{wxStringTokenizer::GetNextToken}\label{wxstringtokenizergetnexttoken}
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2000-02-04 13:31:26 -05:00
|
|
|
\func{wxString}{GetNextToken}{\void}
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2000-01-31 15:46:49 -05:00
|
|
|
Returns the next token or empty string if the end of string was reached.
|
|
|
|
|
2004-04-23 15:22:19 -04:00
|
|
|
|
2000-01-31 15:46:49 -05:00
|
|
|
\membersection{wxStringTokenizer::GetPosition}\label{wxstringtokenizergetposition}
|
|
|
|
|
|
|
|
\constfunc{size\_t}{GetPosition}{\void}
|
|
|
|
|
|
|
|
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.
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2004-04-23 15:22:19 -04:00
|
|
|
|
1999-01-24 10:23:54 -05:00
|
|
|
\membersection{wxStringTokenizer::GetString}\label{wxstringtokenizergetstring}
|
|
|
|
|
1999-02-24 03:02:28 -05:00
|
|
|
\constfunc{wxString}{GetString}{\void}
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2000-01-31 15:46:49 -05:00
|
|
|
Returns the part of the starting string without all token already extracted.
|
1999-01-24 10:23:54 -05:00
|
|
|
|
2004-04-23 15:22:19 -04:00
|
|
|
|
1999-02-16 15:17:02 -05:00
|
|
|
\membersection{wxStringTokenizer::SetString}\label{wxstringtokenizersetstring}
|
|
|
|
|
2000-02-04 13:31:26 -05:00
|
|
|
\func{void}{SetString}{\param{const wxString\& }{to\_tokenize}, \param{const wxString\& }{delims = " $\backslash$t$\backslash$r$\backslash$n"}, \param{wxStringTokenizerMode }{mode = wxTOKEN\_DEFAULT}}
|
1999-01-24 10:23:54 -05:00
|
|
|
|
1999-02-16 15:17:02 -05:00
|
|
|
Initializes the tokenizer.
|
|
|
|
|
|
|
|
Pass the string to tokenize, a string containing delimiters,
|
2000-02-04 13:31:26 -05:00
|
|
|
and the mode specifying how the string should be tokenized.
|
1999-01-24 10:23:54 -05:00
|
|
|
|