Hello everyone,
I'm using NSString's localizedCaseInsensitiveCompare to maintain a data
structure sorted by some keys, which are strings that will be displayed to the
end-user. For this question it's enough to think of an array of sorted strings,
on which binary searches are run. The problem is that the localized string
comparison method produces return values that are inconsistent.
For example, consider the following sorted list of strings:
"aaa" < "laso" < "lasso" < "zzz"
I would expect that any new string I want to insert into this list would
compare so that it has just one point of insertion. But this is not true if I
test "laßt", where the German Eszett "ß" character sounds/behaves like "ss":
(gdb) p (NSComparisonResult)[@"laßt"
localizedCaseInsensitiveCompare:@"aaa"]
$16 = 1
(gdb) p (NSComparisonResult)[@"laßt"
localizedCaseInsensitiveCompare:@"laso"]
$17 = -1
(gdb) p (NSComparisonResult)[@"laßt"
localizedCaseInsensitiveCompare:@"lasso"]
$18 = 1
(gdb) p (NSComparisonResult)[@"laßt"
localizedCaseInsensitiveCompare:@"zzz"]
$19 = -1
So, when using a binary search, I get different answers depending on the other
strings in the list!
I've tried CFStringCompareWithOptionsAndLocale with some flags
(kCFCompareCaseInsensitive | kCFCompareLocalized | kCFCompareForcedOrdering),
but it has the same quirk.
This seems nutty to me. Surely a single string should have a single proper sort
ordering. Are my intuitions misplaced, or is this a bug?
Thanks for any thoughts on this matter,
~Martin
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]