| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/text/Character.h" | 5 #include "platform/text/Character.h" |
| 6 | 6 |
| 7 #include <unicode/uvernum.h> |
| 8 |
| 9 #if defined(USING_SYSTEM_ICU) && (U_ICU_VERSION_MAJOR_NUM <= 56) |
| 7 #include <unicode/uniset.h> | 10 #include <unicode/uniset.h> |
| 11 #else |
| 12 #include <unicode/uchar.h> |
| 13 #endif |
| 8 | 14 |
| 9 using namespace WTF; | 15 using namespace WTF; |
| 10 using namespace Unicode; | 16 using namespace Unicode; |
| 11 | 17 |
| 12 namespace blink { | 18 namespace blink { |
| 13 | 19 |
| 20 // ICU 56 or earlier does not have API for Emoji properties, |
| 21 // but Chrome's copy of ICU 56 does. |
| 22 #if defined(USING_SYSTEM_ICU) && (U_ICU_VERSION_MAJOR_NUM <= 56) |
| 14 // The following UnicodeSet patterns were compiled from | 23 // The following UnicodeSet patterns were compiled from |
| 15 // http://www.unicode.org/Public/emoji/2.0//emoji-data.txt | 24 // http://www.unicode.org/Public/emoji/2.0//emoji-data.txt |
| 16 | 25 |
| 17 // FIXME crbug.com/579552: | |
| 18 // These patterns should move to property group definitions in ICU. | |
| 19 | |
| 20 static const char kEmojiTextPattern[] = | 26 static const char kEmojiTextPattern[] = |
| 21 R"([[#][*][0-9][\u00A9][\u00AE][\u203C][\u2049][\u2122][\u2139])" | 27 R"([[#][*][0-9][\u00A9][\u00AE][\u203C][\u2049][\u2122][\u2139])" |
| 22 R"([\u2194-\u2199][\u21A9-\u21AA][\u231A-\u231B][\u2328][\u23CF])" | 28 R"([\u2194-\u2199][\u21A9-\u21AA][\u231A-\u231B][\u2328][\u23CF])" |
| 23 R"([\u23E9-\u23F3][\u23F8-\u23FA][\u24C2][\u25AA-\u25AB][\u25B6][\u25C0])" | 29 R"([\u23E9-\u23F3][\u23F8-\u23FA][\u24C2][\u25AA-\u25AB][\u25B6][\u25C0])" |
| 24 R"([\u25FB-\u25FE][\u2600-\u2604][\u260E][\u2611][\u2614-\u2615][\u2618])" | 30 R"([\u25FB-\u25FE][\u2600-\u2604][\u260E][\u2611][\u2614-\u2615][\u2618])" |
| 25 R"([\u261D][\u2620][\u2622-\u2623][\u2626][\u262A][\u262E-\u262F])" | 31 R"([\u261D][\u2620][\u2622-\u2623][\u2626][\u262A][\u262E-\u262F])" |
| 26 R"([\u2638-\u263A][\u2648-\u2653][\u2660][\u2663][\u2665-\u2666][\u2668])" | 32 R"([\u2638-\u263A][\u2648-\u2653][\u2660][\u2663][\u2665-\u2666][\u2668])" |
| 27 R"([\u267B][\u267F][\u2692-\u2694][\u2696-\u2697][\u2699][\u269B-\u269C])" | 33 R"([\u267B][\u267F][\u2692-\u2694][\u2696-\u2697][\u2699][\u269B-\u269C])" |
| 28 R"([\u26A0-\u26A1][\u26AA-\u26AB][\u26B0-\u26B1][\u26BD-\u26BE])" | 34 R"([\u26A0-\u26A1][\u26AA-\u26AB][\u26B0-\u26B1][\u26BD-\u26BE])" |
| 29 R"([\u26C4-\u26C5][\u26C8][\u26CE-\u26CF][\u26D1][\u26D3-\u26D4])" | 35 R"([\u26C4-\u26C5][\u26C8][\u26CE-\u26CF][\u26D1][\u26D3-\u26D4])" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 104 } |
| 99 | 105 |
| 100 bool Character::isEmojiEmojiDefault(UChar32 ch) | 106 bool Character::isEmojiEmojiDefault(UChar32 ch) |
| 101 { | 107 { |
| 102 DEFINE_STATIC_LOCAL(icu::UnicodeSet, emojiEmojiSet, ()); | 108 DEFINE_STATIC_LOCAL(icu::UnicodeSet, emojiEmojiSet, ()); |
| 103 if (emojiEmojiSet.isEmpty()) | 109 if (emojiEmojiSet.isEmpty()) |
| 104 applyPatternAndFreeze(&emojiEmojiSet, kEmojiEmojiPattern); | 110 applyPatternAndFreeze(&emojiEmojiSet, kEmojiEmojiPattern); |
| 105 return emojiEmojiSet.contains(ch); | 111 return emojiEmojiSet.contains(ch); |
| 106 } | 112 } |
| 107 | 113 |
| 108 | |
| 109 bool Character::isEmojiModifierBase(UChar32 ch) | 114 bool Character::isEmojiModifierBase(UChar32 ch) |
| 110 { | 115 { |
| 111 DEFINE_STATIC_LOCAL(icu::UnicodeSet, emojieModifierBaseSet, ()); | 116 DEFINE_STATIC_LOCAL(icu::UnicodeSet, emojieModifierBaseSet, ()); |
| 112 if (emojieModifierBaseSet.isEmpty()) | 117 if (emojieModifierBaseSet.isEmpty()) |
| 113 applyPatternAndFreeze(&emojieModifierBaseSet, kEmojiModifierBasePattern)
; | 118 applyPatternAndFreeze(&emojieModifierBaseSet, kEmojiModifierBasePattern)
; |
| 114 return emojieModifierBaseSet.contains(ch); | 119 return emojieModifierBaseSet.contains(ch); |
| 115 } | 120 } |
| 121 #else |
| 122 bool Character::isEmoji(UChar32 ch) |
| 123 { |
| 124 return u_hasBinaryProperty(ch, UCHAR_EMOJI); |
| 125 } |
| 126 bool Character::isEmojiTextDefault(UChar32 ch) |
| 127 { |
| 128 return u_hasBinaryProperty(ch, UCHAR_EMOJI) |
| 129 && !u_hasBinaryProperty(ch, UCHAR_EMOJI_PRESENTATION); |
| 130 } |
| 131 |
| 132 bool Character::isEmojiEmojiDefault(UChar32 ch) |
| 133 { |
| 134 return u_hasBinaryProperty(ch, UCHAR_EMOJI_PRESENTATION); |
| 135 } |
| 136 |
| 137 bool Character::isEmojiModifierBase(UChar32 ch) |
| 138 { |
| 139 return u_hasBinaryProperty(ch, UCHAR_EMOJI_MODIFIER_BASE); |
| 140 } |
| 141 #endif // defined(USING_SYSTEM_ICU) && (U_ICU_VERSION_MAJOR_NUM <= 56) |
| 116 | 142 |
| 117 bool Character::isEmojiKeycapBase(UChar32 ch) | 143 bool Character::isEmojiKeycapBase(UChar32 ch) |
| 118 { | 144 { |
| 119 return (ch >= '0' && ch <= '9') || ch == '#'; | 145 return (ch >= '0' && ch <= '9') || ch == '#'; |
| 120 } | 146 } |
| 121 | 147 |
| 122 bool Character::isRegionalIndicator(UChar32 ch) | 148 bool Character::isRegionalIndicator(UChar32 ch) |
| 123 { | 149 { |
| 124 return (ch >= 0x1F1E6 && ch <= 0x1F1FF); | 150 return (ch >= 0x1F1E6 && ch <= 0x1F1FF); |
| 125 } | 151 } |
| 126 | 152 |
| 127 | 153 |
| 128 }; // namespace blink | 154 }; // namespace blink |
| OLD | NEW |