Created
March 5, 2015 03:17
-
-
Save Aufree/91160ca4f3f4e063035c to your computer and use it in GitHub Desktop.
Filter all emoji from nsstring
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
- (NSString*)removeEmoji:(NSString *)username { | |
__block NSMutableString* temp = [NSMutableString string]; | |
[username enumerateSubstringsInRange:NSMakeRange(0, [username length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock: | |
^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | |
const unichar hs = [substring characterAtIndex: 0]; | |
// surrogate pair | |
if (0xd800 <= hs && hs <= 0xdbff) { | |
const unichar ls = [substring characterAtIndex: 1]; | |
const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000; | |
[temp appendString: (0x1d000 <= uc && uc <= 0x1f77f)? @"": substring]; // U+1D000-1F77F | |
// non surrogate | |
} else { | |
[temp appendString: (0x2100 <= hs && hs <= 0x26ff)? @"": substring]; // U+2100-26FF | |
} | |
}]; | |
return temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment