1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-25 19:01:52 +02:00

Clean up trim() utility function

This commit is contained in:
Maarten ter Huurne 2014-07-19 02:32:30 +02:00
parent 5e31df9e0f
commit 9b93eabcc5
2 changed files with 5 additions and 8 deletions

View File

@ -40,15 +40,10 @@ bool case_less::operator()(const string &left, const string &right) const {
return strcasecmp(left.c_str(), right.c_str()) < 0;
}
// General tool to strip spaces from both ends:
string trim(const string& s) {
if(s.length() == 0)
return s;
int b = s.find_first_not_of(" \t\r");
int e = s.find_last_not_of(" \t\r");
if(b == -1) // No non-spaces
return "";
return string(s, b, e - b + 1);
auto b = s.find_first_not_of(" \t\r");
auto e = s.find_last_not_of(" \t\r");
return b == string::npos ? "" : string(s, b, e + 1 - b);
}
bool fileExists(const string &file) {

View File

@ -35,7 +35,9 @@ public:
bool operator()(const std::string &left, const std::string &right) const;
};
/** Returns the string with whitespace stripped from both ends. */
std::string trim(const std::string& s);
std::string strreplace(std::string orig, const std::string &search, const std::string &replace);
std::string cmdclean(std::string cmdline);