init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
92
Telegram/lib_ui/emoji_suggestions/emoji_suggestions.h
Normal file
92
Telegram/lib_ui/emoji_suggestions/emoji_suggestions.h
Normal file
@@ -0,0 +1,92 @@
|
||||
// This file is part of Desktop App Toolkit,
|
||||
// a set of libraries for developing nice desktop applications.
|
||||
//
|
||||
// For license and copyright information please follow this link:
|
||||
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Ui {
|
||||
namespace Emoji {
|
||||
|
||||
using small = unsigned char;
|
||||
using medium = unsigned short;
|
||||
using utf16char = unsigned short;
|
||||
|
||||
static_assert(sizeof(utf16char) == 2, "Bad UTF-16 character size.");
|
||||
|
||||
class utf16string {
|
||||
public:
|
||||
utf16string() = default;
|
||||
utf16string(const utf16char *data, std::size_t size) : data_(data), size_(size) {
|
||||
}
|
||||
utf16string(const utf16string &other) = default;
|
||||
utf16string &operator=(const utf16string &other) = default;
|
||||
|
||||
const utf16char *data() const {
|
||||
return data_;
|
||||
}
|
||||
std::size_t size() const {
|
||||
return size_;
|
||||
}
|
||||
|
||||
utf16char operator[](int index) const {
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
private:
|
||||
const utf16char *data_ = nullptr;
|
||||
std::size_t size_ = 0;
|
||||
|
||||
};
|
||||
|
||||
inline bool operator==(utf16string a, utf16string b) {
|
||||
return (a.size() == b.size()) && (!a.size() || !memcmp(a.data(), b.data(), a.size() * sizeof(utf16char)));
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
using checksum = unsigned int;
|
||||
checksum countChecksum(const void *data, std::size_t size);
|
||||
|
||||
utf16string GetReplacementEmoji(utf16string replacement);
|
||||
|
||||
} // namespace internal
|
||||
|
||||
class Suggestion {
|
||||
public:
|
||||
Suggestion() = default;
|
||||
Suggestion(utf16string emoji, utf16string label, utf16string replacement) : emoji_(emoji), label_(label), replacement_(replacement) {
|
||||
}
|
||||
Suggestion(const Suggestion &other) = default;
|
||||
Suggestion &operator=(const Suggestion &other) = default;
|
||||
|
||||
utf16string emoji() const {
|
||||
return emoji_;
|
||||
}
|
||||
utf16string label() const {
|
||||
return label_;
|
||||
}
|
||||
utf16string replacement() const {
|
||||
return replacement_;
|
||||
}
|
||||
|
||||
private:
|
||||
utf16string emoji_;
|
||||
utf16string label_;
|
||||
utf16string replacement_;
|
||||
|
||||
};
|
||||
|
||||
std::vector<Suggestion> GetSuggestions(utf16string query);
|
||||
|
||||
inline utf16string GetSuggestionEmoji(utf16string replacement) {
|
||||
return internal::GetReplacementEmoji(replacement);
|
||||
}
|
||||
|
||||
int GetSuggestionMaxLength();
|
||||
|
||||
} // namespace Emoji
|
||||
} // namespace Ui
|
||||
Reference in New Issue
Block a user