Orxonox
0.0.5 Codename: Arcturus
|
A class that splits a string into multiple tokens using different options. More...
#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/util/SubString.h>
Public Member Functions | |
SubString () | |
Default constructor. More... | |
SubString (const SubString &other)=default | |
Copy constructor. More... | |
SubString (SubString &&other)=default | |
Move constructor. More... | |
SubString (const std::string &line, const std::string &delimiters=SubString::WhiteSpaces, const std::string &delimiterNeighbours="", bool bAllowEmptyEntries=false, char escapeChar='\\', bool bRemoveEscapeChar=true, char safemodeChar= '"', bool bRemoveSafemodeChar = true, char openparenthesisChar = '{', char closeparenthesisChar = '}', bool bRemoveParenthesisChars = true, char commentChar = '\0') | |
Splits a string into multiple tokens. More... | |
SubString (size_t argc, const char **argv) | |
Creates a SubString from a count and values set. More... | |
SubString (const SubString &other, size_t begin, size_t length=std::string::npos) | |
creates a new SubString based on a subset of an other SubString. More... | |
~SubString () | |
Destructor. More... | |
SubString & | append (const SubString &other) |
Appends the tokens of another SubString to this. More... | |
const std::string & | back () const |
Returns the back of the list of tokens. More... | |
bool | compare (const SubString &other, size_t length=std::string::npos) const |
Compares this SubString to another SubString and returns true if the first length values match. More... | |
void | debug () const |
Some nice debug information about this SubString. More... | |
bool | empty () const |
Returns true if the SubString is empty. More... | |
const std::string & | front () const |
Returns the front of the list of tokens. More... | |
const std::vector< std::string > & | getAllStrings () const |
Returns all tokens as std::vector. More... | |
const std::string & | getString (size_t index) const |
Returns the i'th token from the subset of strings. More... | |
bool | isInSafemode (size_t index) const |
Returns true if the token is in safemode. More... | |
std::string | join (const std::string &delimiter=" ") const |
Joins the tokens of this SubString using the given delimiter and returns a string. More... | |
SubString | operator+ (const SubString &other) const |
Concatenates the tokens of two SubStrings and returns the resulting new SubString. More... | |
SubString & | operator+= (const SubString &other) |
Appends the tokens of other to this SubString. More... | |
SubString & | operator= (const SubString &other) |
Stores the tokens of other in this SubString. More... | |
SubString & | operator= (SubString &&other)=default |
Move assignment. More... | |
bool | operator== (const SubString &other) const |
Compares this SubString to another SubString and returns true if they contain the same values. More... | |
const std::string & | operator[] (size_t index) const |
Returns the i'th token from the subset of strings. More... | |
void | pop_back () |
Removes the back of the list of tokens. More... | |
size_t | size () const |
Returns the number of tokens stored in this SubString. More... | |
size_t | split (const std::string &line, const std::string &delimiters=SubString::WhiteSpaces, const std::string &delimiterNeighbours="", bool bAllowEmptyEntries=false, char escapeChar='\\', bool bRemoveEscapeChar=true, char safemodeChar= '"', bool bRemoveSafemodeChar = true, char openparenthesisChar = '{', char closeparenthesisChar = '}', bool bRemoveParenthesisChars = true, char commentChar = '\0') |
Splits a string into multiple tokens. More... | |
SubString | subSet (size_t begin, size_t length=std::string::npos) const |
Creates a subset of this SubString. More... | |
Static Public Attributes | |
static const SubString | NullSubString = SubString() |
An empty SubString. More... | |
static const std::string | WhiteSpaces = " \n\t" |
All whitespaces (usually used as delimiters or delimiterNeighbours. More... | |
static const std::string | WhiteSpacesWithComma = " \n\t," |
All whitespaces and the comma (usually used as delimiters) More... | |
Private Types | |
enum | SPLIT_LINE_STATE { SPLIT_LINE_STATE::NORMAL, SPLIT_LINE_STATE::ESCAPE, SPLIT_LINE_STATE::SAFEMODE, SPLIT_LINE_STATE::SAFEESCAPE, SPLIT_LINE_STATE::COMMENT, SPLIT_LINE_STATE::PARENTHESES, SPLIT_LINE_STATE::PARENTHESESESCAPE } |
An enumerator for the internal state of the parser. More... | |
Static Private Member Functions | |
static SPLIT_LINE_STATE | splitLine (std::vector< std::string > &tokens, std::vector< bool > &bTokenInSafemode, const std::string &line, const std::string &delimiters=SubString::WhiteSpaces, const std::string &delimiterNeighbours="", bool bAllowEmptyEntries=false, char escapeChar= '\\', bool bRemoveEscapeChar=true, char safemodeChar= '"', bool bRemoveSafemodeChar = true, char openparenthesisChar = '{', char closeparenthesisChar = '}', bool bRemoveParenthesisChars = true, char commentChar = '\0', SPLIT_LINE_STATE start_state = SPLIT_LINE_STATE::NORMAL) |
Splits a string into multiple tokens. More... | |
Private Attributes | |
std::vector< bool > | bTokenInSafemode_ |
Saves for each token if it was in safe mode (between quotation marks or parenthesis) More... | |
std::vector< std::string > | tokens_ |
The tokens after splitting the input line. More... | |
A class that splits a string into multiple tokens using different options.
The string is split into multiple tokens using a delimiter. Different options like escape character, quotation marks, and more can be used to satisfy your needs.
See this description for an example.
|
strongprivate |
An enumerator for the internal state of the parser.
orxonox::SubString::SubString | ( | ) |
Default constructor.
|
default |
Copy constructor.
|
default |
Move constructor.
orxonox::SubString::SubString | ( | const std::string & | line, |
const std::string & | delimiters = SubString::WhiteSpaces , |
||
const std::string & | delimiterNeighbours = "" , |
||
bool | bAllowEmptyEntries = false , |
||
char | escapeChar = '\\' , |
||
bool | bRemoveEscapeChar = true , |
||
char | safemodeChar = '"' , |
||
bool | bRemoveSafemodeChar = true , |
||
char | openparenthesisChar = '{' , |
||
char | closeparenthesisChar = '}' , |
||
bool | bRemoveParenthesisChars = true , |
||
char | commentChar = '\0' |
||
) |
Splits a string into multiple tokens.
line | The line to split |
delimiters | Multiple characters at which to split the line |
delimiterNeighbours | Neighbours of the delimiters that will be erased as well (for example white-spaces) |
bAllowEmptyEntries | If true, empty tokens are also added to the SubString (if there are two delimiters without a char in between) |
escapeChar | The escape character that is used to escape safemode chars (for example if you want to use a quotation mark between two other quotation marks). |
bRemoveEscapeChar | If true, the escape char is removed from the tokens |
safemodeChar | Within these characters splitting won't happen (usually the quotation marks) |
bRemoveSafemodeChar | Removes the safemodeChar from the beginning and the ending of a token |
openparenthesisChar | The beginning of a safemode is marked with this (usually an opening brace) |
closeparenthesisChar | The ending of a safemode is marked with this (usually a closing brace) |
bRemoveParenthesisChars | Removes the parenthesis chars from the beginning and the ending of a token |
commentChar | The comment character (used to ignore the part of the line after the comment char). |
orxonox::SubString::SubString | ( | size_t | argc, |
const char ** | argv | ||
) |
Creates a SubString from a count and values set.
argc | The number of arguments |
argv | An array of pointers to the arguments |
orxonox::SubString::SubString | ( | const SubString & | other, |
size_t | begin, | ||
size_t | length = std::string::npos |
||
) |
orxonox::SubString::~SubString | ( | ) |
Destructor.
|
inline |
Returns the back of the list of tokens.
bool orxonox::SubString::compare | ( | const SubString & | other, |
size_t | length = std::string::npos |
||
) | const |
|
inline |
Returns true if the SubString is empty.
|
inline |
Returns the front of the list of tokens.
|
inline |
Returns all tokens as std::vector.
|
inline |
Returns the i'th token from the subset of strings.
index | The index of the requested token |
|
inline |
Returns true if the token is in safemode.
index | The index of the token |
std::string orxonox::SubString::join | ( | const std::string & | delimiter = " " | ) | const |
Joins the tokens of this SubString using the given delimiter and returns a string.
delimiter | This delimiter will be placed between each two tokens |
bool orxonox::SubString::operator== | ( | const SubString & | other | ) | const |
|
inline |
Returns the i'th token from the subset of strings.
index | The index of the requested token |
|
inline |
Removes the back of the list of tokens.
|
inline |
Returns the number of tokens stored in this SubString.
size_t orxonox::SubString::split | ( | const std::string & | line, |
const std::string & | delimiters = SubString::WhiteSpaces , |
||
const std::string & | delimiterNeighbours = "" , |
||
bool | bAllowEmptyEntries = false , |
||
char | escapeChar = '\\' , |
||
bool | bRemoveEscapeChar = true , |
||
char | safemodeChar = '"' , |
||
bool | bRemoveSafemodeChar = true , |
||
char | openparenthesisChar = '{' , |
||
char | closeparenthesisChar = '}' , |
||
bool | bRemoveParenthesisChars = true , |
||
char | commentChar = '\0' |
||
) |
Splits a string into multiple tokens.
line | The line to split |
delimiters | Multiple characters at which to split the line |
delimiterNeighbours | Neighbours of the delimiters that will be erased as well (for example white-spaces) |
bAllowEmptyEntries | If true, empty tokens are also added to the SubString (if there are two delimiters without a char in between) |
escapeChar | The escape character that is used to escape safemode chars (for example if you want to use a quotation mark between two other quotation marks). |
bRemoveEscapeChar | If true, the escape char is removed from the tokens |
safemodeChar | Within these characters splitting won't happen (usually the quotation marks) |
bRemoveSafemodeChar | Removes the safemodeChar from the beginning and the ending of a token |
openparenthesisChar | The beginning of a safemode is marked with this (usually an opening brace) |
closeparenthesisChar | The ending of a safemode is marked with this (usually a closing brace) |
bRemoveParenthesisChars | Removes the parenthesis chars from the beginning and the ending of a token |
commentChar | The comment character (used to ignore the part of the line after the comment char). |
|
staticprivate |
Splits a string into multiple tokens.
line | The line to split |
delimiters | Multiple characters at which to split the line |
delimiterNeighbours | Neighbours of the delimiters that will be erased as well (for example white-spaces) |
bAllowEmptyEntries | If true, empty tokens are also added to the SubString (if there are two delimiters without a char in between) |
escapeChar | The escape character that is used to escape safemode chars (for example if you want to use a quotation mark between two other quotation marks). |
bRemoveEscapeChar | If true, the escape char is removed from the tokens |
safemodeChar | Within these characters splitting won't happen (usually the quotation marks) |
bRemoveSafemodeChar | Removes the safemodeChar from the beginning and the ending of a token |
openparenthesisChar | The beginning of a safemode is marked with this (usually an opening brace) |
closeparenthesisChar | The ending of a safemode is marked with this (usually a closing brace) |
bRemoveParenthesisChars | Removes the parenthesis chars from the beginning and the ending of a token |
commentChar | The comment character (used to ignore the part of the line after the comment char). |
tokens | The array, where the splitted strings will be stored in |
bTokenInSafemode | A vector wich stores for each character of the string if it is in safemode or not |
start_state | The internal state of the parser |
This is the actual splitting algorithm from Clemens Wacha. Supports delimiters, escape characters, ignores special characters between safemodeChar and between commentChar and line end "\n".
Extended by Orxonox to support parenthesis as additional safe-mode.
SubString orxonox::SubString::subSet | ( | size_t | begin, |
size_t | length = std::string::npos |
||
) | const |
Creates a subset of this SubString.
begin | The beginning of the subset |
length | The length of the subset |
The subset ranges from the token with index begin and contains length elements.
This function is added for your convenience, and does the same as SubString::SubString(const SubString& other, size_t begin, size_t length)
|
private |
Saves for each token if it was in safe mode (between quotation marks or parenthesis)
|
private |
The tokens after splitting the input line.
|
static |
All whitespaces (usually used as delimiters or delimiterNeighbours.
|
static |
All whitespaces and the comma (usually used as delimiters)