Improved utility to clean text from text commands except spoilers.
This commit is contained in:
parent
8331322c20
commit
fc6c3841ee
2 changed files with 10 additions and 2 deletions
|
|
@ -1293,9 +1293,17 @@ bool IsValidTopDomain(const QString &protocol) {
|
|||
return list.contains(base::crc32(protocol.constData(), protocol.size() * sizeof(QChar)));
|
||||
}
|
||||
|
||||
QString Clean(const QString &text) {
|
||||
QString Clean(const QString &text, bool keepSpoilers) {
|
||||
auto result = text;
|
||||
for (auto s = text.unicode(), ch = s, e = text.unicode() + text.size(); ch != e; ++ch) {
|
||||
if (keepSpoilers && (*ch == TextCommand)) {
|
||||
if ((*(ch + 1) == TextCommandSpoiler)
|
||||
|| (*(ch - 1) == TextCommandSpoiler)
|
||||
|| (*(ch + 1) == TextCommandNoSpoiler)
|
||||
|| (*(ch - 1) == TextCommandNoSpoiler)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (*ch == TextCommand) {
|
||||
result[int(ch - s)] = QChar::Space;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ QString MarkdownSpoilerGoodBefore();
|
|||
QString MarkdownSpoilerBadAfter();
|
||||
|
||||
// Text preprocess.
|
||||
QString Clean(const QString &text);
|
||||
QString Clean(const QString &text, bool keepSpoilers = false);
|
||||
QString EscapeForRichParsing(const QString &text);
|
||||
QString SingleLine(const QString &text);
|
||||
TextWithEntities SingleLine(const TextWithEntities &text);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue