ost::StringTokenizer(3) | Library Functions Manual | ost::StringTokenizer(3) |
ost::StringTokenizer - Splits delimited string into tokens.
#include <tokenizer.h>
class iterator
The input forward iterator for tokens. class NoSuchElementException
Exception thrown, if someone tried to read beyond the end of the tokens.
StringTokenizer (const char *str, const char *delim, bool
skipAllDelim=false, bool trim=false)
creates a new StringTokenizer for a string and a given set of
delimiters. StringTokenizer (const char *s)
create a new StringTokenizer which splits the input string at
whitespaces. iterator begin () const
returns the begin iterator void setDelimiters (const char *d)
changes the set of delimiters used in subsequent iterations. iterator
begin (const char *d)
returns a begin iterator with an alternate set of delimiters. const
iterator & end () const
the iterator marking the end.
static const char *const SPACE
a delimiter string containing all usual whitespace delimiters.
class StringTokenizer::iterator
Splits delimited string into tokens.
The StringTokenizer takes a pointer to a string and a pointer to a string containing a number of possible delimiters. The StringTokenizer provides an input forward iterator which allows to iterate through all tokens. An iterator behaves like a logical pointer to the tokens, i.e. to shift to the next token, you've to increment the iterator, you get the token by dereferencing the iterator.
Memory consumption: This class operates on the original string and only allocates memory for the individual tokens actually requested, so this class allocates at maximum the space required for the longest token in the given string. Since for each iteration, memory is reclaimed for the last token, you MAY NOT store pointers to them; if you need them afterwards, copy them. You may not modify the original string while you operate on it with the StringTokenizer; the behaviour is undefined in that case.
The iterator has one special method 'nextDelimiter()' which returns a character containing the next delimiter following this tokenization process or '\0', if there are no following delimiters. In case of skipAllDelim, it returns the FIRST delimiter.
With the method 'setDelimiters(const char*)' you may change the set of delimiters. It affects all running iterators.
Example:
StringTokenizer st('mary had a little lamb;its fleece was..', ' ;');
StringTokenizer::iterator i;
for (i = st.begin() ; i != st.end() ; ++i) {
cout << 'Token: '' << *i << ''\t';
cout << ' next Delim: '' << i.nextDelimiter() << ''' << endl;
}
Author:
License:
creates a new StringTokenizer for a string and a given set of delimiters.
Parameters:
create a new StringTokenizer which splits the input string at whitespaces. The tokens are stripped from whitespaces. This means, if you change the set of delimiters in either the 'begin(const char *delim)' method or in 'setDelimiters()', you then get whitespace trimmed tokens, delimited by the new set. Behaves like StringTokenizer(s, StringTokenizer::SPACE,false,true);
returns the begin iterator
returns a begin iterator with an alternate set of delimiters.
the iterator marking the end.
changes the set of delimiters used in subsequent iterations.
a delimiter string containing all usual whitespace delimiters. These are space, tab, newline, carriage return, formfeed and vertical tab. (see isspace() manpage).
Generated automatically by Doxygen for GNU CommonC++ from the source code.
Wed Oct 31 2018 | GNU CommonC++ |