activemq-cpp-3.6.0
decaf::util::StringTokenizer Class Reference

Class that allows for parsing of string based on Tokens. More...

#include <src/main/decaf/util/StringTokenizer.h>

Public Member Functions

 StringTokenizer (const std::string &str, const std::string &delim=" \t\n\r\f", bool returnDelims=false)
 Constructs a string tokenizer for the specified string.
virtual ~StringTokenizer ()
virtual int countTokens () const
 Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.
virtual bool hasMoreTokens () const
 Tests if there are more tokens available from this tokenizer's string.
virtual std::string nextToken ()
 Returns the next token from this string tokenizer.
virtual std::string nextToken (const std::string &delim)
 Returns the next token in this string tokenizer's string.
virtual unsigned int toArray (std::vector< std::string > &array)
 Grab all remaining tokens in the String and return them in the vector that is passed in by reference.
virtual void reset (const std::string &str="", const std::string &delim="", bool returnDelims=false)
 Resets the Tokenizer's position in the String to the Beginning calls to countToken and nextToken now start back at the beginning.

Detailed Description

Class that allows for parsing of string based on Tokens.

Since
1.0

Constructor & Destructor Documentation

decaf::util::StringTokenizer::StringTokenizer ( const std::string &  str,
const std::string &  delim = " \t\n\r\f",
bool  returnDelims = false 
)

Constructs a string tokenizer for the specified string.

All characters in the delim argument are the delimiters for separating tokens.

If the returnDelims flag is true, then the delimiter characters are also returned as tokens. Each delimiter is returned as a string of length one. If the flag is false, the delimiter characters are skipped and only serve as separators between tokens.

Note that if delim is "", this constructor does not throw an exception. However, trying to invoke other methods on the resulting StringTokenizer may result in an Exception.

Parameters
str- The string to tokenize
delim- String containing the delimiters
returnDelims- boolean indicating if the delimiters are returned as tokens
virtual decaf::util::StringTokenizer::~StringTokenizer ( )
virtual

Member Function Documentation

virtual int decaf::util::StringTokenizer::countTokens ( ) const
virtual

Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.

The current position is not advanced.

Returns
Count of remaining tokens
virtual bool decaf::util::StringTokenizer::hasMoreTokens ( ) const
virtual

Tests if there are more tokens available from this tokenizer's string.

Returns
true if there are more tokens remaining
virtual std::string decaf::util::StringTokenizer::nextToken ( )
virtual

Returns the next token from this string tokenizer.

Returns
string value of next token
Exceptions
NoSuchElementExceptionif there are no more tokens in this string.
virtual std::string decaf::util::StringTokenizer::nextToken ( const std::string &  delim)
virtual

Returns the next token in this string tokenizer's string.

First, the set of characters considered to be delimiters by this StringTokenizer object is changed to be the characters in the string delim. Then the next token in the string after the current position is returned. The current position is advanced beyond the recognized token. The new delimiter set remains the default after this call.

Parameters
delimThe string containing the new set of delimiters.
Returns
next string in the token list
Exceptions
NoSuchElementExceptionif there are no more tokens in this string.
virtual void decaf::util::StringTokenizer::reset ( const std::string &  str = "",
const std::string &  delim = "",
bool  returnDelims = false 
)
virtual

Resets the Tokenizer's position in the String to the Beginning calls to countToken and nextToken now start back at the beginning.

This allows this object to be reused, the caller need not create a new instance every time a String needs tokenizing.

  • If set the string param will reset the string that this Tokenizer is working on. If set to "" no change is made.
  • If set the delim param will reset the string that this Tokenizer is using to tokenizer the string. If set to "", no change is made
  • If set the return Delims will set if this Tokenizer will return delimiters as tokens. Defaults to false.
Parameters
strNew String to tokenize or "", defaults to ""
delimNew Delimiter String to use or "", defaults to ""
returnDelimsShould the Tokenizer return delimiters as Tokens, default false
virtual unsigned int decaf::util::StringTokenizer::toArray ( std::vector< std::string > &  array)
virtual

Grab all remaining tokens in the String and return them in the vector that is passed in by reference.

Parameters
array- vector to place token strings in
Returns
number of string placed into the vector

The documentation for this class was generated from the following file: