using namespace std;
/*}}}*/
+// Strip - Remove white space from the front and back of a string /*{{{*/
+// ---------------------------------------------------------------------
+namespace APT {
+ namespace String {
+std::string Strip(const std::string &s)
+{
+ size_t start = s.find_first_not_of(" \t\n");
+ // only whitespace
+ if (start == string::npos)
+ return "";
+ 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);
+}
+
+}
+}
+ /*}}}*/
// UTF8ToCodeset - Convert some UTF-8 string for some codeset /*{{{*/
// ---------------------------------------------------------------------
/* This is handy to use before display some information for enduser */
/*}}}*/
// StringSplit - split a string into a string vector by token /*{{{*/
// ---------------------------------------------------------------------
-/* This can be used to split a given string up from a given string token
- * into a vector of strings. A optional "maxsplit" argument can be used
- * to limit the splitting, in this case the
+/* See header for details.
*/
-vector<string> StringSplit(string const &s, std::string const &sep,
+vector<string> StringSplit(std::string const &s, std::string const &sep,
unsigned int maxsplit)
{
vector<string> split;
split.push_back(s.substr(start, pos-start));
// if maxsplit is reached, the remaining string is the last item
- if(maxsplit > 0 && split.size() >= maxsplit)
+ if(split.size() >= maxsplit)
{
split[split.size()-1] = s.substr(start);
break;