给定代码:
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");
我得到以下输出:
cs1 - YES
cs2 - NO
cs3 - NO
mcs1 - YES
mcs2 - NO
- 为什么只有 cs1 似乎可以正常工作(对于不可变字符集)?
- 为什么顺序对于可变字符集很重要?
这是一个错误吗?ObjC 的内部 UTF-16 表示存在一个已知问题(现在仍然如此吗?)?