Class UnicodeEmojiSequences
A sequence is fully-qualified in the sense of
UTS #51 when every code point that needs
an emoji presentation selector has one, and minimally-qualified when only its first
code point has it. The inventory holds the fully-qualified and
minimally-qualified lines of emoji-test.txt, which cover single emoji, emoji
with U+FE0F, flags, keycaps, skin tone modifier sequences, ZWJ sequences and tag sequences, in
a trie, plus the Emoji_Component ranges of emoji-data.txt: the joiners,
modifiers, selectors, flag letters and tags that occur inside sequences. A component on its
own is never an emoji, but a stray one next to an emoji marks a malformed candidate that is
kept as it is.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final recordWhatcandidateAt(CharSequence, int)found at a position.private static final classA trie node: the code points that may follow, and whether a sequence ends here.private static final recordThe result of one trie walk. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BitSetEvery code point a candidate can start with: the first code point of a sequence or a structural component.private static final charFirst character of a comment line of the data file.private static final StringPrefix of a record holding oneEmoji_Componentcode point range.private final int[][]private static final BundledUnicodeData.Lazy<UnicodeEmojiSequences> private static final CodePointSetThe bases of the keycap sequences:#,*and the ASCII digits.private static final Stringprivate final UnicodeEmojiSequences.Nodeprivate static final StringPrefix of a record holding one qualified sequence.private final int(package private) static final intU+FE0F asks for emoji presentation.(package private) static final intU+FE0E asks for text presentation. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateUnicodeEmojiSequences(UnicodeEmojiSequences.Node root, int[][] componentRanges, int sequenceCount) -
Method Summary
Modifier and TypeMethodDescription(package private) UnicodeEmojiSequences.CandidatecandidateAt(CharSequence text, int start) Finds the emoji candidate that starts at a position.(package private) static UnicodeEmojiSequencesReturns the matcher built from the bundled data, loaded on first use.(package private) booleanisCandidateStart(int codePoint) Returns whether a code point can start a candidate.private booleanisStructuralComponent(int codePoint) Returns whether a code point is a joiner, modifier, selector, flag letter or tag that occurs inside sequences.private static UnicodeEmojiSequencesload()Loads the bundled data resource.private intmatch(CharSequence text, int start) Returns the index after the longest complete sequence starting atstart, or-1if none starts there.(package private) static UnicodeEmojiSequencesparse(InputStream in) ParsesS;sequence andC;component range records into a matcher.(package private) intReturns the number of sequence records that were loaded.private UnicodeEmojiSequences.Walkwalk(CharSequence text, int start) Walks the trie along the text from a position.
-
Field Details
-
RESOURCE
- See Also:
-
INSTANCE
-
SEQUENCE_RECORD
Prefix of a record holding one qualified sequence.- See Also:
-
COMPONENT_RECORD
Prefix of a record holding oneEmoji_Componentcode point range.- See Also:
-
COMMENT
private static final char COMMENTFirst character of a comment line of the data file.- See Also:
-
VARIATION_SELECTOR_TEXT
static final int VARIATION_SELECTOR_TEXTU+FE0E asks for text presentation. It has noEmoji_Componentproperty but it binds to the symbol before it the same way U+FE0F does, so it counts as a structural component.- See Also:
-
VARIATION_SELECTOR_EMOJI
static final int VARIATION_SELECTOR_EMOJIU+FE0F asks for emoji presentation.- See Also:
-
KEYCAP_BASES
The bases of the keycap sequences:#,*and the ASCII digits. They have theEmoji_Componentproperty, but as ordinary text characters they must never make a neighboring emoji a malformed candidate, so they are excluded from the structural components. -
root
-
componentRanges
private final int[][] componentRanges -
sequenceCount
private final int sequenceCount -
candidateStarts
Every code point a candidate can start with: the first code point of a sequence or a structural component. One bit test rejects nearly every position of ordinary text before the trie is touched.
-
-
Constructor Details
-
UnicodeEmojiSequences
private UnicodeEmojiSequences(UnicodeEmojiSequences.Node root, int[][] componentRanges, int sequenceCount)
-
-
Method Details
-
getInstance
Returns the matcher built from the bundled data, loaded on first use. A failed load is not cached, so the next call loads again.- Returns:
- the matcher built from the bundled data, loaded on first use
- Throws:
IllegalStateException- Thrown if the bundled data resource is missing.UncheckedIOException- Thrown if the bundled data resource cannot be read.IllegalArgumentException- Thrown if the bundled data is malformed.
-
isCandidateStart
boolean isCandidateStart(int codePoint) Returns whether a code point can start a candidate. A cheap pre-check for callers that scan text, so the trie is only touched at positions that can hold an emoji.- Parameters:
codePoint- The code point to test.- Returns:
- whether a code point can start a candidate
-
sequenceCount
int sequenceCount()Returns the number of sequence records that were loaded.- Returns:
- the number of sequence records that were loaded
-
candidateAt
Finds the emoji candidate that starts at a position.The candidate is a run of complete sequences, or a malformed one: an emoji with a stray component such as a trailing joiner or an extra modifier, a leading component connected to an emoji, or a prefix of a sequence that continues with a component. A stray component connects only to the complete sequence right before it and to the one right after it; complete sequences that merely touch the malformed part are not included, so the caller removes them and sees the malformed candidate at a later call. One U+FE0F right after a complete sequence is part of it.
- Parameters:
text- The text to look into. Must not benull.start- The index the candidate must start at.- Returns:
nullif no candidate starts atstart; otherwise a candidate that is valid when it consists of complete sequences only, and invalid when it holds a stray component or an incomplete sequence, withUnicodeEmojiSequences.Candidate.end()as the index after it in both cases.
-
match
Returns the index after the longest complete sequence starting atstart, or-1if none starts there.- Parameters:
text- The text to look into. Must not benull.start- The index the sequence must start at.- Returns:
- the index after the longest complete sequence starting at
start, or-1if none starts there
-
walk
Walks the trie along the text from a position.- Parameters:
text- The text to look into. Must not benull.start- The index the walk starts at.- Returns:
- The index after the longest complete sequence, or
-1if none, and the index after the longest prefix of any sequence, which isstartif none.
-
isStructuralComponent
private boolean isStructuralComponent(int codePoint) Returns whether a code point is a joiner, modifier, selector, flag letter or tag that occurs inside sequences. These are theEmoji_Componentranges plus U+FE0E, without the keycap bases.- Parameters:
codePoint- The code point to test.- Returns:
- whether a code point is a joiner, modifier, selector, flag letter or tag that occurs inside sequences
-
load
Loads the bundled data resource.- Returns:
- The matcher.
- Throws:
IllegalStateException- Thrown if the bundled data resource is missing.UncheckedIOException- Thrown if the bundled data resource cannot be read.IllegalArgumentException- Thrown if the bundled data is malformed.
-
parse
ParsesS;sequence andC;component range records into a matcher. Package-visible so the malformed-data handling can be exercised without the bundled resource.- Parameters:
in- The records to read, one per line;#lines are comments.- Returns:
- The matcher.
- Throws:
IOException- Thrown if readinginfails.IllegalArgumentException- Thrown if a record is malformed.
-