• 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: Ignore accents when comparing strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ignore accents when comparing strings


  • Subject: Re: Ignore accents when comparing strings
  • From: j o a r <email@hidden>
  • Date: Thu, 6 Jan 2005 10:47:01 +0100


On 2005-01-06, at 02.21, Brendan Younger wrote:

I think (mostly) everyone here is missing the point. The accented "a", also known as U+0030, does not compare before the word "arc" as it should (especially since it compares equal to a non-accented "a"). The original poster had a legitimate problem which had nothing to do with file encodings but that seems to be all everyone is talking about. The question is, is it a bug that the accented "a" compares after the word "arc" or is it a misunderstanding?

Posting flawed sample code is not the best way to get the discussion on the right track...


Here is improved sample code for the problem:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	NSString *mot1 = @"ar";
	NSString *mot2 = @"a";
	unichar u[] = {0x00E0};
	NSString *mot3 = [NSString stringWithCharacters: u length: 1];

NSMutableArray *sim = [NSMutableArray arrayWithObjects: mot1, mot2, mot3, nil];

NSLog([sim componentsJoinedByString: @", "]);
[sim sortUsingSelector: @selector(compare:)];
NSLog([sim componentsJoinedByString: @", "]);

[pool release];

return 0;
}


The problem can probably be found in this comment from the documentation:

"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."

I thought that "localizedCompare:" might fare better, but it doesn't seem to be the case.

j o a r

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: 
 >Ignore accents when comparing strings (From: "Simon alias Trax" <email@hidden>)
 >Re: Ignore accents when comparing strings (From: Andrew Farmer <email@hidden>)
 >Re: Ignore accents when comparing strings (From: Kevin Ballard <email@hidden>)
 >Re: Ignore accents when comparing strings (From: Brendan Younger <email@hidden>)

  • Prev by Date: Re: Newbie: debugging raised exception
  • Next by Date: Re: Why does this not compile?
  • Previous by thread: Re: Ignore accents when comparing strings
  • Next by thread: Re: Ignore accents when comparing strings
  • Index(es):
    • Date
    • Thread