]> git.llucax.com Git - z.facultad/75.29/susanita.git/blobdiff - src/parser.cpp
Corregir el strip()
[z.facultad/75.29/susanita.git] / 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