Finding emojis in NSStrings
// This is bad and I feel bad. Suggestions for improvements on finding Emoji? | |
// This current solution is acceptable for us right now, but obviously the less I have to exclude the better. | |
@interface NSString (Emoji) | |
/** | |
Returns if the receiver may contain Emoji characters. | |
@note This method may have false-positives since it sees if the string has non-ASCII characters. If the receiver has a non-Emoji, non-ASCII character (like é) then it will still return YES. | |
*/ | |
- (BOOL)maybeContainsEmoji; | |
@end | |
@implementation NSString (Emoji) | |
- (BOOL)maybeContainsEmoji | |
{ | |
NSData *stringData = [self dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; | |
return ![[[NSString alloc] initWithData:stringData encoding:NSASCIIStringEncoding] isEqualToString:self]; | |
} | |
@end |
This comment has been minimized.
This comment has been minimized.
You could do something like
(note this is off the top of my head so may not actually compile) There are obvious tradeoffs here that may or may not work for your case, though Whoops, @mattbischoff's answer is similar/better |
This comment has been minimized.
This comment has been minimized.
Thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
:(, I might actually go this route if it was me: https://github.com/luosheng/CoreTextEmoji/blob/master/CoreTextEmoji/NSCharacterSet%2BEmojiAdditions.m