Created
March 7, 2016 05:46
-
-
Save satoshin2071/5b196244cbb78b86cf9a to your computer and use it in GitHub Desktop.
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
#import "NSString+CharacterCheck.h" | |
/** | |
サロゲートペアの前半部分 下位の値 | |
*/ | |
static const unichar MinimumHighSurrogate = 0xD800; | |
/** | |
サロゲートペアの前半部分 上位の値 | |
*/ | |
static const unichar MaximumHighSurrogate = 0xDBFF; | |
/** | |
サロゲートペアの後半部分 下位の値 | |
*/ | |
static const unichar MinimumLowSurrogate = 0xDC00; | |
/** | |
サロゲートペアの後半部分 上位の値 | |
*/ | |
static const unichar MaximumLowSurrogate = 0xDFFF; | |
@implementation NSString (CharacterCheck) | |
/** | |
文字列中にサロゲートペアが存在するかをチェックする | |
*/ | |
- (BOOL)existSurrogatePairs | |
{ | |
const NSUInteger length = self.length; | |
for (NSUInteger index = 0; index < length; ++index) { | |
unichar c = [self characterAtIndex:index]; | |
if ([self existHighSurrogate:c] || [self existLowSurrogate:c]) { | |
return YES; | |
} | |
} | |
return NO; | |
} | |
- (BOOL)existHighSurrogate:(const unichar)c | |
{ | |
return (MinimumHighSurrogate <= c && c <= MaximumHighSurrogate); | |
} | |
- (BOOL)existLowSurrogate:(const unichar)c | |
{ | |
return (MinimumLowSurrogate <= c && c <= MaximumLowSurrogate); | |
} | |
@end |
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 Foundation; | |
@interface NSString (CharacterCheck) | |
/** | |
文字列中にサロゲートペアが存在するかをチェックする | |
*/ | |
- (BOOL)existSurrogatePairs; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment