Fix Text::String::isOnlyEmojiAndSpaces for empty string.

This commit is contained in:
John Preston 2023-01-30 14:10:11 +04:00
parent f2e698f220
commit 7bcca23bfe
3 changed files with 9 additions and 9 deletions

View file

@ -872,8 +872,8 @@ OnlyCustomEmoji String::toOnlyCustomEmoji() const {
return result;
}
bool String::isOnlyEmojiAndSpaces() const {
return _isOnlyEmojiAndSpaces;
bool String::hasNotEmojiAndSpaces() const {
return _hasNotEmojiAndSpaces;
}
QString String::toString(TextSelection selection) const {

View file

@ -227,7 +227,7 @@ public:
[[nodiscard]] bool isOnlyCustomEmoji() const;
[[nodiscard]] OnlyCustomEmoji toOnlyCustomEmoji() const;
[[nodiscard]] bool isOnlyEmojiAndSpaces() const;
[[nodiscard]] bool hasNotEmojiAndSpaces() const;
[[nodiscard]] const style::TextStyle *style() const {
return _st;
@ -282,7 +282,7 @@ private:
bool _hasCustomEmoji : 1 = false;
bool _isIsolatedEmoji : 1 = false;
bool _isOnlyCustomEmoji : 1 = false;
bool _isOnlyEmojiAndSpaces : 1 = false;
bool _hasNotEmojiAndSpaces : 1 = false;
QString _text;
const style::TextStyle *_st = nullptr;

View file

@ -606,7 +606,7 @@ void Parser::finalize(const TextParseOptions &options) {
_t->_hasCustomEmoji = false;
_t->_isIsolatedEmoji = true;
_t->_isOnlyCustomEmoji = true;
_t->_isOnlyEmojiAndSpaces = true;
_t->_hasNotEmojiAndSpaces = false;
auto spacesCheckFrom = uint16(-1);
const auto length = int(_t->_text.size());
for (auto &block : _t->_blocks) {
@ -618,7 +618,7 @@ void Parser::finalize(const TextParseOptions &options) {
} else if (block->lnkIndex()) {
_t->_isOnlyCustomEmoji = _t->_isIsolatedEmoji = false;
}
if (_t->_isOnlyEmojiAndSpaces) {
if (!_t->_hasNotEmojiAndSpaces) {
if (block->type() == TextBlockTText) {
if (spacesCheckFrom == uint16(-1)) {
spacesCheckFrom = block->from();
@ -628,7 +628,7 @@ void Parser::finalize(const TextParseOptions &options) {
for (auto i = spacesCheckFrom; i != checkTill; ++i) {
Assert(i < length);
if (!_t->_text[i].isSpace()) {
_t->_isOnlyEmojiAndSpaces = false;
_t->_hasNotEmojiAndSpaces = true;
break;
}
}
@ -714,12 +714,12 @@ void Parser::finalize(const TextParseOptions &options) {
if (_t->_blocks.empty() || _t->_spoiler.data) {
_t->_isIsolatedEmoji = false;
}
if (_t->_isOnlyEmojiAndSpaces && spacesCheckFrom != uint16(-1)) {
if (!_t->_hasNotEmojiAndSpaces && spacesCheckFrom != uint16(-1)) {
Assert(spacesCheckFrom < length);
for (auto i = spacesCheckFrom; i != length; ++i) {
Assert(i < length);
if (!_t->_text[i].isSpace()) {
_t->_isOnlyEmojiAndSpaces = false;
_t->_hasNotEmojiAndSpaces = true;
break;
}
}