From ec3ca17d4e339c0db3425544a772497e924be0de Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 25 Oct 2023 17:15:16 +0300 Subject: =?UTF-8?q?fixes=20#3751=20(SmileyAdd:=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BB=D0=B8=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D1=81=D0=BC=D0=B0=D0=B9=D0=BB=D1=8B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/SmileyAdd/src/smileyroutines.cpp | 62 ++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'plugins') 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); -- cgit v1.2.3