Mantid
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
Mantid::Kernel::StringTokenizer Class Referencefinal

#include <StringTokenizer.h>

Public Types

using ConstIterator = std::vector< std::string >::const_iterator
 
using Iterator = std::vector< std::string >::iterator
 
enum  Options { TOK_IGNORE_EMPTY = 1 , TOK_TRIM = 2 , TOK_IGNORE_FINAL_EMPTY_TOKEN = 4 }
 Specify tokenizer options. These can be combined using + or |. More...
 
using TokenVec = std::vector< std::string >
 

Public Member Functions

const TokenVecasVector ()
 Returns a vector of tokenized strings. More...
 
std::string & at (std::size_t index)
 Get a reference to the index'th token. More...
 
const std::string & at (std::size_t index) const
 Get a const reference to the index'th token. More...
 
Iterator begin ()
 Iterator referring to first element in the container. More...
 
ConstIterator begin () const
 Const iterator referring to first element in the container. More...
 
ConstIterator cbegin () const
 Const iterator referring to first element in the container. More...
 
ConstIterator cend () const
 Const iterator referring to the past-the-end element in the container. More...
 
std::size_t count () const
 Get the total number of tokens. More...
 
Iterator end ()
 Iterator referring to the past-the-end element in the container. More...
 
ConstIterator end () const
 Const iterator referring to the past-the-end element in the container. More...
 
std::string & operator[] (std::size_t index)
 Get a const reference to the index'th token. More...
 
const std::string & operator[] (std::size_t index) const
 Get a const reference to the index'th token. More...
 
std::size_t size () const noexcept
 Get the total number of tokens. More...
 
 StringTokenizer ()=default
 Constructs an object from an empty string. More...
 
 StringTokenizer (const std::string &str, const std::string &separators, unsigned options=0)
 Constructor requiring a string to tokenize and a string of separators. More...
 
 ~StringTokenizer ()=default
 Destroys the tokenizer. More...
 

Private Attributes

std::vector< std::string > m_tokens
 

Detailed Description

Definition at line 27 of file StringTokenizer.h.

Member Typedef Documentation

◆ ConstIterator

using Mantid::Kernel::StringTokenizer::ConstIterator = std::vector<std::string>::const_iterator

Definition at line 37 of file StringTokenizer.h.

◆ Iterator

using Mantid::Kernel::StringTokenizer::Iterator = std::vector<std::string>::iterator

Definition at line 36 of file StringTokenizer.h.

◆ TokenVec

using Mantid::Kernel::StringTokenizer::TokenVec = std::vector<std::string>

Definition at line 35 of file StringTokenizer.h.

Member Enumeration Documentation

◆ Options

Specify tokenizer options. These can be combined using + or |.

Enumerator
TOK_IGNORE_EMPTY 

ignore empty tokens

TOK_TRIM 

remove leading and trailing whitespace from tokens

TOK_IGNORE_FINAL_EMPTY_TOKEN 

ignore an empty token at the end of the string.

Definition at line 30 of file StringTokenizer.h.

Constructor & Destructor Documentation

◆ StringTokenizer() [1/2]

Mantid::Kernel::StringTokenizer::StringTokenizer ( )
default

Constructs an object from an empty string.

◆ StringTokenizer() [2/2]

Mantid::Kernel::StringTokenizer::StringTokenizer ( const std::string &  str,
const std::string &  separators,
unsigned  options = 0 
)

Constructor requiring a string to tokenize and a string of separators.

Parameters
strInput string to be separated into tokens.
separatorsList of characters used to separate the input string.
optionstokenizer settings. The number can be found using the StringTokenizer::Options enum
Exceptions
Throwsstd::runtime_error if options > 7.
Returns
a const reference to the index'th token.

Definition at line 106 of file StringTokenizer.cpp.

References m_tokens, std::to_string(), TOK_IGNORE_EMPTY, TOK_IGNORE_FINAL_EMPTY_TOKEN, and TOK_TRIM.

◆ ~StringTokenizer()

Mantid::Kernel::StringTokenizer::~StringTokenizer ( )
default

Destroys the tokenizer.

Member Function Documentation

◆ asVector()

const TokenVec & Mantid::Kernel::StringTokenizer::asVector ( )
inline

◆ at() [1/2]

std::string & Mantid::Kernel::StringTokenizer::at ( std::size_t  index)
inline

Get a reference to the index'th token.

Parameters
indexIndex of the requested token.
Returns
a reference to the index'th token.
Exceptions
Throwsstd::out_of_range if the index is out of range.

Definition at line 105 of file StringTokenizer.h.

References index.

◆ at() [2/2]

const std::string & Mantid::Kernel::StringTokenizer::at ( std::size_t  index) const
inline

Get a const reference to the index'th token.

Parameters
indexIndex of the requested token.
Returns
a const reference to the index'th token.
Exceptions
Throwsstd::out_of_range if the index is out of range.

Definition at line 98 of file StringTokenizer.h.

References index.

◆ begin() [1/2]

Iterator Mantid::Kernel::StringTokenizer::begin ( )
inline

◆ begin() [2/2]

ConstIterator Mantid::Kernel::StringTokenizer::begin ( ) const
inline

Const iterator referring to first element in the container.

Returns
a const iterator referring to the first element in the container.

Definition at line 59 of file StringTokenizer.h.

◆ cbegin()

ConstIterator Mantid::Kernel::StringTokenizer::cbegin ( ) const
inline

◆ cend()

ConstIterator Mantid::Kernel::StringTokenizer::cend ( ) const
inline

◆ count()

std::size_t Mantid::Kernel::StringTokenizer::count ( ) const
inline

◆ end() [1/2]

Iterator Mantid::Kernel::StringTokenizer::end ( )
inline

◆ end() [2/2]

ConstIterator Mantid::Kernel::StringTokenizer::end ( ) const
inline

Const iterator referring to the past-the-end element in the container.

Returns
a const iterator referring to the past-the-end element in the container.

Definition at line 64 of file StringTokenizer.h.

◆ operator[]() [1/2]

std::string & Mantid::Kernel::StringTokenizer::operator[] ( std::size_t  index)
inline

Get a const reference to the index'th token.

Indexing an out-of-range element won't throw, but is otherwise undefined behavior.

Parameters
indexIndex of the requested token.
Returns
a const reference to the index'th token.

Definition at line 88 of file StringTokenizer.h.

References index.

◆ operator[]() [2/2]

const std::string & Mantid::Kernel::StringTokenizer::operator[] ( std::size_t  index) const
inline

Get a const reference to the index'th token.

Indexing an out-of-range element won't throw, but is otherwise undefined behavior.

Parameters
indexIndex of the requested token.
Returns
a const reference to the index'th token.

Definition at line 81 of file StringTokenizer.h.

References index.

◆ size()

std::size_t Mantid::Kernel::StringTokenizer::size ( ) const
inlinenoexcept

Member Data Documentation

◆ m_tokens

std::vector<std::string> Mantid::Kernel::StringTokenizer::m_tokens
private

Definition at line 118 of file StringTokenizer.h.

Referenced by StringTokenizer().


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