case insensitive comparison of "i" and "I" fails with Dutch locale settings on OSX Yosemite

103 views Asked by At

I'm trying to do a case insensitive comparison of "i" and "I" on OSX Yosemite using Dutch locale settings. But OSX keeps telling me that the strings are different. If I change the locale to "en_US" the comparison works as expected.

The following xcode "command line tool" project can be used to demonstrate the problem.

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {

        CFStringRef s1 = (__bridge CFStringRef)@"i";
        CFStringRef s2 = (__bridge CFStringRef)@"I";

        CFLocaleRef tmpLocale = CFLocaleCreate(nil, (__bridge CFStringRef)@"nl_NL"); // or // CFLocaleRef tmpLocale = CFLocaleCopyCurrent(); on a Dutch OSX

        int result = CFStringCompareWithOptionsAndLocale(s1, s2, CFRangeMake(0, 1), kCFCompareCaseInsensitive, tmpLocale);

        CFRelease(tmpLocale);

        NSLog(@"%d", result);

        if (result == 0) NSLog(@"same"); else NSLog(@"different");

    }
    return 0;
}

Is this a bug in OSX or is there anything I am missing?

1

There are 1 answers

0
Sean On BEST ANSWER

Dutch does need some special logic when sorting (collating) and transforming the digraph 'ij' (becomes 'IJ' when capitalized / title cased). These two letters are often considered as a single letter (or ligature even) to Dutch dictionaries and their language preservation body.

What you're experiencing does indeed smell like a legitimate bug in CoreFoundation. After further testing, any string that begins with an 'i' causes the CFStringCompareWithOptionsAndLocale to return either 1 or -1, never 0.