Re: inconsistent behavior of NSString's localizedCaseInsensitiveCompare
Re: inconsistent behavior of NSString's localizedCaseInsensitiveCompare
- Subject: Re: inconsistent behavior of NSString's localizedCaseInsensitiveCompare
- From: Quincey Morris <email@hidden>
- Date: Sat, 05 May 2012 22:06:42 -0700
On May 5, 2012, at 19:45 , Jens Alfke wrote:
> On May 5, 2012, at 4:51 PM, Kyle Sluder wrote:
>
>> If I understand Quincey correctly, that's exactly what he's saying: the semantics of localizedCaseInsensitiveCompare: might be such that it is not appropriate for such algorithms.
>
> But that doesn’t make sense, because the main purpose of -compare: methods is to use for sorting, for methods like -sortUsingSelector: or for NSSortDescriptor. And using -localizedCaseInsensitiveCompare: is pretty common for lists displayed in a UI. So I maintain this is a bug.
It could easily be a bug.
However, even in pure ASCII strings, 'localizedCaseInsensitiveCompare:' doesn't support sorting via (say) a binary search. Strings such as "a" and "A" are *equal* according to this method. Binary search doesn't work if sorted elements are equal according to the comparison function.
The kind of comparison function needed for what we think of as case-insensitive-sorted lists of strings needs a function where case isn't ignored, but rather where the collating sequence puts case-insensitive-equal strings next to each other with a definite order.
The NSString option that apparently causes this is 'NSForcedOrderingSearch', but the documentation doesn't really say whether this option is assumed by 'localizedCaseInsensitiveCompare:' or not. (The documentation for 'caseInsensitiveCompare:' implies not.)
When we throw a 'ß' into the mix, things just get harder. My understanding is that, in German, the uppercase of "laßt" is "LASST". So, "laßt" and "lasst" should be equal according to 'localizedCaseInsensitiveCompare:' in a German locale, shouldn't they? But they aren't equal on my US-locale system 10.7.3 -- I tried it.
So even if we get the right compare options, 'localizedCaseInsensitiveCompare:' may not be viable for strings *not* in the language of the current locale.
Note that all of this is prior even to the question of transitivity. If 'localizedCaseInsensitiveCompare:' isn't suitable for sorting lists of mixed-language strings "case-insensitively"**, then delving into its transitivity problems seems beside the point.
** Incidentally, it's no help arguing that "laßt" in this case isn't German but just some string with an ess-zett. Case-(in)sensitivity is, in general, a language-dependent concept.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden