Date:2014-07-19 02:32:30 (3 months 13 days ago)
Author:Maarten ter Huurne
Commit:9b93eabcc5b8ebe5bcda37414e2740345d55b91c
Message:Clean up trim() utility function

Files: src/utilities.cpp (1 diff)
src/utilities.h (1 diff)

Change Details

src/utilities.cpp
4040    return strcasecmp(left.c_str(), right.c_str()) < 0;
4141}
4242
43// General tool to strip spaces from both ends:
4443string trim(const string& s) {
45  if(s.length() == 0)
46    return s;
47  int b = s.find_first_not_of(" \t\r");
48  int e = s.find_last_not_of(" \t\r");
49  if(b == -1) // No non-spaces
50    return "";
51  return string(s, b, e - b + 1);
44  auto b = s.find_first_not_of(" \t\r");
45  auto e = s.find_last_not_of(" \t\r");
46  return b == string::npos ? "" : string(s, b, e + 1 - b);
5247}
5348
5449bool fileExists(const string &file) {
src/utilities.h
3535    bool operator()(const std::string &left, const std::string &right) const;
3636};
3737
38/** Returns the string with whitespace stripped from both ends. */
3839std::string trim(const std::string& s);
40
3941std::string strreplace(std::string orig, const std::string &search, const std::string &replace);
4042std::string cmdclean(std::string cmdline);
4143

Archive Download the corresponding diff file



interactive