• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.text;
18 
19 import android.icu.lang.UCharacter;
20 import android.icu.lang.UProperty;
21 
22 /**
23  * An utility class for Emoji.
24  * @hide
25  */
26 @android.ravenwood.annotation.RavenwoodKeepWholeClass
27 public class Emoji {
28     public static int COMBINING_ENCLOSING_KEYCAP = 0x20E3;
29 
30     public static int ZERO_WIDTH_JOINER = 0x200D;
31 
32     public static int VARIATION_SELECTOR_16 = 0xFE0F;
33 
34     public static int CANCEL_TAG = 0xE007F;
35 
36     /**
37      * Returns true if the given code point is regional indicator symbol.
38      */
isRegionalIndicatorSymbol(int codePoint)39     public static boolean isRegionalIndicatorSymbol(int codePoint) {
40         return 0x1F1E6 <= codePoint && codePoint <= 0x1F1FF;
41     }
42 
43     /**
44      * Returns true if the given code point is emoji modifier.
45      */
isEmojiModifier(int codePoint)46     public static boolean isEmojiModifier(int codePoint) {
47         return UCharacter.hasBinaryProperty(codePoint, UProperty.EMOJI_MODIFIER);
48     }
49 
50     //
51 
52     /**
53      * Returns true if the given code point is emoji modifier base.
54      * @param c codepoint to check
55      * @return true if is emoji modifier base
56      */
isEmojiModifierBase(int c)57     public static boolean isEmojiModifierBase(int c) {
58         // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to
59         // keep them as emoji modifier bases since there are fonts and user-generated text out there
60         // that treats these as potential emoji bases.
61         if (c == 0x1F91D || c == 0x1F93C) {
62             return true;
63         }
64         // If Android's copy of ICU is behind, check for new codepoints here.
65         // Consult log for implementation pattern.
66         return UCharacter.hasBinaryProperty(c, UProperty.EMOJI_MODIFIER_BASE);
67     }
68 
69     /**
70      * Returns true if the character has Emoji property.
71      */
isEmoji(int codePoint)72     public static boolean isEmoji(int codePoint) {
73         return UCharacter.hasBinaryProperty(codePoint, UProperty.EMOJI);
74     }
75 
76     // Returns true if the character can be a base character of COMBINING ENCLOSING KEYCAP.
isKeycapBase(int codePoint)77     public static boolean isKeycapBase(int codePoint) {
78         return ('0' <= codePoint && codePoint <= '9') || codePoint == '#' || codePoint == '*';
79     }
80 
81     /**
82      * Returns true if the character can be a part of tag_spec in emoji tag sequence.
83      *
84      * Note that 0xE007F (CANCEL TAG) is not included.
85      */
isTagSpecChar(int codePoint)86     public static boolean isTagSpecChar(int codePoint) {
87         return 0xE0020 <= codePoint && codePoint <= 0xE007E;
88     }
89 }
90