discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Localized string compare


From: Stefan Bidi
Subject: Re: Localized string compare
Date: Fri, 2 Mar 2012 20:31:11 -0600

Eric, I was taking a look at some of what you did (maybe use some of that in corebase) and I think you're not using the "dist" variable.  According to the Apple documentation:
Prior to Mac OS X v10.5, the locale argument was an instance of NSDictionary. On Mac OS X v10.5 and later, if you pass an instance of NSDictionary the current locale is used instead.

So we need to be ready to handle an NSDictionary.  Should be easy enough to just check the class before continuing on.  I would add the check myself but I'm out of town and can't do anything.

Stef

On Fri, Mar 2, 2012 at 4:08 PM, Eric Wasylishen <ewasylishen@gmail.com> wrote:
Hi Stef,
Sorry, my bad, I didn't think of checking corebase first; in any case we should be able to share code. I implemented anchored forward/backward search, and just added a simple test suite in base/Tests/base/NSString/locale.m.

Eric


On 2012-03-02, at 7:02 AM, Stefan Bidi wrote:

I just wanted to mention that this has been implemented in corebase for some time.  Should be able to use the code there if needed.  I still need to really clean it up as I was kind of in a rush at the time, but the concept is there.  That should go for any of the localized/normalization/etc string stuff and anything else requiring ICU support.

On Fri, Mar 2, 2012 at 1:03 AM, Eric Wasylishen <ewasylishen@gmail.com> wrote:
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


_______________________________________________
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]