From f975b96aef520fcd47d8b571f6e1f19d0779870c Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Thu, 3 Nov 2005 05:29:18 +0000 Subject: [PATCH] Corregir el strip() --- src/parser.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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 -- 2.43.0