discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Localized string compare


From: Eric Wasylishen
Subject: Re: Localized string compare
Date: Fri, 2 Mar 2012 00:03:12 -0700

Hey, I just committed a first attempt at implementing this with ICU 
(compare:options:range:locale:, and I also did 
rangeOfString:options:range:locale: since it was similar.) 

It needs more careful testing, but this little toy example works:

        NSLocale *german = [[NSLocale alloc] initWithLocaleIdentifier: 
@"de_DE"];
        
        int i = (int)[@"ß" compare: @"ss" options: NSCaseInsensitiveSearch 
range: NSMakeRange(0, 1) locale: german];
        NSLog(@"s-set vs 'ss': %d", i); // returns 0 - the strings are equal

        NSRange r = [@"ßab" rangeOfString: @"sS" options: 
NSCaseInsensitiveSearch range: NSMakeRange(0, 3)
                                                           locale: german];
        
        NSLog(@"range: %@", NSStringFromRange(r)); // returns {0, 1}

-Eric

On 2012-03-01, at 2:50 PM, David Chisnall wrote:

> On OS X and FreeBSD trunk, we have strcoll_l which can do this.  I think it's 
> in POSIX2008, so it should appear elsewhere soon.  Otherwise, yes, ICU is the 
> way to go.
> 
> David
> 
> On 1 Mar 2012, at 21:47, Jens Alfke wrote:
> 
>> Looks like localized string comparison (-[NSString localizedCompare:], et 
>> al) isn’t implemented — NSString.m has various reminder comments like 
>> “Should implement full POSIX.2 collate” and "FIXME: This does only a normal 
>> compare, ignoring locale”.
>> 
>> Unfortunately Unicode collation is kind of important for my app, as its data 
>> interchange format relies on a single cross-platform sort order for strings.
>> 
>> How hard would it be to implement this? Does it mean calling into the scary 
>> innards of ICU, or is there some higher level collation API available?
>> 
>> —Jens_______________________________________________
>> Discuss-gnustep mailing list
>> Discuss-gnustep@gnu.org
>> https://lists.gnu.org/mailman/listinfo/discuss-gnustep
> 
> 
> -- Sent from my PDP-11
> 
> 
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep




reply via email to

[Prev in Thread] Current Thread [Next in Thread]