|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |
#include "ot/util/StringTokenizer.h"
Splits a String into a sequence of delimited tokens.
A StringTokenizer is constructed using a String together with a set of delimiter characters contained in another String. The StringTokenizer will split the controlled String into a sequence of tokens, each token separated by one or more characters from the set of delimiter characters.The StringTokenizer can behave in one of three ways, depending on the values of the bReturnDelims and bReturnContiguousDelims constructor flags:
The following example splits a string containing words separated by space characters into a number of word tokens. Delimiters are not returned in this case:
StringTokenizer tokenizer(OT_T("this is a test")); while (tokenizer.hasMoreTokens()) { Console::cout() << tokenizer.nextToken() << endl; }
In common with all String handling in OpenTop, the controlled String and the set of delimiter characters may contain Unicode characters that have been encoded into a multi-character sequence. The StringTokenizer class correctly treats multi-character sequences as single Unicode characters for the purposes of comparison between characters in the controlled String and the set of delimiter characters.
Constructor/Destructor Summary | |
StringTokenizer(const String& str) Constructs a StringTokenizer with the controlled String str using a default white-space string as the delimiter. | |
StringTokenizer(const String& str, const String& delim, bool bReturnDelims, bool bReturnContiguousDelims) Constructs a StringTokenizer with the controlled String str using all the Unicode characters from delim as delimiters. |
Method Summary | |
bool |
hasMoreTokens() const Tests to see if more tokens exist in the controlled String. |
String |
nextToken() Returns the next token from the controlled String. |
String |
peekNextToken() const Returns the next token without advancing the position of the StringTokenizer. |
std::vector< String > |
toVector() Returns the remaining tokens as elements of a std::vector<String>. |
Constructor/Destructor Detail |
StringTokenizer(const String& str)
str
- StringTokenizer(const String& str, const String& delim, bool bReturnDelims, bool bReturnContiguousDelims)
str
- delim
- bReturnDelims
- bReturnContiguousDelims
- Method Detail |
bool hasMoreTokens() const
String nextToken()
When all the tokens have been exhausted, an empty String is returned.
String peekNextToken() const
std::vector< String > toVector()
This function is implemented as if nextToken() is called until it returns an empty String, adding each returned token to the vector. Therefore, if the StringTokenizer is set to return delimiters as tokens, the returned vector will contain the delimiters also.
|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |