• 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 COMPOSED_HANDSHAKE = new String(new int[] {0x1FAF1, 0x200D, 0x1FAF2},0,3);
34     public static final String MALE_SIGN = "♂";
35     public static final String FEMALE_SIGN = "♀";
36     public static final String MAN = "��";
37     public static final String WOMAN = "��";
38     public static final String JOINER_MALE_SIGN = JOINER_STRING + MALE_SIGN;
39     public static final String JOINER_FEMALE_SIGN = JOINER_STRING + FEMALE_SIGN;
40     public static final UnicodeSet HAIR_EXPLICIT = new UnicodeSet("[�� ��]").freeze();
41 
42     public static final ListTypeLength COMPOSED_NAME_LIST = ListTypeLength.UNIT_SHORT;
43 
44     //public static final UnicodeSet MODIFIERS_GENDER_SIGNS = new UnicodeSet(0x1F3FB, 0x1F3FF).add(MALE_SIGN).add(FEMALE_SIGN).freeze();
getFlagCode(String s)45     public static String getFlagCode(String s) {
46         return String.valueOf((char) (s.codePointAt(0) - FIRST_REGIONAL + 'A')) + (char) (s.codePointAt(2) - FIRST_REGIONAL + 'A');
47     }
48 
getEmojiFromRegionCodes(String chars)49     public static String getEmojiFromRegionCodes(String chars) {
50         return new StringBuilder()
51                 .appendCodePoint(chars.codePointAt(0) + FIRST_REGIONAL - 'A')
52                 .appendCodePoint(chars.codePointAt(1) + FIRST_REGIONAL - 'A')
53                 .toString();
54     }
55 
56     public static final int TAG_BASE = 0xE0000;
57     public static final int TAG_TERM_CHAR = 0xE007F;
58 
getEmojiFromSubdivisionCodes(String string)59     public static String getEmojiFromSubdivisionCodes(String string) {
60         string = string.toLowerCase(Locale.ROOT).replace("-","");
61         StringBuilder result = new StringBuilder().appendCodePoint(0x1F3F4);
62         for (int cp : CharSequences.codePoints(string)) {
63             result.appendCodePoint(TAG_BASE + cp);
64         }
65         return result.appendCodePoint(TAG_TERM_CHAR).toString();
66     }
67 
68     public static final UnicodeSet FAMILY_MARKERS = new UnicodeSet()
69         .add(0x1F466, 0x1F469).add(0x1F476)
70         .add(JOINER_STRING)
71         .freeze(); // boy, girl, man, woman, baby
72     public static final UnicodeSet REM_SKIP_SET = new UnicodeSet()
73         .add(JOINER_STRING)
74         .freeze();
75     public static final UnicodeSet REM_GROUP_SKIP_SET = new UnicodeSet(REM_SKIP_SET)
76         .add(EmojiConstants.HEART)
77         .add(EmojiConstants.KISS)
78         .add(EmojiConstants.HANDSHAKE)
79         .add(MALE_SIGN)
80         .add(FEMALE_SIGN)
81         .freeze();
82 
getTagSpec(String code)83     public static String getTagSpec(String code) {
84         StringBuilder b = new StringBuilder();
85         for (int codePoint : CharSequences.codePoints(code)) {
86             if (codePoint >= 0xE0020 && codePoint <= 0xE007E) {
87                 b.appendCodePoint(codePoint - 0xE0000);
88             }
89         }
90         return b.toString();
91     }
92 
93     // U+1F3F4 U+E0067 U+E0062 U+E0065 U+E006E U+E0067 U+E007F
toTagSeq(String subdivisionCode)94     public static String toTagSeq(String subdivisionCode) {
95         StringBuilder b = new StringBuilder().appendCodePoint(0x1F3F4);
96         for (int i = 0; i < subdivisionCode.length(); ++i) {
97             b.appendCodePoint(subdivisionCode.charAt(i) + 0xE0000);
98         }
99         return b.appendCodePoint(0xE007F).toString();
100     }
101 
fromCodePoints(int... codePoints)102     public static CharSequence fromCodePoints(int... codePoints) {
103         return EmojiConstants.appendCodePoints(new StringBuilder(), codePoints).toString();
104     }
105 
appendCodePoints(StringBuilder b, int... codePoints)106     public static StringBuilder appendCodePoints(StringBuilder b, int... codePoints) {
107         for (int i = 0; i < codePoints.length; ++i) {
108             b.appendCodePoint(codePoints[i]);
109         }
110         return b;
111     }
112 }