EventAnalysis
1.0.0
|
A namespace with some utility methods for strings. More...
Typedefs | |
using | Tokens = std::vector< std::string > |
Functions | |
Tokens | Tokenize (const std::string &str, char delimiter=' ') |
Extracts words from a string. More... | |
std::string | Trim (const std::string &str) |
Trims a string. More... | |
bool | IsInteger (const std::string &str) |
Checks if a string is an a integer. More... | |
bool | IsReal (const std::string &str) |
Checks if a string is a real number. More... | |
bool | ToBoolean (const std::string &str) |
Converts a string into a boolean value. More... | |
bool | IsGlobExpression (const std::string &str) |
Check if the given string is a glob expression. More... | |
std::string | RegexFromGlob (const std::string &str) |
Build a regex starting from a glob expression. More... | |
A namespace with some utility methods for strings.
using EA::StringUtils::Tokens = typedef std::vector<std::string> |
bool EA::StringUtils::IsGlobExpression | ( | const std::string & | str | ) |
Check if the given string is a glob expression.
A glob expression is recognized by looking at '*' or '?' characters in the string. Other glob wildcards are ignored.
str | The string to be checked. |
bool EA::StringUtils::IsInteger | ( | const std::string & | str | ) |
Checks if a string is an a integer.
Checks if the trimmed input string represents an integer value, possibly with sign.
str | The input string. |
bool EA::StringUtils::IsReal | ( | const std::string & | str | ) |
Checks if a string is a real number.
Checks if the trimmed input string represents a real value, possibly with sign, in the standard notation (e.g. 10.2, not 1.02e1). Note that integer numbers e.g. 10 are real numbers so they are recognized as real by this function.
str | The input string. |
std::string EA::StringUtils::RegexFromGlob | ( | const std::string & | str | ) |
Build a regex starting from a glob expression.
This function manages only the '*' and '?' glob wildcards.
str | The glob expression. |
bool EA::StringUtils::ToBoolean | ( | const std::string & | str | ) |
Converts a string into a boolean value.
Valid values for the string are : "0", "1", "true" (any case), "false" (any case). Non-trimmed strings (e.g. "true ", " 1 ") are considered invalid.
str | The input string. |
std::invalid_argument | if the string does not represent a boolean value |
StringUtils::Tokens EA::StringUtils::Tokenize | ( | const std::string & | str, |
char | delimiter = ' ' |
||
) |
Extracts words from a string.
The string must be a sequence of words separated by a given delimiter. A string portion enclosed within double quotation marks will be treated as a single word (the quotation marks will be removed). If the closing double quotation is missing then a std::runtime_error is thrown.
str | The string to tokenize. |
delimiter | A vector used to return the words in the string. |
std::runtime_error | if a non-terminated double-quotation-enclosed sequence is found. |
std::string EA::StringUtils::Trim | ( | const std::string & | str | ) |
Trims a string.
Removes all leading and trailing invisible characters (spaces, tabs etc.).
str | The input string. |