• 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
Re: -[NSString localizedCompare:] - example of semantic difference with compare?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -[NSString localizedCompare:] - example of semantic difference with compare?


  • Subject: Re: -[NSString localizedCompare:] - example of semantic difference with compare?
  • From: Ricky Sharp <email@hidden>
  • Date: Fri, 24 Mar 2006 17:56:09 -0600


On Mar 24, 2006, at 2:29 PM, Deborah Goldsmith wrote:

Hmmm. There doesn't appear to be a way to do this with the NSString API. You can do it with CFStringCompareWithOptions:

enum CFStringCompareFlags {
   kCFCompareCaseInsensitive = 1,
   kCFCompareBackwards = 4,
   kCFCompareAnchored = 8,
   kCFCompareNonliteral = 16,
   kCFCompareLocalized = 32,
   kCFCompareNumerically = 64
};

Of course, you can pass an NSString to CFStringCompareWithOptions.

This works well, thanks!

The new code (which lives as a category on NSString):

CFComparisonResult theCFResult = CFStringCompareWithOptions ((CFStringRef) self,
(CFStringRef) anItemName, CFRangeMake (0, CFStringGetLength ((CFStringRef) self)),
kCFCompareCaseInsensitive | kCFCompareLocalized | kCFCompareNumerically);


Now I get beautiful output for my English and Hawaiian test runs:

English
-------
A hui hou
'Ae
'A'ole
Maika'i no au
student
Student #1
Student #2
Student #10
Student #11
<chinese>

Hawaiian
--------
A hui hou
Maika'i no au
'Ae
'A'ole
student
Student #1
Student #2
Student #10
Student #11
<chinese>


Once again, (') is actually U+02BB and <chinese> is U+7389


You might want to file a bug against NSString to add either localizedCompare:withOptions:, or to add a NSLocalizedSearch option.

Will definitely do this tonight; I'll actually request both options just for completeness sake.



From my original e-mail when using localizedCompare: ...

On Mar 23, 2006, at 6:30 PM, Ricky Sharp wrote:
English
-------
Student #1
Student #2
Student #10
student #11

Hawaiian
--------
Student #1
Student #2
Student #10
student #11

This was a bad cut-and-paste. In both cases here, the output was this:

Student #1
Student #10
student #11
Student #2

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >-[NSString localizedCompare:] - example of semantic difference with compare? (From: Jim Correia <email@hidden>)
 >Re: -[NSString localizedCompare:] - example of semantic difference with compare? (From: Deborah Goldsmith <email@hidden>)
 >Re: -[NSString localizedCompare:] - example of semantic difference with compare? (From: Deborah Goldsmith <email@hidden>)

  • Prev by Date: Click on NSActionCell
  • Next by Date: Re: Help in Disabling a menu
  • Previous by thread: Re: -[NSString localizedCompare:] - example of semantic difference with compare?
  • Next by thread: NSString: localizedCaseInsensitiveCompare + NSNumericSearch?
  • Index(es):
    • Date
    • Thread