String utilities

namespace str

Functions

std::string trim(std::string s)

Trim a string from both ends.

Parameters:

s – The string to trim

Returns:

a copy of s without any space before (resp. after) the first (resp. last) character

template<>
bool get_val_from_str<bool>(const std::string &str_val)

Read a boolean from a string.

Accepted values for true are “1”, “true”, “True”, and “TRUE”. Accepted values for false are “0”, “false”, “False”, and “FALSE”.

Throws:

bad_lexical_cast – if the value can not be parsed as a boolean

Returns:

the parsed boolean value

template<>
bg::date get_val_from_str<bg::date>(const std::string &str_val)

Read a value from a string (using boost::gregorian::date_from_iso_string)

Throws:

bad_lexical_cast – if the value can not be parsed

Returns:

the value

template<>
bpt::ptime get_val_from_str<bpt::ptime>(const std::string &str_val)

Read a value from a string (using boost::posix_time::from_iso_extended_string)

Throws:

bad_lexical_cast – if the value can not be parsed

Returns:

the value

template<>
bpt::time_duration get_val_from_str<bpt::time_duration>(const std::string &str_val)

Read a value from a string (using boost::posix_time::duration_from_string)

Throws:

bad_lexical_cast – if the value can not be parsed

Returns:

the value

template<typename T>
T get_val_from_str(const std::string &str_val)

Dedicated exception for cast error from (resp. to) string.

Read a value from a string (using boost::lexical_cast)

Throws:

bad_lexical_cast – if the value can not be parsed

Returns:

the value

template<>
bool get_val_from_str<bool>(const std::string &str_val)

Read a boolean from a string.

Accepted values for true are “1”, “true”, “True”, and “TRUE”. Accepted values for false are “0”, “false”, “False”, and “FALSE”.

Throws:

bad_lexical_cast – if the value can not be parsed as a boolean

Returns:

the parsed boolean value

template<>
bg::date get_val_from_str<bg::date>(const std::string &str_val)

Read a value from a string (using boost::gregorian::date_from_iso_string)

Throws:

bad_lexical_cast – if the value can not be parsed

Returns:

the value

template<>
bpt::ptime get_val_from_str<bpt::ptime>(const std::string &str_val)

Read a value from a string (using boost::posix_time::from_iso_extended_string)

Throws:

bad_lexical_cast – if the value can not be parsed

Returns:

the value

template<>
bpt::time_duration get_val_from_str<bpt::time_duration>(const std::string &str_val)

Read a value from a string (using boost::posix_time::duration_from_string)

Throws:

bad_lexical_cast – if the value can not be parsed

Returns:

the value