Friday, June 14, 2013

NSCharacterSet hasMemberInPlane example in Objective C (iOS).


NSCharacterSet hasMemberInPlane

Returns a Boolean value that indicates whether the receiver has at least one member in a given character plane.

- (BOOL)hasMemberInPlane:(uint8_t)thePlane

Parameters of [NSCharacterSet hasMemberInPlane]
thePlane
A character plane.

Return Value
YES if the receiver has at least one member in thePlane, otherwise NO.

Discussion of [NSCharacterSet hasMemberInPlane]
This method makes it easier to find the plane containing the members of the current character set. The Basic Multilingual Plane is plane 0.

NSCharacterSet hasMemberInPlane 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 hasMemberInPlane example article.