Skip to content

Commit c9e88bd

Browse files
committed
Find emojis by codepoint
Now you can find emojis by codepoint using the `U+ABCD` notation, for example `U+1F976` (or `u+1f976`) will find 🥶. A nice side effect is that you can show all the emojis having a VS-16 codepoint with `u+fe0f` and all the emojis having a ZWJ with `u+200d`. This is all implemented in EmojiDb::findEmojis(): there needs to be a single needle, its size needs to be at least three, and it must start with `u+` (all needles are lowercase). Signed-off-by: Philippe Proulx <[email protected]>
1 parent 54045d5 commit c9e88bd

File tree

5 files changed

+103
-4
lines changed

5 files changed

+103
-4
lines changed

README.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ endif::env-github[]
1111

1212
= jome 😏
1313
Philippe Proulx <eepp.ca>
14-
8 April 2025
14+
14 April 2025
1515

1616
https://github.com/eepp/jome/releases/tag/v1.2.1[image:https://img.shields.io/github/v/release/eepp/jome?display_name=release[GitHub Release]]
1717
https://aur.archlinux.org/packages/jome[image:https://img.shields.io/aur/version/jome?&label=AUR[AUR Version]]
@@ -230,6 +230,8 @@ The format of a query is 1️⃣ of:
230230
* `_TERMS_`
231231
* `_CAT_/`
232232
* `_CAT_/_TERMS_`
233+
* `_CODEPOINT_`
234+
* `_CAT_/_CODEPOINT_`
233235

234236
where:
235237

@@ -242,6 +244,11 @@ where:
242244
For an emoji to be part of the results, its name and keywords must
243245
contain _all_ the 🔍 terms.
244246

247+
`_CODEPOINT_`::
248+
A single Unicode codepoint using the standard `U+__ABCD__` notation.
249+
250+
Everything is 💼-insensitive.
251+
245252
[[select]]
246253
=== Select and ✅ an emoji
247254

jome/emoji-db.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,28 @@
2424
#include "emoji-db.hpp"
2525

