EaseEmoji.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /************************************************************
  2. * * Hyphenate CONFIDENTIAL
  3. * __________________
  4. * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
  5. *
  6. * NOTICE: All information contained herein is, and remains
  7. * the property of Hyphenate Inc.
  8. * Dissemination of this information or reproduction of this material
  9. * is strictly forbidden unless prior written permission is obtained
  10. * from Hyphenate Inc.
  11. */
  12. #import "EaseEmoji.h"
  13. #import "EaseEmojiEmoticons.h"
  14. @implementation EaseEmoji
  15. + (NSString *)emojiWithCode:(int)code
  16. {
  17. int sym = EMOJI_CODE_TO_SYMBOL(code);
  18. return [[NSString alloc] initWithBytes:&sym length:sizeof(sym) encoding:NSUTF8StringEncoding];
  19. }
  20. + (NSArray *)allEmoji
  21. {
  22. NSMutableArray *array = [NSMutableArray new];
  23. [array addObjectsFromArray:[EaseEmojiEmoticons allEmoticons]];
  24. return array;
  25. }
  26. + (BOOL)stringContainsEmoji:(NSString *)string
  27. {
  28. __block BOOL returnValue = NO;
  29. [string enumerateSubstringsInRange:NSMakeRange(0, [string length])
  30. options:NSStringEnumerationByComposedCharacterSequences
  31. usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
  32. const unichar hs = [substring characterAtIndex:0];
  33. if (0xd800 <= hs && hs <= 0xdbff) {
  34. if (substring.length > 1) {
  35. const unichar ls = [substring characterAtIndex:1];
  36. const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
  37. if (0x1d000 <= uc && uc <= 0x1f77f) {
  38. returnValue = YES;
  39. }
  40. }
  41. } else if (substring.length > 1) {
  42. const unichar ls = [substring characterAtIndex:1];
  43. if (ls == 0x20e3) {
  44. returnValue = YES;
  45. }
  46. } else {
  47. if (0x2100 <= hs && hs <= 0x27ff) {
  48. returnValue = YES;
  49. } else if (0x2B05 <= hs && hs <= 0x2b07) {
  50. returnValue = YES;
  51. } else if (0x2934 <= hs && hs <= 0x2935) {
  52. returnValue = YES;
  53. } else if (0x3297 <= hs && hs <= 0x3299) {
  54. returnValue = YES;
  55. } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
  56. returnValue = YES;
  57. }
  58. }
  59. }];
  60. return returnValue;
  61. }
  62. @end