]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/strutl.cc
add APT::String::Strip(), start cleanup of ProcessDpkgStatusLine
[apt.git] / apt-pkg / contrib / strutl.cc
index 77e48962c086ec7be659736b1fd6e9d62e303994..9f794927d0e3280f1a3f9e5072b28c0c896d533a 100644 (file)
 
 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);
+}
+}
+}
+                                                                       /*}}}*/
 // UTF8ToCodeset - Convert some UTF-8 string for some codeset          /*{{{*/
 // ---------------------------------------------------------------------
 /* This is handy to use before display some information for enduser  */