• 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: Sorting unicode strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting unicode strings


  • Subject: Re: Sorting unicode strings
  • From: Ali Ozer <email@hidden>
  • Date: Thu, 30 Dec 2004 18:21:55 -0800

NSLiteralSearch is usually not a good idea for user-visible strings, as it will end up ignoring some Unicode variations which should normally compare the same. For instance:

  unichar u[] = {0x0d6};   // O-umlaut as one character
  NSString *s = [NSString stringWithCharacters:u length:1];
  unichar u2[] = {'O', 0x0308};   // O-umlaut as two characters
  NSString *s2 = [NSString stringWithCharacters:u2 length:2];

NSLog(@"%d", [s compare:s2]); // This compares same
NSLog(@"%d", [s compare:s2 options:NSLiteralSearch]); // But this doesn't


Ali




Begin forwarded message:

From: Ricky Sharp <email@hidden>
Date: December 30, 2004 4:14:59 PST
To: Kevin Ballard <email@hidden>
Cc: Cocoa-Dev Development <email@hidden>
Subject: Re: Sorting unicode strings


On Wednesday, December 29, 2004, at 11:38PM, Kevin Ballard <email@hidden> wrote:


I've never really been clear on this. The docs for NSLiteralSearch say
it does a byte-for-byte comparison of strings. Is there any reason to
use this aside from a speed boost? Is there any situation in which you
would definitely *not* want to use this?

I'm not sure of this myself as this is the first time I'm sorting unicode strings.


But after brief testing, calling compare: or compare:options: with NSLiteralSearch appear to do the same exact thing. This makes sense as the docs mention:

"Search and comparison are currently performed as if the NSLiteralSearch option were specified. As the Unicode encoding becomes more widely used, and the need for more flexible comparison increases, the default behavior will be changed accordingly."

So the final code I'll use will just be compare:. That way, I'm ensured to always use the default behavior.

--
Rick Sharp
Instant Interactive(tm)

_______________________________________________ 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: 
 >Sorting unicode strings (From: Ricky Sharp <email@hidden>)
 >Re: Sorting unicode strings (From: Kevin Ballard <email@hidden>)
 >Re: Sorting unicode strings (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Embedding a custom view within NSScrollView
  • Next by Date: Displaying Swedish Characters?
  • Previous by thread: Re: Sorting unicode strings
  • Next by thread: RE: Sorting unicode strings
  • Index(es):
    • Date
    • Thread