• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.util;
2 
3 import java.util.Locale;
4 
5 import org.unicode.cldr.util.XListFormatter.ListTypeLength;
6 
7 import com.ibm.icu.lang.CharSequences;
8 import com.ibm.icu.text.UTF16;
9 import com.ibm.icu.text.UnicodeSet;
10 
11 public class EmojiConstants {
12     public static final String EMOJI_VARIANT_STRING = "\uFE0F";
13     static final int FIRST_REGIONAL = 0x1F1E6;
14     static final int LAST_REGIONAL = 0x1F1FF;
15     public static final UnicodeSet REGIONAL_INDICATORS = new UnicodeSet(FIRST_REGIONAL, LAST_REGIONAL).freeze();
16     public static final String KEYCAP_MARK_STRING = "\u20E3";
17     public static final UnicodeSet MODIFIERS = new UnicodeSet(0x1F3FB, 0x1F3FF).freeze();
18     public static final UnicodeSet HAIR = new UnicodeSet(0x1F9B0, 0x1F9B3).freeze();
19     public static final char JOINER = '\u200D';
20     public static final String JOINER_STRING = String.valueOf(JOINER);
21     public static final UnicodeSet COMPONENTS = new UnicodeSet(EmojiConstants.MODIFIERS)
22         .add(EmojiConstants.fromCodePoints(JOINER,0x1F9B0))
23         .add(EmojiConstants.fromCodePoints(JOINER,0x1F9B1))
24         .add(EmojiConstants.fromCodePoints(JOINER,0x1F9B2))
25         .add(EmojiConstants.fromCodePoints(JOINER,0x1F9B3))
26         .freeze();
27 
28     public static final String KISS = "��";
29     public static final String HEART = "❤";
30     public static final String TAG_TERM = UTF16.valueOf(0xE007F);
31     public static final String BLACK_FLAG = UTF16.valueOf(0x1F3F4);
32     public static final String HANDSHAKE = UTF16.valueOf(0x1f91d);
33     public static final String MALE_SIGN = "♂";
34     public static final String FEMALE_SIGN = "♀";
35     public static final String MAN = "��";
36     public static final String WOMAN = "��";
37     public static final String JOINER_MALE_SIGN = JOINER_STRING + MALE_SIGN;
38     public static final String JOINER_FEMALE_SIGN = JOINER_STRING + FEMALE_SIGN;
39     public static final UnicodeSet HAIR_EXPLICIT = new UnicodeSet("[�� ��]").freeze();
40 
41     public static final ListTypeLength COMPOSED_NAME_LIST = ListTypeLength.UNIT_SHORT;
42 
43     //public static final UnicodeSet MODIFIERS_GENDER_SIGNS = new UnicodeSet(0x1F3FB, 0x1F3FF).add(MALE_SIGN).add(FEMALE_SIGN).freeze();
getFlagCode(String s)44     public static String getFlagCode(String s) {
45         return String.valueOf((char) (s.codePointAt(0) - FIRST_REGIONAL + 'A')) + (char) (s.codePointAt(2) - FIRST_REGIONAL + 'A');
46     }
47 
getEmojiFromRegionCodes(String chars)48     public static String getEmojiFromRegionCodes(String chars) {
49         return new StringBuilder()
50                 .appendCodePoint(chars.codePointAt(0) + FIRST_REGIONAL - 'A')
51                 .appendCodePoint(chars.codePointAt(1) + FIRST_REGIONAL - 'A')
52                 .toString();
53     }
54 
55     public static final int TAG_BASE = 0xE0000;
56     public static final int TAG_TERM_CHAR = 0xE007F;
57 
getEmojiFromSubdivisionCodes(String string)58     public static String getEmojiFromSubdivisionCodes(String string) {
59         string = string.toLowerCase(Locale.ROOT).replace("-","");
60         StringBuilder result = new StringBuilder().appendCodePoint(0x1F3F4);
61         for (int cp : CharSequences.codePoints(string)) {
62             result.appendCodePoint(TAG_BASE + cp);
63         }
64         return result.appendCodePoint(TAG_TERM_CHAR).toString();
65     }
66 
67     public static final UnicodeSet FAMILY_MARKERS = new UnicodeSet()
68         .add(0x1F466, 0x1F469).add(0x1F476)
69         .add(JOINER_STRING)
70         .freeze(); // boy, girl, man, woman, baby
71     public static final UnicodeSet REM_SKIP_SET = new UnicodeSet()
72         .add(JOINER_STRING)
73         .freeze();
74     public static final UnicodeSet REM_GROUP_SKIP_SET = new UnicodeSet(REM_SKIP_SET)
75         .add(EmojiConstants.HEART)
76         .add(EmojiConstants.KISS)
77         .add(EmojiConstants.HANDSHAKE)
78         .add(MALE_SIGN)
79         .add(FEMALE_SIGN)
80         .freeze();
81 
getTagSpec(String code)82     public static String getTagSpec(String code) {
83         StringBuilder b = new StringBuilder();
84         for (int codePoint : CharSequences.codePoints(code)) {
85             if (codePoint >= 0xE0020 && codePoint <= 0xE007E) {
86                 b.appendCodePoint(codePoint - 0xE0000);
87             }
88         }
89         return b.toString();
90     }
91 
92     // U+1F3F4 U+E0067 U+E0062 U+E0065 U+E006E U+E0067 U+E007F
toTagSeq(String subdivisionCode)93     public static String toTagSeq(String subdivisionCode) {
94         StringBuilder b = new StringBuilder().appendCodePoint(0x1F3F4);
95         for (int i = 0; i < subdivisionCode.length(); ++i) {
96             b.appendCodePoint(subdivisionCode.charAt(i) + 0xE0000);
97         }
98         return b.appendCodePoint(0xE007F).toString();
99     }
100 
fromCodePoints(int... codePoints)101     public static CharSequence fromCodePoints(int... codePoints) {
102         return EmojiConstants.appendCodePoints(new StringBuilder(), codePoints).toString();
103     }
104 
appendCodePoints(StringBuilder b, int... codePoints)105     public static StringBuilder appendCodePoints(StringBuilder b, int... codePoints) {
106         for (int i = 0; i < codePoints.length; ++i) {
107             b.appendCodePoint(codePoints[i]);
108         }
109         return b;
110     }
111 }