Trims the right side of str, using pred to decide trimming (while true) cppcheck-suppress passedByValue
| 38 | // Trims the right side of str, using pred to decide trimming (while true) |
| 39 | // cppcheck-suppress passedByValue |
| 40 | inline void trim_right(std::string& str, std::function<bool(char)> pred) { |
| 41 | auto it = str.rbegin(); |
| 42 | auto it_end = str.rend(); |
| 43 | // Skip last items while predicate gives true |
| 44 | while (it != it_end && pred(*it)) { |
| 45 | ++it; // reverse iterator goes back |
| 46 | } |
| 47 | // Drop from here till the end |
| 48 | str.erase(it.base(), str.end()); |
| 49 | } |
| 50 | |
| 51 | // Trims left and right side of str, using predicate to check if the character |
| 52 | // stays (false) or will be trimmed (true) |