Added utility to correctly cut text with commands.
This commit is contained in:
parent
44853e9334
commit
774da18a38
2 changed files with 19 additions and 0 deletions
|
|
@ -2348,6 +2348,20 @@ QString TextWithSpoilerCommands(const TextWithEntities &textWithEntities) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CutTextWithCommands(
|
||||||
|
QString text,
|
||||||
|
int length,
|
||||||
|
const QString &start,
|
||||||
|
const QString &stop) {
|
||||||
|
text = text.mid(0, length);
|
||||||
|
const auto lastStart = text.lastIndexOf(start);
|
||||||
|
const auto lastStop = text.lastIndexOf(stop);
|
||||||
|
const auto additional = ((lastStart == -1) || (lastStart < lastStop))
|
||||||
|
? QString()
|
||||||
|
: stop;
|
||||||
|
return text + additional + qstr("...");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace TextUtilities
|
} // namespace TextUtilities
|
||||||
|
|
||||||
EntityInText::EntityInText(
|
EntityInText::EntityInText(
|
||||||
|
|
|
||||||
|
|
@ -383,5 +383,10 @@ void SetClipboardText(
|
||||||
|
|
||||||
[[nodiscard]] QString TextWithSpoilerCommands(
|
[[nodiscard]] QString TextWithSpoilerCommands(
|
||||||
const TextWithEntities &textWithEntities);
|
const TextWithEntities &textWithEntities);
|
||||||
|
[[nodiscard]] QString CutTextWithCommands(
|
||||||
|
QString text,
|
||||||
|
int length,
|
||||||
|
const QString &start,
|
||||||
|
const QString &stop);
|
||||||
|
|
||||||
} // namespace TextUtilities
|
} // namespace TextUtilities
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue