ost::StringTokenizer(3)
π ost::StringTokenizer(3) π
okay bestie, welcome to the ost::StringTokenizer page from the Library Functions Manual β yes it's a C++ thing, yes it's from GNU CommonC++, yes we're gonna make it cute. stay with me π«Ά
β¨ NAME β¨
ost::StringTokenizer β splits delimited string into tokens. that's it, that's the job. queen behavior π
πΈ SYNOPSIS πΈ
#include <tokenizer.h>
π Classes π
class iteratorβ the input forward iterator for tokens. she walks the walk πclass NoSuchElementExceptionβ the exception thrown if someone tried to read beyond the end of the tokens. caught you slippin' π
π¦ Public Member Functions π¦
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 iteratorvoid 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 Public Attributes β
static const char *const SPACEβ a delimiter string containing all usual whitespace delimiters.
π Friends π
class StringTokenizer::iterator
π Detailed Description π
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. literally just a little pointer-coded bestie pointing at your tokens π«΅
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. (bestie. do not. the vibes will be rancid π)
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. (yes, all of them. she's a group chat not a DM π₯)
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 π
Henner Zeller H.Zeller@acm.org
π License π
\n LGPL
π§ Constructor & Destructor Documentation π§
π ost::StringTokenizer::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.
Parameters
strβ String to be split up. This string will not be modified by this StringTokenizer, but you may as well not modfiy this string while tokenizing is in process, which may lead to undefined behaviour. (note: the original says "modfiy". we respect the typo. no cap π)delimβ String containing the characters which should be regarded as delimiters.skipAllDelimβ OPTIONAL.true, if subsequent delimiters should be skipped at once orfalse, if empty tokens should be returned for two delimiters with no other text inbetween. The first behaviour may be desirable for whitespace skipping, the second for input with delimited entry e.g./etc/passwdlike files or CSV input. NOTE, that'true'here resembles the ANSI-Cstrtok(char *s,char *d)behaviour. DEFAULT =falsetrimβ OPTIONAL.true, if the tokens returned should be trimmed, so that they don't have any whitespaces at the beginning or end. Whitespaces are any of the characters defined inStringTokenizer::SPACE. Ifdelimitself isStringTokenizer::SPACE, this will result in a behaviour withskipAllDelim = true. DEFAULT =false
π ost::StringTokenizer::StringTokenizer (const char * s)
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);
πΈ Member Function Documentation πΈ
β¨ iterator ost::StringTokenizer::begin () const [inline]
returns the begin iterator
β¨ iterator ost::StringTokenizer::begin (const char * d) [inline]
returns a begin iterator with an alternate set of delimiters.
β¨ const iterator& ost::StringTokenizer::end (void) const [inline]
the iterator marking the end.
β¨ void ost::StringTokenizer::setDelimiters (const char * d) [inline]
changes the set of delimiters used in subsequent iterations.
π¦ Friends And Related Function Documentation π¦
friend class StringTokenizer::iterator [friend]
π Member Data Documentation π
π« const char* const ost::StringTokenizer::SPACE [static]
a delimiter string containing all usual whitespace delimiters. These are space, tab, newline, carriage return, formfeed and vertical tab. (see isspace() manpage).
π Author π
Generated automatically by Doxygen for GNU CommonC++ from the source code.
and that's the whole page bestie!! π this lil' gem is brought to you by GNU CommonC++, dated Sun Dec 27 2020, and the manpage title she came in under was ost::StringTokenizer(3) from the Library Functions Manual. slay, tokenize responsibly, and remember: don't store pointers to your tokens, copy them. mwah π
πβ¨
π¦ where this page comes from
- ubuntu jammy: libcommoncpp2-doc 1.8.1-10
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms