Skip to content

Instantly share code, notes, and snippets.

@michaelochs
Created December 17, 2015 12:32
Show Gist options
  • Save michaelochs/dd032ff619b1e30e5013 to your computer and use it in GitHub Desktop.
Save michaelochs/dd032ff619b1e30e5013 to your computer and use it in GitHub Desktop.
A NSCharacterSet containing (hopefully) all logographic characters from unicode.
#define CharacterRange(__from__, __to__) NSMakeRange(__from__, __to__ - __from__ + 1)
@implementation NSCharacterSet (HRSCharacterSet)
+ (instancetype)logographicCharacterSet
{
NSRange ranges[] = {
CharacterRange(0x2E80, 0x2EFF), // CJK Radicals Supplement
CharacterRange(0x2F00, 0x2FDF), // Kangxi Radicals
CharacterRange(0x3300, 0x33FF), // CJK Compatibility
CharacterRange(0x3400, 0x4DBF), // CJK Unified Ideographs Extension A
CharacterRange(0x4E00, 0x9FFF), // CJK Unified Ideographs
CharacterRange(0xA000, 0xA48F), // Yi Syllables
CharacterRange(0xA490, 0xA4CF), // Yi Radicals
CharacterRange(0xAC00, 0xD7AF), // Hangul Syllables
CharacterRange(0xF900, 0xFAFF), // CJK Compatibility Ideographs
CharacterRange(0x20000, 0x2A6DF), // CJK Unified Ideographs Extension B
CharacterRange(0x2F800, 0x2FA1F), // CJK Compatibility Ideographs Supplement
};
NSUInteger rangeCount = 10;
NSMutableCharacterSet *characterSet = [NSMutableCharacterSet new];
for (int i = 0; i < rangeCount; i++) {
[characterSet addCharactersInRange:ranges[i]];
}
return [characterSet copy];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment