Interface header review of wxStringTokenizer by Azriel Fasten.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53464 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -6,96 +6,86 @@
|
|||||||
// Licence: wxWindows license
|
// Licence: wxWindows license
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
The behaviour of wxStringTokenizer is governed by the
|
||||||
|
wxStringTokenizer::wxStringTokenizer() or wxStringTokenizer::SetString()
|
||||||
|
with the parameter @e mode, which may be one of the following:
|
||||||
|
*/
|
||||||
|
enum wxStringTokenizerMode
|
||||||
|
{
|
||||||
|
wxTOKEN_INVALID = -1, ///< Invalid tokenizer mode.
|
||||||
|
|
||||||
|
/**
|
||||||
|
Default behaviour: wxStringTokenizer will behave in the same way as
|
||||||
|
@c strtok() (::wxTOKEN_STRTOK) if the delimiters string only contains
|
||||||
|
white space characters but, unlike the standard function, it will
|
||||||
|
behave like ::wxTOKEN_RET_EMPTY, returning 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.
|
||||||
|
@c TAB or comma delimited text files).
|
||||||
|
*/
|
||||||
|
wxTOKEN_DEFAULT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
In this mode, the empty tokens in the middle of the string will be returned,
|
||||||
|
i.e. @c "a::b:" will be tokenized in three tokens @c 'a', " and @c 'b'. Notice
|
||||||
|
that all trailing delimiters are ignored in this mode, not just the last one,
|
||||||
|
i.e. a string @c "a::b::" would still result in the same set of tokens.
|
||||||
|
*/
|
||||||
|
wxTOKEN_RET_EMPTY,
|
||||||
|
|
||||||
|
/**
|
||||||
|
In this mode, empty trailing tokens (including the one after the last delimiter
|
||||||
|
character) will be returned as well. The string @c "a::b:" will be tokenized in
|
||||||
|
four tokens: the already mentioned ones and another empty one as the last one
|
||||||
|
and a string @c "a::b::" will have five tokens.
|
||||||
|
*/
|
||||||
|
wxTOKEN_RET_EMPTY_ALL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
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 ::wxTOKEN_RET_EMPTY. Notice that there is no
|
||||||
|
mode like this one but behaving like ::wxTOKEN_RET_EMPTY_ALL instead of
|
||||||
|
::wxTOKEN_RET_EMPTY, use ::wxTOKEN_RET_EMPTY_ALL and
|
||||||
|
wxStringTokenizer::GetLastDelimiter() to emulate it.
|
||||||
|
*/
|
||||||
|
wxTOKEN_RET_DELIMS,
|
||||||
|
|
||||||
|
/**
|
||||||
|
In this mode the class behaves exactly like the standard @c strtok() function:
|
||||||
|
the empty tokens are never returned.
|
||||||
|
*/
|
||||||
|
wxTOKEN_STRTOK
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class wxStringTokenizer
|
@class wxStringTokenizer
|
||||||
@wxheader{tokenzr.h}
|
@wxheader{tokenzr.h}
|
||||||
|
|
||||||
wxStringTokenizer helps you to break a string up into a number of tokens. It
|
wxStringTokenizer helps you to break a string up into a number of tokens.
|
||||||
replaces the standard C function @c strtok() and also extends it in a
|
It replaces the standard C function @c strtok() and also extends it in a
|
||||||
number of ways.
|
number of ways.
|
||||||
|
|
||||||
To use this class, you should create a wxStringTokenizer object, give it the
|
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
|
string to tokenize and also the delimiters which separate tokens in the string
|
||||||
(by default, white space characters will be used).
|
(by default, white space characters will be used).
|
||||||
|
|
||||||
Then wxStringTokenizer::GetNextToken may be called
|
Then wxStringTokenizer::GetNextToken() may be called repeatedly until
|
||||||
repeatedly until it wxStringTokenizer::HasMoreTokens
|
wxStringTokenizer::HasMoreTokens() returns @false.
|
||||||
returns @false.
|
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
@code
|
@code
|
||||||
wxStringTokenizer tkz(wxT("first:second:third:fourth"), wxT(":"));
|
wxStringTokenizer tokenizer("first:second:third:fourth", ":");
|
||||||
while ( tkz.HasMoreTokens() )
|
while ( tokenizer.HasMoreTokens() )
|
||||||
{
|
{
|
||||||
wxString token = tkz.GetNextToken();
|
wxString token = tokenizer.GetNextToken();
|
||||||
|
|
||||||
// process token here
|
// process token here
|
||||||
}
|
}
|
||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
By default, wxStringTokenizer will behave in the same way as @c 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. @c TAB or comma delimited text
|
|
||||||
files).
|
|
||||||
|
|
||||||
The behaviour is governed by the last
|
|
||||||
@ref wxStringTokenizer::wxstringtokenizer
|
|
||||||
constructor/wxStringTokenizer::SetString
|
|
||||||
parameter @c mode which may be one of the following:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@c wxTOKEN_DEFAULT
|
|
||||||
|
|
||||||
|
|
||||||
Default behaviour (as described above):
|
|
||||||
same as @c wxTOKEN_STRTOK if the delimiter string contains only
|
|
||||||
whitespaces, same as @c wxTOKEN_RET_EMPTY otherwise
|
|
||||||
|
|
||||||
|
|
||||||
@c wxTOKEN_RET_EMPTY
|
|
||||||
|
|
||||||
|
|
||||||
In this mode, the empty tokens in the
|
|
||||||
middle of the string will be returned, i.e. @c "a::b:" will be tokenized in
|
|
||||||
three tokens 'a', " and 'b'. Notice that all trailing delimiters are ignored
|
|
||||||
in this mode, not just the last one, i.e. a string @c "a::b::" would
|
|
||||||
still result in the same set of tokens.
|
|
||||||
|
|
||||||
|
|
||||||
@c wxTOKEN_RET_EMPTY_ALL
|
|
||||||
|
|
||||||
|
|
||||||
In this mode, empty trailing tokens
|
|
||||||
(including the one after the last delimiter character) will be returned as
|
|
||||||
well. The string @c "a::b:" will be tokenized in four tokens: the already
|
|
||||||
mentioned ones and another empty one as the last one and a string
|
|
||||||
@c "a::b::" will have five tokens.
|
|
||||||
|
|
||||||
|
|
||||||
@c 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
|
|
||||||
@c wxTOKEN_RET_EMPTY. Notice that there is no mode like this one but
|
|
||||||
behaving like @c wxTOKEN_RET_EMPTY_ALL instead of
|
|
||||||
@c wxTOKEN_RET_EMPTY, use @c wxTOKEN_RET_EMPTY_ALL and
|
|
||||||
wxStringTokenizer::GetLastDelimiter to emulate it.
|
|
||||||
|
|
||||||
|
|
||||||
@c wxTOKEN_STRTOK
|
|
||||||
|
|
||||||
|
|
||||||
In this mode the class behaves exactly like
|
|
||||||
the standard @c strtok() function: the empty tokens are never returned.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@library{wxbase}
|
@library{wxbase}
|
||||||
@category{data}
|
@category{data}
|
||||||
|
|
||||||
@@ -104,31 +94,35 @@
|
|||||||
class wxStringTokenizer : public wxObject
|
class wxStringTokenizer : public wxObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//@{
|
|
||||||
/**
|
/**
|
||||||
Constructor. Pass the string to tokenize, a string containing delimiters
|
Default constructor. You must call SetString() before calling any other
|
||||||
and the mode specifying how the string should be tokenized.
|
methods.
|
||||||
*/
|
*/
|
||||||
wxStringTokenizer();
|
wxStringTokenizer();
|
||||||
|
/**
|
||||||
|
Constructor. Pass the string to tokenize, a string containing
|
||||||
|
delimiters, and the @a mode specifying how the string should be
|
||||||
|
tokenized.
|
||||||
|
|
||||||
|
@see SetString()
|
||||||
|
*/
|
||||||
wxStringTokenizer(const wxString& str,
|
wxStringTokenizer(const wxString& str,
|
||||||
const wxString& delims = " \t\r\n",
|
const wxString& delims = " \t\r\n",
|
||||||
wxStringTokenizerMode mode = wxTOKEN_DEFAULT);
|
wxStringTokenizerMode mode = wxTOKEN_DEFAULT);
|
||||||
//@}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the number of tokens remaining in the input string. The number of
|
Returns the number of tokens remaining in the input string. The number
|
||||||
tokens returned by this function is decremented each time
|
of tokens returned by this function is decremented each time
|
||||||
GetNextToken() is called and when it
|
GetNextToken() is called and when it reaches 0, HasMoreTokens()
|
||||||
reaches 0 HasMoreTokens() returns
|
returns @false.
|
||||||
@false.
|
|
||||||
*/
|
*/
|
||||||
int CountTokens() const;
|
int CountTokens() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the delimiter which ended scan for the last token returned by
|
Returns the delimiter which ended scan for the last token returned by
|
||||||
GetNextToken() or @c NUL if
|
GetNextToken() or @c NUL if there had been no calls to this function
|
||||||
there had been no calls to this function yet or if it returned the trailing
|
yet or if it returned the trailing empty token in
|
||||||
empty token in @c wxTOKEN_RET_EMPTY_ALL mode.
|
::wxTOKEN_RET_EMPTY_ALL mode.
|
||||||
|
|
||||||
@since 2.7.0
|
@since 2.7.0
|
||||||
*/
|
*/
|
||||||
@@ -157,12 +151,11 @@ public:
|
|||||||
bool HasMoreTokens() const;
|
bool HasMoreTokens() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes the tokenizer.
|
Initializes the tokenizer. Pass the string to tokenize, a string
|
||||||
Pass the string to tokenize, a string containing delimiters,
|
containing delimiters, and the @a mode specifying how the string
|
||||||
and the mode specifying how the string should be tokenized.
|
should be tokenized.
|
||||||
*/
|
*/
|
||||||
void SetString(const wxString& to_tokenize,
|
void SetString(const wxString& to_tokenize,
|
||||||
const wxString& delims = " \t\r\n",
|
const wxString& delims = " \t\r\n",
|
||||||
wxStringTokenizerMode mode = wxTOKEN_DEFAULT);
|
wxStringTokenizerMode mode = wxTOKEN_DEFAULT);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user