24std::string&
trim(std::string* str,
const char* drop) {
25 std::string::size_type pos = str->find_last_not_of(drop);
26 if (pos != std::string::npos) {
28 pos = str->find_first_not_of(drop);
29 if (pos != std::string::npos) str->erase(0, pos);
32 str->erase(str->begin(), str->end());
37std::string&
trim(std::string* str,
const std::string& drop) {
38 std::string::size_type pos = str->find_last_not_of(drop);
39 if (pos != std::string::npos) {
41 pos = str->find_first_not_of(drop);
42 if (pos != std::string::npos) str->erase(0, pos);
45 str->erase(str->begin(), str->end());
54std::string
trim(
const std::string& str,
const char* drop) {
56 std::string::size_type pos1 = str.find_first_not_of(drop);
57 if (pos1 == std::string::npos)
return std::string();
60 std::string out = str.substr(pos1, std::string::npos);
63 std::string::size_type pos2 = out.find_last_not_of(drop);
64 if (pos2 != std::string::npos)
70std::string
trim(
const std::string& str,
71 const std::string& drop) {
73 out.reserve(str.size());
76 std::string::const_iterator it = str.begin();
77 while (it != str.end() && drop.find(*it) != std::string::npos)
81 out.resize(str.end() - it);
82 std::copy(it, str.end(), out.begin());
85 std::string::size_type pos = out.find_last_not_of(drop);
86 if (pos != std::string::npos)