KTextAddons

emoticonunicodeutils.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2025 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "emoticonunicodeutils.h"
8#include <QList>
9using namespace TextEmoticonsCore;
10QString EmoticonUnicodeUtils::emojiFontName()
11{
12#ifdef Q_OS_WIN
13 return QStringLiteral("Segoe UI Emoji");
14#else
15 return QStringLiteral("NotoColorEmoji");
16#endif
17}
18
19QString EmoticonUnicodeUtils::recentIdentifier()
20{
21 return QStringLiteral("recents");
22}
23
24QString EmoticonUnicodeUtils::customIdentifier()
25{
26 return QStringLiteral("customs");
27}
28
29QString EmoticonUnicodeUtils::recentName()
30{
31 return QStringLiteral("⌛️");
32}
33
34QString EmoticonUnicodeUtils::customName()
35{
36 return QStringLiteral("🖼️");
37}
38
39// input: codepoints in hex like 1f9d7-1f3fb-2640
40// output: QString with 3 ucs4 code points for the above, which is in fact 5 QChars.
41QString EmoticonUnicodeUtils::escapeUnicodeEmoji(const QString &pString)
42{
43 QString retString;
44
45 const QList<QStringView> parts = QStringView(pString).split(QLatin1Char('-'));
46 for (const QStringView &item : parts) {
47 bool ok;
48 const int part = item.toInt(&ok, 16);
49 Q_ASSERT(ok);
50 if (QChar::requiresSurrogates(part)) {
51 retString += QChar::highSurrogate(part);
52 retString += QChar::lowSurrogate(part);
53 } else {
54 retString += QChar(part);
55 }
56 }
57
58 return retString;
59}
char16_t highSurrogate(char32_t ucs4)
char16_t lowSurrogate(char32_t ucs4)
bool requiresSurrogates(char32_t ucs4)
QList< QStringView > split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:51:55 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.