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; return result;
} }
bool String::isOnlyEmojiAndSpaces() const { bool String::hasNotEmojiAndSpaces() const {
return _isOnlyEmojiAndSpaces; return _hasNotEmojiAndSpaces;
} }
QString String::toString(TextSelection selection) const { QString String::toString(TextSelection selection) const {

View file

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

View file

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