Boost logo

Boost :

Subject: [boost] [string_algo] ilexicographical_compare()/is_iless() bug?
From: Dmitry Vinogradov (sraider_at_[hidden])
Date: 2012-04-08 09:46:19


I want to share a problem using ilexicographical_compare().

I think that ilexicographical_compare() must compare two strings in
"alphabetical" order, the order letters appear in alphabet.
But ilexicographical_compare() uses is_iless() to compare letters.
And such comparison looks like:
std::toupper<T1>(Arg1,m_Loc)<std::toupper<T2>(Arg2,m_Loc);

So, in fact, letters are compared depending on their position in a
charset. It's not always match the alphabet order. Examples are Cyrillic
letters "Io" and "i" (Unicode 0451 and 0456).

I think the right solution is to compare like this:
T1 Ch1 = std::toupper<T1>(Arg1,m_Loc);
T2 Ch2 = std::toupper<T2>(Arg2,m_Loc);
return std::use_facet< std::collate<typename CharType> >
(m_Loc).compare(&Ch1, &Ch1 + 1, &Ch2, &Ch2 + 1);


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk