Files
tdesktop/Telegram/lib_ui/ui/text/text_variant.cpp
allhaileris afb81b8278
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
init
2026-02-16 15:50:16 +03:00

61 lines
1.9 KiB
C++

// 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
//
#include "ui/text/text_variant.h"
namespace v::text {
bool is_plain(const data &d) {
return v::is<v::null_t>(d)
|| v::is<QString>(d)
|| v::is<rpl::producer<QString>>(d);
}
bool is_marked(const data &d) {
return !is_plain(d);
}
rpl::producer<QString> take_plain(
data &&d,
rpl::producer<QString> &&fallback) {
using RplMarked = rpl::producer<TextWithEntities>;
if (v::is_null(d)) {
return std::move(fallback);
} else if (const auto ptr = std::get_if<QString>(&d)) {
return rpl::single(base::take(*ptr));
} else if (const auto ptr = std::get_if<rpl::producer<QString>>(&d)) {
return base::take(*ptr);
} else if (const auto ptr = std::get_if<TextWithEntities>(&d)) {
return rpl::single(base::take(*ptr).text);
} else if (const auto ptr = std::get_if<RplMarked>(&d)) {
return base::take(*ptr) | rpl::map([](const auto &marked) {
return marked.text;
});
}
Unexpected("Bad variant in take_plain.");
}
rpl::producer<TextWithEntities> take_marked(
data &&d,
rpl::producer<TextWithEntities> &&fallback) {
using RplMarked = rpl::producer<TextWithEntities>;
if (v::is_null(d)) {
return std::move(fallback);
} else if (const auto ptr = std::get_if<QString>(&d)) {
return rpl::single(TextWithEntities{ base::take(*ptr) });
} else if (const auto ptr = std::get_if<rpl::producer<QString>>(&d)) {
return base::take(*ptr) | rpl::map(TextWithEntities::Simple);
} else if (const auto ptr = std::get_if<TextWithEntities>(&d)) {
return rpl::single(base::take(*ptr));
} else if (const auto ptr = std::get_if<RplMarked>(&d)) {
return base::take(*ptr);
}
Unexpected("Bad variant in take_marked.");
}
} // namespace v::text