Boost logo

Boost Users :

From: Pavol Droba (droba_at_[hidden])
Date: 2005-07-16 11:46:33


Hi,

On Sat, Jul 16, 2005 at 03:02:11PM +0200, Matthias Kaeppler wrote:
> Hi,
>
> I am aware that string_algo has an if_iequal functor. Is there also an
> equivalent for a less-than comparison? I have to compare strings
> ignoring the case but taking locales into account.
> Right now I'm calling boost::algorithm::to_lower on two copies of the
> original strings. I'm not so sure if this is very efficient when I'm
> comparing thousands of strings.
>
> Here's the functor as it is now:
>
> struct FileLessNameA
> : std::binary_function<const File&,const File&,bool> {
> bool operator() (const File& lhs, const File& rhs) const {
> std::string path1( lhs.get_name().c_str() );
> std::string path2( rhs.get_name().c_str() );
> boost::algorithm::to_lower( path1 );
> boost::algorithm::to_lower( path2 );
> return path1 < path2;
> }
> };
>

There is no such a function in string_algo lib. But you can easily use
std::lexicographical_compare.

There is a variant with a custom comparison predicate. For that you can use
boost::is_iequal defined in boost/algorithm/string/compare.hpp.

Best regards,
Pavol.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net