2626
namespace jome {
27+
namespace {
28+
29+
QString cpStr(const Emoji::Codepoints& codepoints)
30+
{
31+
QStringList parts;
32+
33+
for (const auto cp : codepoints) {
34+
parts.append(qFmtFormat("u+{:x}", cp));
35+
}
36+
37+
return parts.join(' ');
38+
}
39+
40+
} // namespace
2741

2842
Emoji::Emoji(QString str, QString name,
2943
std::unordered_set<QString>&& keywords, const bool hasSkinToneSupport,
3044
const EmojiVersion version) :
3145
_str {std::move(str)},
3246
_name {std::move(name)},
3347
_lcName {_name.toLower()},
48+
_cpStr {cpStr(this->codepoints())},
3449
_keywords {std::move(keywords)},
3550
_hasSkinToneSupport {hasSkinToneSupport},
3651
_version {version}
@@ -427,6 +442,31 @@ void EmojiDb::findEmojis(QString catName, const QString& needlesStr,
427442
_tmpFindResults.clear();
428443
_tmpFindResultEmojis.clear();
429444

445+
// handle specific codepoint search
446+
if (needles.size() == 1 && needles.first().size() >= 3 && needles.first().startsWith("u+")) {
447+
for (auto& cat : _cats) {
448+
if (cat->isRecent()) {
449+
// exclude "Recent" category
450+
continue;
451+
}
452+
453+
if (!catName.isEmpty() && !cat->lcName().contains(catName)) {
454+
// we don't even want to search this category
455+
continue;
456+
}
457+
458+
for (auto emoji : cat->emojis()) {
459+
if (emoji->codepointStr().contains(needles.first()) &&
460+
_tmpFindResultEmojis.count(emoji) == 0) {
461+
results.push_back(emoji);
462+
_tmpFindResultEmojis.insert(emoji);
463+
}
464+
}
465+
}
466+
467+
return;
468+
}
469+
430470
auto pos = 0U;
431471

432472
for (auto& cat : _cats) {

jome/emoji-db.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ class Emoji final
120120
return _lcName;
121121
}
122122

123+
/*
124+
* Codepoint string (lowercase).
125+
*
126+
* For example: `u+2600 u+fe0f`.
127+
*
128+
* The purpose of this string is to be able to find an emoji quickly
129+
* by codepoint with the `U+ABCD` notation.
130+
*/
131+
const QString& codepointStr() const noexcept
132+
{
133+
return _cpStr;
134+
}
135+
123136
/*
124137
* Keywords of this emoji.
125138
*/
@@ -148,6 +161,7 @@ class Emoji final
148161
const QString _str;
149162
const QString _name;
150163
const QString _lcName;
164+
const QString _cpStr;
151165
const std::unordered_set<QString> _keywords;
152166
const bool _hasSkinToneSupport;
153167
const EmojiVersion _version;

man/jome.1

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: vlttng
33
.\" Author: [see the "AUTHOR(S)" section]
44
.\" Generator: Asciidoctor 2.0.23
5-
.\" Date: 8 April 2025
5+
.\" Date: 14 April 2025
66
.\" Manual: JOME
77
.\" Source: JOME
88
.\" Language: English
99
.\"
10-
.TH "JOME" "1" "8 April 2025" "JOME" "JOME"
10+
.TH "JOME" "1" "14 April 2025" "JOME" "JOME"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0
@@ -203,6 +203,28 @@ The format of a query is one of:
203203
\fICAT\fP/\fITERMS\fP
204204
.RE
205205
.sp
206+
.RS 4
207+
.ie n \{\
208+
\h'-04'\(bu\h'+03'\c
209+
.\}
210+
.el \{\
211+
. sp -1
212+
. IP \(bu 2.3
213+
.\}
214+
\fICODEPOINT\fP
215+
.RE
216+
.sp
217+
.RS 4
218+
.ie n \{\
219+
\h'-04'\(bu\h'+03'\c
220+
.\}
221+
.el \{\
222+
. sp -1
223+
. IP \(bu 2.3
224+
.\}
225+
\fICAT\fP/\fICODEPOINT\fP
226+
.RE
227+
.sp
206228
where:
207229
.sp
208230
\fICAT\fP
@@ -217,6 +239,14 @@ Space\-separated list of search terms.
217239
For an emoji to be part of the results, its name and keywords
218240
must contain ALL the searched terms.
219241
.RE
242+
.sp
243+
\fICODEPOINT\fP
244+
.RS 4
245+
A single Unicode codepoint using the standard \fBU\fP+\fIABCD\fP
246+
notation.
247+
.RE
248+
.sp
249+
Everything is case\-insensitive.
220250
.SS "Select and accept an emoji"
221251
.sp
222252
To select an emoji, use the following keys:

man/jome.1.adoc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
= vlttng(1)
2-
:revdate: 8 April 2025
2+
:revdate: 14 April 2025
33
:docdate: {revdate}
44
:doctype: manpage
55
:manmanual: JOME
@@ -120,6 +120,8 @@ The format of a query is one of:
120120
* __TERMS__
121121
* __CAT__/
122122
* __CAT__/__TERMS__
123+
* __CODEPOINT__
124+
* __CAT__/__CODEPOINT__
123125

124126
where:
125127

@@ -132,6 +134,12 @@ __TERMS__::
132134
For an emoji to be part of the results, its name and keywords
133135
must contain ALL the searched terms.
134136

137+
__CODEPOINT__::
138+
A single Unicode codepoint using the standard **U**+__ABCD__
139+
notation.
140+
141+
Everything is case-insensitive.
142+
135143
=== Select and accept an emoji
136144

137145
To select an emoji, use the following keys:

0 commit comments

Comments
 (0)