mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 18:58:25 +02:00
Clean up trim() utility function
This commit is contained in:
parent
5e31df9e0f
commit
9b93eabcc5
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user