Created
November 7, 2012 02:41
-
-
Save qchenqizhi/4029296 to your computer and use it in GitHub Desktop.
NSString has emoji
This file contains hidden or 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
// Reference: | |
// https://github.com/iamcal/php-emoji | |
// http://de.wikipedia.org/wiki/Unicode-Block_Kombinierende_diakritische_Zeichen_f%C3%BCr_Symbole | |
- (BOOL)hasEmoji | |
{ | |
__block BOOL emoji = NO; | |
[self enumerateSubstringsInRange:NSMakeRange(0, self.length) | |
options:NSStringEnumerationByComposedCharacterSequences | |
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | |
const unichar hs = [substring characterAtIndex: 0]; | |
if (0xd800 <= hs && hs <= 0xdbff) { | |
const unichar ls = [substring characterAtIndex: 1]; | |
const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000; | |
if (0x1d000 <= uc && uc <= 0x1f77f) { | |
emoji = YES; | |
*stop = YES; | |
} | |
} else { | |
if (0x2100 <= hs && hs <= 0x27ff) { | |
emoji = YES; | |
*stop = YES; | |
} | |
else if (hs == 0x2b05 || hs == 0x2b06 || hs == 0x2b07 || | |
hs == 0x2b55 || hs == 0x2b50 || hs == 0x2b1b || hs == 0x2b1c || | |
hs == 0x00a9 || hs == 0x00ae || | |
hs == 0x2934 || hs == 0x2935 || | |
hs == 0x2049 || hs == 0x203c || hs == 0x2002 || hs == 0x2003 || hs == 0x2005 || | |
hs == 0x3030 || hs == 0x303d || | |
hs == 0x3297 || hs == 0x3299 || | |
hs == 0x231a || hs == 0x231b || hs == 0x23f0 || hs == 0x23f3 || | |
(hs >= 0x23e9 && hs <= 0x23ec) || | |
hs == 0x24c2 || | |
(hs >= 0x25fb && hs <= 0x25fe) || | |
hs == 0x25aa || hs == 0x25ab || hs == 0x25b6 || hs == 0x25c0) { | |
emoji = YES; | |
*stop = YES; | |
} | |
else if ((hs >= 0x0030 && hs <= 0x0039) || hs == 0x0023) { //1234567890# | |
if (substring.length > 1) { //1⃣2⃣3⃣... | |
const unichar ls = [substring characterAtIndex:1]; | |
if (ls == 0x20E3) { // ⃣ | |
emoji = YES; | |
*stop = YES; | |
} | |
} | |
} | |
} | |
}]; | |
return emoji; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment