From: Alberto Bertogli Date: Thu, 3 Nov 2005 05:29:18 +0000 (+0000) Subject: Corregir el strip() X-Git-Tag: darcs_import~51 X-Git-Url: https://git.llucax.com/z.facultad/75.29/susanita.git/commitdiff_plain/f975b96aef520fcd47d8b571f6e1f19d0779870c?hp=a86e26ae42584c979262de7f6ddefa815ac7c625 Corregir el strip() --- diff --git a/src/parser.cpp b/src/parser.cpp index f15b9c7..2d8ae55 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -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