summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-10-25 17:15:16 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-10-25 17:15:16 +0300
commitec3ca17d4e339c0db3425544a772497e924be0de (patch)
treee5012f37617e901281fba467733c945820a4b634
parentbb08cc53238ad5f17a28235cb6017fc1f1ba1c8d (diff)
fixes #3751 (SmileyAdd: перестали работать смайлы)
-rw-r--r--plugins/SmileyAdd/src/smileyroutines.cpp62
1 files changed, 35 insertions, 27 deletions
diff --git a/plugins/SmileyAdd/src/smileyroutines.cpp b/plugins/SmileyAdd/src/smileyroutines.cpp
index 8622599db2..b178574d6e 100644
--- a/plugins/SmileyAdd/src/smileyroutines.cpp
+++ b/plugins/SmileyAdd/src/smileyroutines.cpp
@@ -38,6 +38,15 @@ static int CompareSmileys(const SmileyLookup::SmileyLocType *p1, const SmileyLoo
return (int)p1->pos - (int)p2->pos;
}
+static bool HasOverlap(const CHARRANGE &loc, SmileysQueueType &smllist)
+{
+ for (auto &it : smllist)
+ if (it->loc.cpMin <= loc.cpMin && it->loc.cpMax >= loc.cpMax)
+ return true;
+
+ return false;
+}
+
static void LookupAllSmileysWorker(
SmileyPackType *smileyPack,
SmileyPackCType *smileyCPack,
@@ -86,45 +95,44 @@ static void LookupAllSmileysWorker(
const wchar_t *textSmlStart = lpstrText + pCurr.pos;
const wchar_t *textSmlEnd = textSmlStart + pCurr.len;
- ReplaceSmileyType *dat = new ReplaceSmileyType;
+ ReplaceSmileyType dat;
// check if leading space exist
const wchar_t *prech = _wcsdec(textToSearch, textSmlStart);
- dat->ldspace = prech != nullptr ? iswspace(*prech) != 0 : smloff == 0;
+ dat.ldspace = prech != nullptr ? iswspace(*prech) != 0 : smloff == 0;
if (i > 0 && smileys[i - 1].pos + smileys[i - 1].len == smloff)
- dat->ldspace = true;
+ dat.ldspace = true;
// check if trailing space exist
- dat->trspace = *textSmlEnd == 0 || iswspace(*textSmlEnd);
+ dat.trspace = *textSmlEnd == 0 || iswspace(*textSmlEnd);
if (i < smileys.getCount() - 1 && pCurr.pos + pCurr.len == smileys[i + 1].pos)
- dat->trspace = true;
+ dat.trspace = true;
// compute text location in RichEdit
- dat->loc.cpMin = (long)_wcsncnt(textToSearch, pCurr.pos - smloff) + numCharsSoFar;
- dat->loc.cpMax = numCharsSoFar = (long)_wcsncnt(textSmlStart, pCurr.len) + dat->loc.cpMin;
-
- if (!opt.EnforceSpaces || (dat->ldspace && dat->trspace)) {
- dat->ldspace |= !opt.SurroundSmileyWithSpaces;
- dat->trspace |= !opt.SurroundSmileyWithSpaces;
-
- if (smileyCPack && smileyCPack->GetSmileyLookup().find(pCurr.sml)) {
- dat->smlc = smileyCPack->GetSmiley(pCurr.sml->GetIndex());
- dat->sml = nullptr;
- }
- else {
- dat->sml = smileyPack->GetSmiley(pCurr.sml->GetIndex());
- dat->smlc = nullptr;
- }
+ dat.loc.cpMin = (long)_wcsncnt(textToSearch, pCurr.pos - smloff) + numCharsSoFar;
+ dat.loc.cpMax = numCharsSoFar = (long)_wcsncnt(textSmlStart, pCurr.len) + dat.loc.cpMin;
+ if (!HasOverlap(dat.loc, smllist)) {
+ if (!opt.EnforceSpaces || (dat.ldspace && dat.trspace)) {
+ dat.ldspace |= !opt.SurroundSmileyWithSpaces;
+ dat.trspace |= !opt.SurroundSmileyWithSpaces;
+
+ if (smileyCPack && smileyCPack->GetSmileyLookup().find(pCurr.sml)) {
+ dat.smlc = smileyCPack->GetSmiley(pCurr.sml->GetIndex());
+ dat.sml = nullptr;
+ }
+ else {
+ dat.sml = smileyPack->GetSmiley(pCurr.sml->GetIndex());
+ dat.smlc = nullptr;
+ }
- if (dat->sml != nullptr || dat->smlc != nullptr) {
- // First smiley found record it
- smllist.insert(dat);
- if (firstOnly)
- return;
+ if (dat.sml != nullptr || dat.smlc != nullptr) {
+ // First smiley found record it
+ smllist.insert(new ReplaceSmileyType(dat));
+ if (firstOnly)
+ return;
+ }
}
- else delete dat;
}
- else delete dat;
// Advance string pointer to search for the next smiley
smloff = int(pCurr.pos + pCurr.len);