Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
Mantid::Kernel::UserStringParser Class Reference

This class parses a given string into vector of vectors of numbers. More...

#include <UserStringParser.h>

Public Member Functions

std::vector< std::vector< unsigned int > > parse (const std::string &userString)
 parses a given string into a vector of vector of numbers More...
 

Private Member Functions

bool Contains (const std::string &input, char ch)
 This method checks the input string contains the character ch. More...
 
void convertToNumbers (const std::string &input, const std::vector< std::string > &tokens, unsigned int &start, unsigned int &end, unsigned int &step)
 converts the parsed tokens to numbers More...
 
bool isValid (const std::string &input, std::vector< std::string > &tokens)
 validates the input string More...
 
bool isValidStepSeparator (const std::string &input, const std::vector< std::string > &tokens)
 This method checks the separator preceded by the step string is valid colon ':' is valid separator for step string. More...
 
void parse (const std::string &userString, std::vector< std::vector< unsigned int > > &numbers)
 convert the string into numbers More...
 
std::vector< std::vector< unsigned int > > separateColon (const std::string &input)
 separates a given string to vector of vector of numbers using colon as the delimeter More...
 
std::vector< std::string > separateComma (const std::string &)
 separate a given string to a vector of comma separated strings More...
 
std::vector< unsigned int > separateDelimiters (const std::string &input, const std::string &delimiters)
 separate delimiter string from input string and return a vector of numbers created from the separated string More...
 
void Tokenize (const std::string &input, const std::string &delimiter, unsigned int &start, unsigned int &end, unsigned int &step)
 This method removes the separator string from the input string and converts the tokens to unisgned int. More...
 
unsigned int toUInt (const std::string &input)
 converts a string to int. More...
 

Detailed Description

This class parses a given string into vector of vectors of numbers.

For example : 60,61+62,63-66,67:70,71-75:2 This gives a vector containing 8 vectors as Vec[8] and Vec[0] is a vector containing 1 element 60 Vec[1] is a vector containing elements 61,62 Vec[2] is a vector containing elements 63,64,65,66, Vec[3] is a vector containing element 67,Vec[4] is a vector containing element 68, Vec[5] is a vector containing element 69,Vec[6] is a vector containing element 70 , vec[7] is a vector containing element 71,73,75

Author
Sofia Antony, Rutherford Appleton Laboratory
Date
27/01/2011

Definition at line 36 of file UserStringParser.h.

Member Function Documentation

◆ Contains()

bool Mantid::Kernel::UserStringParser::Contains ( const std::string &  input,
char  ch 
)
private

This method checks the input string contains the character ch.

This method checks input string contains character ch.

Parameters
input- the input string
ch- character ch to search
Returns
- true if the string contains character ch.

Definition at line 76 of file UserStringParser.cpp.

Referenced by parse().

◆ convertToNumbers()

void Mantid::Kernel::UserStringParser::convertToNumbers ( const std::string &  input,
const std::vector< std::string > &  tokens,
unsigned int &  start,
unsigned int &  end,
unsigned int &  step 
)
private

converts the parsed tokens to numbers

This method checks the input string is valid format.

Parameters
input- input string to validate
tokens- vector containing separated values.
start- start number
end- end number
step- step used for incrementing

Definition at line 179 of file UserStringParser.cpp.

References toUInt().

Referenced by Tokenize().

◆ isValid()

bool Mantid::Kernel::UserStringParser::isValid ( const std::string &  input,
std::vector< std::string > &  tokens 
)
private

validates the input string

◆ isValidStepSeparator()

bool Mantid::Kernel::UserStringParser::isValidStepSeparator ( const std::string &  input,
const std::vector< std::string > &  tokens 
)
private

This method checks the separator preceded by the step string is valid colon ':' is valid separator for step string.

Parameters
input- input string to validate
tokens- vector containing separated values.
Returns
true if the input is valid

Definition at line 157 of file UserStringParser.cpp.

References index.

Referenced by Tokenize().

◆ parse() [1/2]

std::vector< std::vector< unsigned int > > Mantid::Kernel::UserStringParser::parse ( const std::string &  userString)

parses a given string into a vector of vector of numbers

This method parses a given string of numbers and returns a vector of vector of numbers.

Parameters
userString- the string to parse
Returns
a vector containing vectors of numbers.

Definition at line 21 of file UserStringParser.cpp.

References parse(), and separateComma().

Referenced by parse().

◆ parse() [2/2]

void Mantid::Kernel::UserStringParser::parse ( const std::string &  userString,
std::vector< std::vector< unsigned int > > &  numbers 
)
private

convert the string into numbers

This method parses a given string of numbers and returns a vector of vector of numbers.

Parameters
userString- the input string to parse
numbers-a vector containing vectors of numbers.

Definition at line 45 of file UserStringParser.cpp.

References Contains(), separateColon(), separateDelimiters(), toUInt(), and value.

◆ separateColon()

std::vector< std::vector< unsigned int > > Mantid::Kernel::UserStringParser::separateColon ( const std::string &  input)
private

separates a given string to vector of vector of numbers using colon as the delimeter

This method parses a given string of numbers into colon separated tokens.

Parameters
input- the string to parse
Returns
a vector of vector containing colon separated tokens.

Definition at line 95 of file UserStringParser.cpp.

References Tokenize().

Referenced by parse().

◆ separateComma()

std::vector< std::string > Mantid::Kernel::UserStringParser::separateComma ( const std::string &  input)
private

separate a given string to a vector of comma separated strings

This method parses a given string of numbers into comma separated tokens.

Parameters
input- the string to parse
Returns
a vector containing comma separated tokens.

Definition at line 85 of file UserStringParser.cpp.

References Mantid::Kernel::StringTokenizer::asVector(), and Mantid::Kernel::StringTokenizer::TOK_TRIM.

Referenced by parse().

◆ separateDelimiters()

std::vector< unsigned int > Mantid::Kernel::UserStringParser::separateDelimiters ( const std::string &  input,
const std::string &  delimiters 
)
private

separate delimiter string from input string and return a vector of numbers created from the separated string

This method parses a given string of numbers into tokens using the separator character symbol.

Parameters
input- the string to parse
delimiters- the string used as separator
Returns
a vector of vector containing colon separated tokens.

Definition at line 114 of file UserStringParser.cpp.

References Tokenize().

Referenced by parse().

◆ Tokenize()

void Mantid::Kernel::UserStringParser::Tokenize ( const std::string &  input,
const std::string &  delimiter,
unsigned int &  start,
unsigned int &  end,
unsigned int &  step 
)
private

This method removes the separator string from the input string and converts the tokens to unisgned int.

This method parses a given string of numbers into tokens based on the given separator returns numbers corresponding to separated tokens and separators if any.

Parameters
input- the string to parse
delimiter- character to separate
start- a number corresponding to the string before delimiter
end- a number corresponding to the string after delimiter
step- number used to increment from the start num generate the series of numbers .

Definition at line 138 of file UserStringParser.cpp.

References Mantid::Kernel::StringTokenizer::asVector(), convertToNumbers(), and isValidStepSeparator().

Referenced by separateColon(), and separateDelimiters().

◆ toUInt()

unsigned int Mantid::Kernel::UserStringParser::toUInt ( const std::string &  input)
private

converts a string to int.

This method converts a string to unsigned int.

Parameters
input- the string to parse
Returns
an unsigned number equivalent of the input

Definition at line 209 of file UserStringParser.cpp.

Referenced by convertToNumbers(), and parse().


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