radarlib
1.4.6
|
String manipulation functions. More...
Functions | |
void | split (const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ") |
Splits a string into substrings using the chacatars of a given string as tokens separators. More... | |
void | split (const std::string &str, std::string &first, std::string &second, const char separator= ',') |
Splits a string into two parts, using the given separator. More... | |
std::string & | trimleft (std::string &str) |
removes all spaces to the left of a string More... | |
std::string | trimleft (const std::string &str) |
removes all spaces to the left of a string, building a new string More... | |
std::string & | trimright (std::string &str) |
removes all spaces to the right of a string More... | |
std::string | trimright (const std::string &str) |
removes all spaces to the right of a string, building a new string More... | |
std::string & | trim (std::string &str) |
remove all space to the left and the right of a string More... | |
std::string | trim (const std::string &str) |
removes all spaces to the left and the right of a string, building a new string More... | |
std::string | toString (bool val) |
Convert a boolean value to its string rapresentation (0/1). More... | |
std::string | toString (int val) |
Convert a int value to its string rapresentation . More... | |
std::string | toString (long val) |
Convert a long value to its string rapresentation. More... | |
std::string | toString (float val) |
Convert a float value to its string rapresentation. More... | |
std::string | toString (double val) |
Convert a double value to its string rapresentation. More... | |
std::string | toString (size_t val) |
Convert a size_t value to its string rapresentation. More... | |
std::string | toString (const std::vector< bool > &val, const char *sep=",") |
Convert a std::vector of boolean values to a string. More... | |
std::string | toString (const std::vector< int > &val, const char *sep=",") |
Convert a std::vector of int values to a string. More... | |
std::string | toString (const std::vector< long > &val, const char *sep=",") |
Convert a std::vector of long values to a string. More... | |
std::string | toString (const std::vector< float > &val, const char *sep=",") |
Convert a std::vector of float values to a string. More... | |
std::string | toString (const std::vector< double > &val, const char *sep=",") |
Convert a std::vector of double values to a string. More... | |
bool | isInt (const std::string &str) |
Check if the string is a number. More... | |
bool | parseBool (const std::string &str) |
Parse a std::string to a boolean value. More... | |
int | parseInt (const std::string &str) |
Parse a std::string to an int value. More... | |
float | parseFloat (const std::string &str) |
Parse a std::string to a float value. More... | |
double | parseDouble (const std::string &str) |
Parse a std::string to a double value. More... | |
void | parseSeq (const std::string &str, std::vector< bool > &val, const char *sep=",", const bool allowEmptyStr=true) |
Parse a string sequence of boolean values to a std::vector. More... | |
void | parseSeq (const std::string &str, std::vector< int > &val, const char *sep=",", const bool allowEmptyStr=true) |
Parse a string sequence of integer values to a std::vector. More... | |
void | parseSeq (const std::string &str, std::vector< double > &val, const char *sep=",", const bool allowEmptyStr=true) |
Parse a string sequence of double values to a std::vector. More... | |
void | parseSeq (const std::string &str, std::vector< std::string > &val, const char *sep=",", const bool allowEmptyStr=true) |
Parse a string sequence of string tokens to a std::vector. More... | |
template<class T > | |
std::string | toString (const T &value) |
Convert a value to its string rapresentation. More... | |
template<class T > | |
std::string | toString (const std::vector< T > &val, const char *sep=",") |
Convert a std::vector to a string. More... | |
template<class T > | |
std::string | toString (const std::vector< std::pair< T, T > > value, const char *sep=",") |
Convert a std::vector of pair values to a string. More... | |
template<class T > | |
static T | parse (const std::string &str, const std::string &typestr) |
Parse a std::string to a given type value. More... | |
String manipulation functions.
RADAR_API void Radar::stringutils::split | ( | const std::string & | str, |
std::vector< std::string > & | tokens, | ||
const std::string & | delimiters = " " |
||
) |
Splits a string into substrings using the chacatars of a given string as tokens separators.
str | the string to split |
tokens | a reference to a std::vector of string that will store a copy of each token |
delimiters | the string that specifiy the tokens separators, if the parameter is omitted only the space charater will be used |
RADAR_API void Radar::stringutils::split | ( | const std::string & | str, |
std::string & | first, | ||
std::string & | second, | ||
const char | separator = ',' |
||
) |
Splits a string into two parts, using the given separator.
str | the string to split |
first | a reference to a string where the first part will be copied |
second | a reference to a string where the second part will be copied |
separator | the character separator to use. If the parameter is omited the comma character will be used |
RADAR_API std::string & Radar::stringutils::trimleft | ( | std::string & | str | ) |
removes all spaces to the left of a string
str | the refernce to the string to trim |
RADAR_API std::string Radar::stringutils::trimleft | ( | const std::string & | str | ) |
removes all spaces to the left of a string, building a new string
str | a constant refernce to string to analize |
RADAR_API std::string & Radar::stringutils::trimright | ( | std::string & | str | ) |
removes all spaces to the right of a string
str | the refernce to the string to trim |
RADAR_API std::string Radar::stringutils::trimright | ( | const std::string & | str | ) |
removes all spaces to the right of a string, building a new string
str | a constant refernce to string to analize |
RADAR_API std::string & Radar::stringutils::trim | ( | std::string & | str | ) |
remove all space to the left and the right of a string
str | the refernce to the string to trim |
RADAR_API std::string Radar::stringutils::trim | ( | const std::string & | str | ) |
removes all spaces to the left and the right of a string, building a new string
str | a constant refernce to string to analize |
RADAR_API std::string Radar::stringutils::toString | ( | bool | val | ) |
Convert a boolean value to its string rapresentation (0/1).
val | the value to convert |
RADAR_API std::string Radar::stringutils::toString | ( | int | val | ) |
Convert a int value to its string rapresentation .
val | the value to convert |
RADAR_API std::string Radar::stringutils::toString | ( | long | val | ) |
Convert a long value to its string rapresentation.
val | the value to convert |
RADAR_API std::string Radar::stringutils::toString | ( | float | val | ) |
Convert a float value to its string rapresentation.
val | the value to convert |
RADAR_API std::string Radar::stringutils::toString | ( | double | val | ) |
Convert a double value to its string rapresentation.
val | the value to convert |
RADAR_API std::string Radar::stringutils::toString | ( | size_t | val | ) |
Convert a size_t value to its string rapresentation.
val | the value to convert |
RADAR_API std::string Radar::stringutils::toString | ( | const std::vector< bool > & | val, |
const char * | sep = "," |
||
) |
Convert a std::vector of boolean values to a string.
Convert a std::vector of booleans values to a string, converting the vector values to their string representation. If no separator is specified, the comma character will be used
val | a reference to the vector to convert |
sep | the value separator to use |
RADAR_API std::string Radar::stringutils::toString | ( | const std::vector< int > & | val, |
const char * | sep = "," |
||
) |
Convert a std::vector of int values to a string.
Convert a std::vector of int values to a string, converting the vector values to their string representation. If no separator is specified, the comma character will be used
val | a reference to the vector to convert |
sep | the value separator to use |
RADAR_API std::string Radar::stringutils::toString | ( | const std::vector< long > & | val, |
const char * | sep = "," |
||
) |
Convert a std::vector of long values to a string.
Convert a std::vector of long values to a string, converting the vector values to their string representation. If no separator is specified, the comma character will be used
val | a reference to the vector to convert |
sep | the value separator to use |
RADAR_API std::string Radar::stringutils::toString | ( | const std::vector< float > & | val, |
const char * | sep = "," |
||
) |
Convert a std::vector of float values to a string.
Convert a std::vector of float values to a string, converting the vector values to their string representation. If no separator is specified, the comma character will be used
val | a reference to the vector to convert |
sep | the value separator to use |
RADAR_API std::string Radar::stringutils::toString | ( | const std::vector< double > & | val, |
const char * | sep = "," |
||
) |
Convert a std::vector of double values to a string.
Convert a std::vector of double values to a string, converting the vector values to their string representation. If no separator is specified, the comma character will be used
val | a reference to the vector to convert |
sep | the value separator to use |
RADAR_API bool Radar::stringutils::isInt | ( | const std::string & | str | ) |
Check if the string is a number.
str | the string to check |
RADAR_API bool Radar::stringutils::parseBool | ( | const std::string & | str | ) |
Parse a std::string to a boolean value.
str | a reference to the strint to convert |
std::invalid_argument | if the string cannot be converted to the given type |
RADAR_API int Radar::stringutils::parseInt | ( | const std::string & | str | ) |
Parse a std::string to an int value.
str | a reference to the strint to convert |
std::invalid_argument | if the string cannot be converted to the given type |
RADAR_API float Radar::stringutils::parseFloat | ( | const std::string & | str | ) |
Parse a std::string to a float value.
str | a reference to the strint to convert |
std::invalid_argument | if the string cannot be converted to the given type |
RADAR_API double Radar::stringutils::parseDouble | ( | const std::string & | str | ) |
Parse a std::string to a double value.
str | a reference to the strint to convert |
std::invalid_argument | if the string cannot be converted to the given type |
RADAR_API void Radar::stringutils::parseSeq | ( | const std::string & | str, |
std::vector< bool > & | val, | ||
const char * | sep = "," , |
||
const bool | allowEmptyStr = true |
||
) |
Parse a string sequence of boolean values to a std::vector.
Parse a string sequence of boolean values to a std::vector.
Values will be extracted using the ginve character as separator
str | the string containing the sequence of values |
val | the vector that will store the parsed values |
sep | the separato used to split the string |
allowEmptyStr | if false empty strings will cause an exception |
std::invalid_argument | if the string cannot be splitted or converted |
RADAR_API void Radar::stringutils::parseSeq | ( | const std::string & | str, |
std::vector< int > & | val, | ||
const char * | sep = "," , |
||
const bool | allowEmptyStr = true |
||
) |
Parse a string sequence of integer values to a std::vector.
Parse a string sequence of integer values to a std::vector.
Values will be extracted using the ginve character as separator
str | the string containing the sequence of values |
val | the vector that will store the parsed values |
sep | the separato used to split the string |
allowEmptyStr | if false empty strings will cause an exception |
std::invalid_argument | if the string cannot be splitted or converted |
RADAR_API void Radar::stringutils::parseSeq | ( | const std::string & | str, |
std::vector< double > & | val, | ||
const char * | sep = "," , |
||
const bool | allowEmptyStr = true |
||
) |
Parse a string sequence of double values to a std::vector.
Parse a string sequence of double values to a std::vector.
Values will be extracted using the ginve character as separator
str | the string containing the sequence of values |
val | the vector that will store the parsed values |
sep | the separato used to split the string |
allowEmptyStr | if false empty strings will cause an exception |
std::invalid_argument | if the string cannot be splitted or converted |
RADAR_API void Radar::stringutils::parseSeq | ( | const std::string & | str, |
std::vector< std::string > & | val, | ||
const char * | sep = "," , |
||
const bool | allowEmptyStr = true |
||
) |
Parse a string sequence of string tokens to a std::vector.
Parse a string sequence of string tokens to a std::vector.
Values will be extracted using the ginve character as separator
str | the string containing the sequence of values |
val | the vector that will store the parsed values |
sep | the separato used to split the string |
allowEmptyStr | if false empty strings will cause an exception |
std::invalid_argument | if the string cannot be splitted or converted |
std::string Radar::stringutils::toString | ( | const T & | value | ) |
Convert a value to its string rapresentation.
Convert a value to its string rapresentation. The type of the value to convert must be of the same type specified with the template syntax
value | the value to convert |
std::string Radar::stringutils::toString | ( | const std::vector< T > & | val, |
const char * | sep = "," |
||
) |
Convert a std::vector to a string.
Convert a std::vector to a string, converting the vector values to their string representation. If no separator is specified, the comma character will be used The vector elements type is specified using template syntax
val | a reference to the vector to convert |
sep | the value separator to use |
std::string Radar::stringutils::toString | ( | const std::vector< std::pair< T, T > > | value, |
const char * | sep = "," |
||
) |
Convert a std::vector of pair values to a string.
Convert a std::vector of pair values to a string, converting the pair values to their string representation.
If no separator is specified, the comma character will be used
value | a reference to the vector to convert |
sep | the value separator to use |
|
static |
Parse a std::string to a given type value.
Convert a std::string to a given type value If no separator is specified, the comma character will be used
str | a reference to the strint to convert |
typestr | the name of the result type (used for exception message if an error occurs) |
std::invalid_argument | if the string cannot be converted to the given type |