]> git.llucax.com Git - z.facultad/75.29/susanita.git/commitdiff
Corregir el strip()
authorAlberto Bertogli <albertogli@telpin.com.ar>
Thu, 3 Nov 2005 05:29:18 +0000 (05:29 +0000)
committerAlberto Bertogli <albertogli@telpin.com.ar>
Thu, 3 Nov 2005 05:29:18 +0000 (05:29 +0000)
src/parser.cpp

index f15b9c7ee2bec68585456461c7029755c3b3085c..2d8ae559d6337b2ae8702d0745e7f4479405e85c 100644 (file)
@@ -16,11 +16,20 @@ Parser(Susanita& s):
 namespace
 {
        /// Saca espacios de una palabra
-       std::string strip(std::string s)
-       {
-               std::istringstream ss(s);
-               ss >> s;
-               return s;
+       std::string strip(std::string s) {
+               std::string ws = " \t\n";
+               int first = s.find_first_not_of(ws);
+               int last = s.find_last_not_of(ws);
+
+               if (first == -1) {
+                       int pos_first = s.find_first_of(ws);
+                       if (pos_first == -1) {
+                               return s;
+                       } else {
+                               return std::string("");
+                       }
+               }
+               return s.substr(first,last-first+1).c_str();
        }
 
        /// Devuelve palabra hasta el caracter indicado