Re: Not-equal string searching
On Feb 9, 11:39 pm, "DavidW" <n...@email.provided> wrote:
Is the function below the simplest way to produce an iterator to the next
non-space in a string? (Or the upper-bound iterator if none is found).
Searching for a sequence is overkill and inefficient IMO.
#include <string>
#include <algorithm>
#include <functional>
std::string::iterator find_not_space(std::string &s)
{
char chSpace = ' ';
return std::search(s.begin(), s.end(), &chSpace , &chSpace+1,
std::not_equal_to<char>());
}
I'm not sure I understand. If all you're looking for is the
next non-space, std::find_if should work using the standard
functional objects, e.g.:
std::find_if(
begin, end,
std::bind2nd( std::not_equal_to< char >( ' ' ) ) ) ;
Generally speaking, however, this isn't a good idea, since it
doesn't consider things like '\t' as spaces. I usually use
functional object wrappers for ctype<>::is(), with the
appropriate mask.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34