radarlib  1.4.4
Radar::stringutils Namespace Reference

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) throw (std::invalid_argument)
 Parse a std::string to a boolean value. More...
 
int parseInt (const std::string &str) throw (std::invalid_argument)
 Parse a std::string to an int value. More...
 
float parseFloat (const std::string &str) throw (std::invalid_argument)
 Parse a std::string to a float value. More...
 
double parseDouble (const std::string &str) throw (std::invalid_argument)
 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...
 

Detailed Description

String manipulation functions.

Function Documentation

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.

Parameters
strthe string to split
tokensa reference to a std::vector of string that will store a copy of each token
delimitersthe 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.

Parameters
strthe string to split
firsta reference to a string where the first part will be copied
seconda reference to a string where the second part will be copied
separatorthe 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

Parameters
strthe refernce to the string to trim
Returns
the reference used for str param
RADAR_API std::string Radar::stringutils::trimleft ( const std::string &  str)

removes all spaces to the left of a string, building a new string

Parameters
stra constant refernce to string to analize
Returns
the new string
RADAR_API std::string & Radar::stringutils::trimright ( std::string &  str)

removes all spaces to the right of a string

Parameters
strthe refernce to the string to trim
Returns
the reference used for str param
RADAR_API std::string Radar::stringutils::trimright ( const std::string &  str)

removes all spaces to the right of a string, building a new string

Parameters
stra constant refernce to string to analize
Returns
the new string
RADAR_API std::string & Radar::stringutils::trim ( std::string &  str)

remove all space to the left and the right of a string

Parameters
strthe refernce to the string to trim
Returns
the reference used for str param
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

Parameters
stra constant refernce to string to analize
Returns
the new string
RADAR_API std::string Radar::stringutils::toString ( bool  val)

Convert a boolean value to its string rapresentation (0/1).

Parameters
valthe value to convert
Returns
the string representation of value
Examples:
image-visitor.cpp, and pvolsplitter.cpp.
RADAR_API std::string Radar::stringutils::toString ( int  val)

Convert a int value to its string rapresentation .

Parameters
valthe value to convert
Returns
the string representation of value
RADAR_API std::string Radar::stringutils::toString ( long  val)

Convert a long value to its string rapresentation.

Parameters
valthe value to convert
Returns
the string representation of value
RADAR_API std::string Radar::stringutils::toString ( float  val)

Convert a float value to its string rapresentation.

Parameters
valthe value to convert
Returns
the string representation of value
RADAR_API std::string Radar::stringutils::toString ( double  val)

Convert a double value to its string rapresentation.

Parameters
valthe value to convert
Returns
the string representation of value
RADAR_API std::string Radar::stringutils::toString ( size_t  val)

Convert a size_t value to its string rapresentation.

Parameters
valthe value to convert
Returns
the string representation of value
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

Parameters
vala reference to the vector to convert
septhe value separator to use
Returns
the new string
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

Parameters
vala reference to the vector to convert
septhe value separator to use
Returns
the new string
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

Parameters
vala reference to the vector to convert
septhe value separator to use
Returns
the new string
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

Parameters
vala reference to the vector to convert
septhe value separator to use
Returns
the new string
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

Parameters
vala reference to the vector to convert
septhe value separator to use
Returns
the new string
RADAR_API bool Radar::stringutils::isInt ( const std::string &  str)

Check if the string is a number.

Parameters
strthe string to check
Returns
True if the string can be converted to a integer or floating point value, false otherwise
RADAR_API bool Radar::stringutils::parseBool ( const std::string &  str)
throw (std::invalid_argument
)

Parse a std::string to a boolean value.

Parameters
stra reference to the strint to convert
Returns
the parsed value
Exceptions
std::invalid_argumentif the string cannot be converted to the given type
RADAR_API int Radar::stringutils::parseInt ( const std::string &  str)
throw (std::invalid_argument
)

Parse a std::string to an int value.

Parameters
stra reference to the strint to convert
Returns
the parsed value
Exceptions
std::invalid_argumentif the string cannot be converted to the given type
RADAR_API float Radar::stringutils::parseFloat ( const std::string &  str)
throw (std::invalid_argument
)

Parse a std::string to a float value.

Parameters
stra reference to the strint to convert
Returns
the parsed value
Exceptions
std::invalid_argumentif the string cannot be converted to the given type
RADAR_API double Radar::stringutils::parseDouble ( const std::string &  str)
throw (std::invalid_argument
)

Parse a std::string to a double value.

Parameters
stra reference to the strint to convert
Returns
the parsed value
Exceptions
std::invalid_argumentif 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

Parameters
strthe string containing the sequence of values
valthe vector that will store the parsed values
septhe separato used to split the string
allowEmptyStrif false empty strings will cause an exception
Exceptions
std::invalid_argumentif 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

Parameters
strthe string containing the sequence of values
valthe vector that will store the parsed values
septhe separato used to split the string
allowEmptyStrif false empty strings will cause an exception
Exceptions
std::invalid_argumentif 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

Parameters
strthe string containing the sequence of values
valthe vector that will store the parsed values
septhe separato used to split the string
allowEmptyStrif false empty strings will cause an exception
Exceptions
std::invalid_argumentif 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

Parameters
strthe string containing the sequence of values
valthe vector that will store the parsed values
septhe separato used to split the string
allowEmptyStrif false empty strings will cause an exception
Exceptions
std::invalid_argumentif the string cannot be splitted or converted
template<class T >
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

Parameters
valuethe value to convert
Returns
the string representation of value
Examples:
create_odim_object.cpp.
template<class T >
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

Parameters
vala reference to the vector to convert
septhe value separator to use
Returns
the new string
template<class T >
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

Parameters
valuea reference to the vector to convert
septhe value separator to use
Returns
the new string
template<class T >
static T Radar::stringutils::parse ( const std::string &  str,
const std::string &  typestr 
)
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

Parameters
stra reference to the strint to convert
typestrthe name of the result type (used for exception message if an error occurs)
Returns
the parsed value
Exceptions
std::invalid_argumentif the string cannot be converted to the given type