*/␊ |
␊ |
/**␊ |
* trim the space chars on the right of a sring␊ |
* trim the space (or any substring) chars on the right of a sring␊ |
*/␊ |
inline std::string trim_right(const std::string &source , const std::string& t = " ")␊ |
inline std::string trim_right(const std::string &source , const std::string& substr = " ")␊ |
{␊ |
␉std::string str = source;␊ |
␉return str.erase( str.find_last_not_of(t) + 1);␊ |
␉return str.erase( str.find_last_not_of(substr) + 1);␊ |
}␊ |
␊ |
/**␊ |
* trim the space chars on the left of a sring␊ |
* trim the space chars (or any substring) on the left of a sring␊ |
*/␊ |
inline std::string trim_left( const std::string& source, const std::string& t = " ")␊ |
inline std::string trim_left( const std::string& source, const std::string& substr = " ")␊ |
{␊ |
␉std::string str = source;␊ |
␉return str.erase(0 , source.find_first_not_of(t) );␊ |
␉return str.erase(0 , source.find_first_not_of(substr) );␊ |
}␊ |
␊ |
/**␊ |
* trim the space chars on the left and the right of a string␊ |
* trim the space chars (or any substring) on the left and the right of a string␊ |
*/␊ |
inline std::string trim(const std::string& source, const std::string& t = " ")␊ |
inline std::string trim(const std::string& source, const std::string& substr = " ")␊ |
{␊ |
␉std::string str = source;␊ |
␉return trim_left( trim_right( str , t) , t );␊ |
␉return trim_left( trim_right( source , substr) , substr );␊ |
} ␊ |