4

Given the code:

NSString *a    = @"a";
NSString *clef = @"";
UTF32Char utf32char = 0x1D11E;  // 

NSCharacterSet *cs1 = [NSCharacterSet characterSetWithCharactersInString:@""];
NSCharacterSet *cs2 = [NSCharacterSet characterSetWithCharactersInString:@"a"];
NSCharacterSet *cs3 = [NSCharacterSet characterSetWithCharactersInString:@"a"];
NSMutableCharacterSet *mcs1 = [NSMutableCharacterSet characterSetWithCharactersInString:@""];
NSMutableCharacterSet *mcs2 = [NSMutableCharacterSet characterSetWithCharactersInString:@""];

[mcs1 addCharactersInString:clef];
[mcs1 addCharactersInString:a];

[mcs2 addCharactersInString:a];
[mcs2 addCharactersInString:clef];

NSLog(@"cs1 - %@",  [cs1  longCharacterIsMember:utf32char] ? @"YES" : @"NO");
NSLog(@"cs2 - %@",  [cs2  longCharacterIsMember:utf32char] ? @"YES" : @"NO");
NSLog(@"cs3 - %@",  [cs3  longCharacterIsMember:utf32char] ? @"YES" : @"NO");

NSLog(@"mcs1 - %@", [mcs1 longCharacterIsMember:utf32char] ? @"YES" : @"NO");
NSLog(@"mcs2 - %@", [mcs2 longCharacterIsMember:utf32char] ? @"YES" : @"NO");

I get the following output:

cs1 - YES
cs2 - NO
cs3 - NO
mcs1 - YES
mcs2 - NO
  1. Why does only cs1 seem to work correctly (for the immutable character sets)?
  2. Why is the order important for the mutable character sets?

Is this a bug? A known problem with ObjC's internal UTF-16 representation (is that even still the case?)?

Orangenhain
  • 3,724
  • 1
  • 22
  • 16
  • btw, if you add `utf32char = 0x61; // a` before the membership tests, the results will be "YES" for everything but `cs1`. – Orangenhain Apr 10 '14 at 23:20

0 Answers0