Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- inline std::basic_string<T>& trim_right(std::basic_string<T>& source)
- {
- std::locale loc;
- // Supprime les caractères entre le dernier caractère non espace et la fin de la chaine
- source.erase(std::find_if(source.rbegin(), source.rend(), [&loc] (char c){ return !isspace(c, loc); }).base(), source.end());
- return source;
- }
- template<typename T>
- inline std::basic_string<T>& trim_left(std::basic_string<T>& source)
- {
- std::locale loc;
- // Supprime les caractères entre le dabut de la chaine et le premier caractère non espace
- source.erase(source.begin(), std::find_if(source.begin(), source.end(), [&loc] (char c){ return !isspace(c, loc); }));
- return source;
- }
- template<typename T>
- inline std::basic_string<T>& trim_both(std::basic_string<T>& source)
- {
- trim_right(source);
- trim_left(source);
- return source;
- }
Add Comment
Please, Sign In to add comment