51 myTosplit(tosplit), myPos(0) {
57 myTosplit(tosplit), myPos(0) {
58 prepare(tosplit, token, splitAtAllChars);
63 myTosplit(tosplit), myPos(0) {
75 char* buf =
new char[2];
76 buf[0] = (char) special;
143 int len = (int)token.length();
144 if (splitAtAllChars) {
147 while (beg < (
int)tosplit.length()) {
148 std::string::size_type end;
149 if (splitAtAllChars) {
150 end = tosplit.find_first_of(token, beg);
152 end = tosplit.find(token, beg);
154 if (end == std::string::npos) {
155 end = tosplit.length();
159 beg = (int)end + len;
160 if (beg == (
int)tosplit.length()) {
169 std::string::size_type len = tosplit.length();
170 std::string::size_type beg = 0;
171 while (beg < len && tosplit[beg] <=
SPACE) {
174 while (beg != std::string::npos && beg < len) {
175 std::string::size_type end = beg;
176 while (end < len && tosplit[end] >
SPACE) {
180 myLengths.push_back((
int)end - (
int)beg);
182 while (beg < len && tosplit[beg] <=
SPACE) {
189std::vector<std::string>
191 std::vector<std::string> ret;
194 ret.push_back(
next());
203 std::vector<std::string> v =
getVector();
204 return std::set<std::string>(v.begin(), v.end());
static const int NEWLINE
identifier for splitting the given string at all newline characters
std::string front()
returns the first substring without moving the iterator
std::set< std::string > getSet()
return set of strings
~StringTokenizer()
destructor
int size() const
returns the number of existing substrings
SizeVector myStarts
the list of substring starts
void reinit()
reinitialises the internal iterator
static const int WHITECHARS
identifier for splitting the given string at all whitespace characters
std::string get(int pos) const
returns the item at the given position
std::vector< std::string > getVector()
return vector of strings
bool hasNext()
returns the information whether further substrings exist
static const int TAB
the ascii index of the tab character
static const int SPACE
the ascii index of the highest whitespace character
SizeVector myLengths
the list of substring lengths
StringTokenizer()
default constructor
int myPos
the current position in the list of substrings
void prepare(const std::string &tosplit, const std::string &token, bool splitAtAllChars)
splits the first string at all occurrences of the second. If the third parameter is true split at all...
std::string myTosplit
the string to split
void prepareWhitechar(const std::string &tosplit)
splits the first string at all occurrences of whitechars
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined