size_t end = s.find_last_not_of(" \t\n");
return s.substr(start, end-start+1);
}
+
+bool Endswith(const std::string &s, const std::string &end)
+{
+ if (end.size() > s.size())
+ return false;
+ return (s.substr(s.size() - end.size(), s.size()) == end);
+}
+
}
}
/*}}}*/
namespace APT {
namespace String {
std::string Strip(const std::string &s);
+ bool Endswith(const std::string &s, const std::string &ending);
};
};
std::string sourceslist;
if (CmdL.FileList[1] != NULL)
- sourceslist = _config->FindDir("Dir::Etc::sourceparts") + CmdL.FileList[1] + ".list";
- else
+ {
+ sourceslist = _config->FindDir("Dir::Etc::sourceparts") + CmdL.FileList[1];
+ if (!APT::String::Endswith(sourceslist, ".list"))
+ sourceslist += ".list";
+ } else {
sourceslist = _config->FindFile("Dir::Etc::sourcelist");
-
+ }
HashString before;
if (FileExists(sourceslist))
before.FromFile(sourceslist);
strprintf(outs, _("Failed to parse %s. Edit again? "),
sourceslist.c_str());
std::cout << outs;
+ // FIXME: should we add a "restore previous" option here?
res = !YnPrompt(true);
}
_error->RevertToStack();
result = StringSplit(input, "");
equals(result.size(), 0);
+ // endswith
+ bool b;
+ input = "abcd";
+ b = APT::String::Endswith(input, "d");
+ equals(b, true);
+
+ b = APT::String::Endswith(input, "cd");
+ equals(b, true);
+
+ b = APT::String::Endswith(input, "abcd");
+ equals(b, true);
+
+ b = APT::String::Endswith(input, "x");
+ equals(b, false);
+
+ b = APT::String::Endswith(input, "abcndefg");
+ equals(b, false);
+
return 0;
}