Last active
January 30, 2023 03:25
-
-
Save annidy/f58fac669f124aebead5 to your computer and use it in GitHub Desktop.
NSCharacterSet example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
[self printCharacterSet:@selector(URLFragmentAllowedCharacterSet)]; | |
[self printCharacterSet:@selector(URLPasswordAllowedCharacterSet)]; | |
[self printCharacterSet:@selector(URLPathAllowedCharacterSet)]; | |
[self printCharacterSet:@selector(URLQueryAllowedCharacterSet)]; | |
[self printCharacterSet:@selector(URLUserAllowedCharacterSet)]; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (void)printCharacterSet:(SEL)character | |
{ | |
NSCharacterSet *characterSet = [NSCharacterSet performSelector:character]; | |
NSMutableArray *mutableCharacters = [NSMutableArray array]; | |
for (NSUInteger plane = 0; plane <= 16; plane++) { | |
if ([characterSet hasMemberInPlane:plane]) { | |
for (UTF32Char character = (UTF32Char)(plane << 16); | |
character < (plane + 1) << 16; character++) | |
{ | |
if ([characterSet longCharacterIsMember:character]) { | |
UTF32Char c = OSSwapHostToLittleInt32(character); | |
NSString *characterString = [[NSString alloc] initWithBytes:&c | |
length:sizeof(UTF32Char) | |
encoding:NSUTF32LittleEndianStringEncoding]; | |
[mutableCharacters addObject:characterString]; | |
} | |
} | |
} | |
} | |
printf("%s: ", [NSStringFromSelector(character) UTF8String]); | |
for(NSString *s in mutableCharacters) { | |
printf("%s", [s UTF8String]); | |
} | |
printf("\n"); | |
// NSLog(@"%@: %@", NSStringFromSelector(character), [mutableCharacters componentsJoinedByString:@","]); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment