util: Move TrimString(...). Introduce default pattern (trims whitespace). Add NODISCARD.

This commit is contained in:
practicalswift
2019-12-11 09:55:00 +00:00
parent 22d9bae36f
commit 32e27129ff
2 changed files with 11 additions and 10 deletions

View File

@@ -11,6 +11,16 @@
#include <string>
#include <vector>
NODISCARD inline std::string TrimString(const std::string& str, const std::string& pattern = " \f\n\r\t\v")
{
std::string::size_type front = str.find_first_not_of(pattern);
if (front == std::string::npos) {
return std::string();
}
std::string::size_type end = str.find_last_not_of(pattern);
return str.substr(front, end - front + 1);
}
/**
* Join a list of items
*