From 895aa9cd0f98f703b0563f65fc3c8f079307536e Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Thu, 12 May 2022 13:22:21 +0200 Subject: [PATCH] FindAdv: Remove invalid closings If the searched area contains deleted parts, there may be more closing as opening parentheses in latex output. We have to remove them before further processing. --- src/lyxfind.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 8c609a7980..601f319100 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -1435,6 +1435,7 @@ public: void removeAccents(); void setForDefaultLang(KeyInfo const & defLang) const; int findclosing(int start, int end, char up, char down, int repeat); + void removeInvalidClosings(void); void handleParentheses(int lastpos, bool closingAllowed); bool hasTitle; // Number of disabled language specs up @@ -2241,6 +2242,27 @@ int Intervall::findclosing(int start, int end, char up = '{', char down = '}', i return end; } +void Intervall::removeInvalidClosings(void) +{ + // this can happen, if there are deleted parts + int skip = 0; + int depth = 0; + for (unsigned i = 0; i < par.size(); i += 1 + skip) { + char c = par[i]; + skip = 0; + if (c == '\\') skip = 1; + else if (c == '{') + depth++; + else if (c == '}') { + if (depth == 0) { + addIntervall(i, i+1); + LYXERR(Debug::FINDVERBOSE, "removed invalid closing '}' at " << i); + } + else + --depth; + } + } +} class MathInfo { class MathEntry { public: @@ -2328,6 +2350,7 @@ void LatexInfo::buildEntries(bool isPatternString) static bool removeMathHull = false; interval_.removeAccents(); + interval_.removeInvalidClosings(); for (sregex_iterator itmath(interval_.par.begin(), interval_.par.end(), rmath), end; itmath != end; ++itmath) { submath = *itmath;