Use pass-by-value for peeloff (#2578)

This avoids copies when used with std::move.
This commit is contained in:
Andrew Gaul
2024-10-29 18:21:07 +09:00
committed by GitHub
parent 3b226ed672
commit b87a8400e3
3 changed files with 6 additions and 4 deletions

View File

@ -125,12 +125,14 @@ std::string trim(std::string s, const char *t /* = SPACES */)
return trim_left(trim_right(std::move(s), t), t);
}
std::string peeloff(const std::string& s)
std::string peeloff(std::string s)
{
if(s.size() < 2 || *s.cbegin() != '"' || *s.rbegin() != '"'){
return s;
}
return s.substr(1, s.size() - 2);
s.erase(s.size() - 1);
s.erase(0, 1);
return s;
}
//