Class EmojiFlags
DE), and an emoji tag sequence over U+1F3F4 WAVING BLACK FLAG encodes an ISO 3166-2
subdivision code in tag characters (the England flag decodes to GB-ENG); both mechanisms
are defined by UTS #51.
Decoding is mechanical and deliberately does not check assignment: U+1F1FD U+1F1FD
decodes to XX even though no such region is assigned, because validity against the
region registry is a join-time question for whatever gazetteer the user has installed (see the
joined-facts layer), not a bundled fact. This is also why no per-flag rows exist in
emoji-annotations.txt: the region code is fully determined by the sequence itself.
isoRegion(CharSequence) is the strict decoder: it fails loud on a sequence that is
flag-shaped but malformed, such as a lone regional indicator or an unterminated tag sequence.
isFlag(CharSequence) is the total predicate for bulk callers that must never throw on
degenerate real-world text. The expected input is one symbol, for example one
Term.original() token; the UAX #29 word tokenizer already segments a run of
adjacent flags into regional indicator pairs.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate static final intprivate static final intprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Stringdecode(CharSequence symbol, boolean lenient) private static StringdecodeRegionalIndicators(CharSequence symbol, int first, boolean lenient) private static StringdecodeTagSequence(CharSequence symbol, boolean lenient) static booleanisFlag(CharSequence symbol) Returns whethersymbolis exactly one well-formed flag emoji.isoRegion(CharSequence symbol) Decodes one flag emoji to its ISO 3166 code: a regional indicator pair to the ISO 3166-1 alpha-2 code (DE) and a subdivision tag sequence to the ISO 3166-2 code (GB-ENG).(package private) static StringisoRegionOrNull(CharSequence symbol) Leniently decodes one flag emoji, the total decode for bulk per-token callers: it returns the ISO 3166 code, ornullwhensymbolis not a well-formed flag (whether not flag-shaped at all or flag-shaped but malformed), never throwing on degenerate real-world text.static booleanisRegionalIndicator(int codePoint) Returns whethercodePointis one of the 26 regional indicator symbols.private static booleanisTagBlock(int codePoint) private static booleanisTagCharacter(int codePoint) private static booleanisTagLetter(char decoded) private static String
-
Field Details
-
FIRST_REGIONAL_INDICATOR
private static final int FIRST_REGIONAL_INDICATOR- See Also:
-
LAST_REGIONAL_INDICATOR
private static final int LAST_REGIONAL_INDICATOR- See Also:
-
WAVING_BLACK_FLAG
private static final int WAVING_BLACK_FLAG- See Also:
-
CANCEL_TAG
private static final int CANCEL_TAG- See Also:
-
TAG_OFFSET
private static final int TAG_OFFSET- See Also:
-
-
Constructor Details
-
EmojiFlags
private EmojiFlags()
-
-
Method Details
-
isRegionalIndicator
public static boolean isRegionalIndicator(int codePoint) Returns whethercodePointis one of the 26 regional indicator symbols.- Parameters:
codePoint- The code point to test.- Returns:
- whether
codePointis one of the 26 regional indicator symbols
-
isFlag
Returns whethersymbolis exactly one well-formed flag emoji. True only for a regional indicator pair or a terminated subdivision tag sequence; unlikeisoRegion(CharSequence)this never throws on malformed sequences, so bulk callers (per-token annotation of arbitrary text) can probe safely.- Parameters:
symbol- The code point sequence of one symbol. Must not benull.- Returns:
- whether
symbolis exactly one well-formed flag emoji - Throws:
IllegalArgumentException- Thrown ifsymbolisnull.
-
isoRegion
Decodes one flag emoji to its ISO 3166 code: a regional indicator pair to the ISO 3166-1 alpha-2 code (DE) and a subdivision tag sequence to the ISO 3166-2 code (GB-ENG).- Parameters:
symbol- The code point sequence of one symbol. Must not benull.- Returns:
- The ISO 3166 code, or empty when
symbolis not flag-shaped at all (no leading regional indicator and no tag sequence over U+1F3F4; a lone U+1F3F4 and the ZWJ pirate flag are not region flags). - Throws:
IllegalArgumentException- Thrown ifsymbolisnull, or if it is flag-shaped but malformed: a lone regional indicator, more or fewer than exactly two regional indicators, or a tag sequence that is unterminated, too short for a subdivision code, not letter-led, or followed by trailing content.
-
isoRegionOrNull
Leniently decodes one flag emoji, the total decode for bulk per-token callers: it returns the ISO 3166 code, ornullwhensymbolis not a well-formed flag (whether not flag-shaped at all or flag-shaped but malformed), never throwing on degenerate real-world text.- Parameters:
symbol- The code point sequence of one symbol. Must not benull.- Returns:
- The ISO 3166 code, or
nullwhensymbolis not a well-formed flag. - Throws:
IllegalArgumentException- Thrown ifsymbolisnull.
-
decode
-
decodeRegionalIndicators
-
decodeTagSequence
-
isTagBlock
private static boolean isTagBlock(int codePoint) -
isTagCharacter
private static boolean isTagCharacter(int codePoint) -
isTagLetter
private static boolean isTagLetter(char decoded) -
malformed
-