• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
inconsistent behavior of NSString's localizedCaseInsensitiveCompare
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

inconsistent behavior of NSString's localizedCaseInsensitiveCompare


  • Subject: inconsistent behavior of NSString's localizedCaseInsensitiveCompare
  • From: Martin Wierschin <email@hidden>
  • Date: Sat, 05 May 2012 14:07:57 -0700

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@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


  • Follow-Ups:
    • Re: inconsistent behavior of NSString's localizedCaseInsensitiveCompare
      • From: Quincey Morris <email@hidden>
    • Re: inconsistent behavior of NSString's localizedCaseInsensitiveCompare
      • From: Markus Spoettl <email@hidden>
  • Prev by Date: Re: -[NSApp orderOut:] leaves custom sheet in -orderedWindows
  • Next by Date: Re: inconsistent behavior of NSString's localizedCaseInsensitiveCompare
  • Previous by thread: Re: -[NSApp orderOut:] leaves custom sheet in -orderedWindows
  • Next by thread: Re: inconsistent behavior of NSString's localizedCaseInsensitiveCompare
  • Index(es):
    • Date
    • Thread