Friday, June 14, 2013

NSCharacterSet longCharacterIsMember example in Objective C (iOS).


NSCharacterSet longCharacterIsMember

Returns a Boolean value that indicates whether a given long character is a member of the receiver.

- (BOOL)longCharacterIsMember:(UTF32Char)theLongChar

Parameters of [NSCharacterSet longCharacterIsMember]
theLongChar
A UTF32 character.

Return Value
YES if theLongChar is in the receiver, otherwise NO.

Discussion of [NSCharacterSet longCharacterIsMember]
This method supports the specification of 32-bit characters.

NSCharacterSet longCharacterIsMember example.
NSCharacterSet *charset = [NSCharacterSet uppercaseLetterCharacterSet];
NSMutableArray *array = [NSMutableArray array];
for (int plane = 0; plane <= 16; plane++) {
    if ([charset hasMemberInPlane:plane]) {
        UTF32Char c;
        for (c = plane << 16; c < (plane+1) << 16; c++) {
            if ([charset longCharacterIsMember:c]) {
                UTF32Char c1 = OSSwapHostToLittleInt32(c); // To make it byte-order safe
                NSString *s = [[NSString alloc] initWithBytes:&c1 length:4 encoding:NSUTF32LittleEndianStringEncoding];
                [array addObject:s];
            }
        }
    }
}

End of NSCharacterSet longCharacterIsMember example article.