Added storage of surrogate pairs count to every emoji.
This commit is contained in:
parent
5d7445ce7d
commit
3c8cf5f5db
2 changed files with 61 additions and 23 deletions
|
|
@ -373,6 +373,24 @@ void ClearUniversalChecked() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] uint8 EmojiSurrogatePairs(const QString &e) {
|
||||||
|
if (e.size() > 1) {
|
||||||
|
auto count = uint8(0);
|
||||||
|
const auto begin = e.data();
|
||||||
|
auto ch = begin;
|
||||||
|
for (const auto end = begin + e.size(); ch != end; ++ch) {
|
||||||
|
if ((ch + 1 < end)
|
||||||
|
&& ch->isHighSurrogate()
|
||||||
|
&& (ch + 1)->isLowSurrogate()) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
@ -627,6 +645,22 @@ int GetSizeTouchbar() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
One::One(
|
||||||
|
const QString &id,
|
||||||
|
EmojiPtr original,
|
||||||
|
uint32 index,
|
||||||
|
bool hasPostfix,
|
||||||
|
bool colorizable,
|
||||||
|
const CreationTag &)
|
||||||
|
: _id(id)
|
||||||
|
, _original(original)
|
||||||
|
, _index(index)
|
||||||
|
, _hasPostfix(hasPostfix)
|
||||||
|
, _colorizable(colorizable)
|
||||||
|
, _surrogatePairs(EmojiSurrogatePairs(text())) {
|
||||||
|
Expects(!_colorizable || !colored());
|
||||||
|
}
|
||||||
|
|
||||||
int One::variantsCount() const {
|
int One::variantsCount() const {
|
||||||
return hasVariants() ? 5 : 0;
|
return hasVariants() ? 5 : 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,66 +51,70 @@ class One {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
One(One &&other) = default;
|
One(One &&other) = default;
|
||||||
One(const QString &id, EmojiPtr original, uint32 index, bool hasPostfix, bool colorizable, const CreationTag &)
|
One(
|
||||||
: _id(id)
|
const QString &id,
|
||||||
, _original(original)
|
EmojiPtr original,
|
||||||
, _index(index)
|
uint32 index,
|
||||||
, _hasPostfix(hasPostfix)
|
bool hasPostfix,
|
||||||
, _colorizable(colorizable) {
|
bool colorizable,
|
||||||
Expects(!_colorizable || !colored());
|
const CreationTag &);
|
||||||
}
|
|
||||||
|
|
||||||
QString id() const {
|
[[nodiscard]] QString id() const {
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
QString text() const {
|
[[nodiscard]] QString text() const {
|
||||||
return hasPostfix() ? (_id + QChar(kPostfix)) : _id;
|
return hasPostfix() ? (_id + QChar(kPostfix)) : _id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool colored() const {
|
[[nodiscard]] bool colored() const {
|
||||||
return (_original != nullptr);
|
return (_original != nullptr);
|
||||||
}
|
}
|
||||||
EmojiPtr original() const {
|
[[nodiscard]] EmojiPtr original() const {
|
||||||
return _original ? _original : this;
|
return _original ? _original : this;
|
||||||
}
|
}
|
||||||
QString nonColoredId() const {
|
[[nodiscard]] QString nonColoredId() const {
|
||||||
return original()->id();
|
return original()->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasPostfix() const {
|
[[nodiscard]] bool hasPostfix() const {
|
||||||
return _hasPostfix;
|
return _hasPostfix;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasVariants() const {
|
[[nodiscard]] bool hasVariants() const {
|
||||||
return _colorizable || colored();
|
return _colorizable || colored();
|
||||||
}
|
}
|
||||||
int variantsCount() const;
|
[[nodiscard]] int variantsCount() const;
|
||||||
int variantIndex(EmojiPtr variant) const;
|
[[nodiscard]] int variantIndex(EmojiPtr variant) const;
|
||||||
EmojiPtr variant(int index) const;
|
[[nodiscard]] EmojiPtr variant(int index) const;
|
||||||
|
|
||||||
int index() const {
|
[[nodiscard]] int index() const {
|
||||||
return _index;
|
return _index;
|
||||||
}
|
}
|
||||||
int sprite() const {
|
[[nodiscard]] int sprite() const {
|
||||||
return int(_index >> 9);
|
return int(_index >> 9);
|
||||||
}
|
}
|
||||||
int row() const {
|
[[nodiscard]] int row() const {
|
||||||
return int((_index >> 5) & 0x0FU);
|
return int((_index >> 5) & 0x0FU);
|
||||||
}
|
}
|
||||||
int column() const {
|
[[nodiscard]] int column() const {
|
||||||
return int(_index & 0x1FU);
|
return int(_index & 0x1FU);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString toUrl() const {
|
[[nodiscard]] QString toUrl() const {
|
||||||
return "emoji://e." + QString::number(index());
|
return "emoji://e." + QString::number(index());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] uint8 surrogatePairs() const {
|
||||||
|
return _surrogatePairs;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString _id;
|
const QString _id;
|
||||||
const EmojiPtr _original = nullptr;
|
const EmojiPtr _original = nullptr;
|
||||||
const uint32 _index = 0;
|
const uint32 _index = 0;
|
||||||
const bool _hasPostfix = false;
|
const bool _hasPostfix = false;
|
||||||
const bool _colorizable = false;
|
const bool _colorizable = false;
|
||||||
|
const uint8 _surrogatePairs;
|
||||||
|
|
||||||
friend void internal::Init();
|
friend void internal::Init();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue