]> git.lyx.org Git - lyx.git/commitdiff
FindAdv: Fix search for '}'
authorKornel Benko <kornel@lyx.org>
Tue, 19 Apr 2022 21:28:27 +0000 (23:28 +0200)
committerKornel Benko <kornel@lyx.org>
Tue, 19 Apr 2022 21:28:27 +0000 (23:28 +0200)
Problem occured if
1.) not using regex and
2.) search without format and
3.) the search pattern ended with '}'.

then this last char '}' in the search pattern was discarded.

src/lyxfind.cpp

index 69e740d470e51730008b9fe88a8f89f7582ec868..6fead6b8357d3afb4e7669698fa4c8e43c9510bd 100644 (file)
@@ -3420,24 +3420,23 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with
 
 
 // Remove trailing closure of math, macros and environments, so to catch parts of them.
-static int identifyClosing(string & t)
+static void identifyClosing(string & t, bool ignoreformat)
 {
-       int open_braces = 0;
        do {
                LYXERR(Debug::FINDVERBOSE, "identifyClosing(): t now is '" << t << "'");
                if (regex_replace(t, t, "(.*[^\\\\])\\$$", "$1"))
                        continue;
                if (regex_replace(t, t, "(.*[^\\\\])\\\\\\]$", "$1"))
                        continue;
-               if (regex_replace(t, t, "(.*[^\\\\])\\\\end\\{[a-zA-Z_]*\\*?\\}$", "$1"))
-                       continue;
-               if (regex_replace(t, t, "(.*[^\\\\])\\}$", "$1")) {
-                       ++open_braces;
+               if (regex_replace(t, t, "(.*[^\\\\])\\\\end\\{[a-zA-Z_]+\\*?\\}$", "$1"))
                        continue;
+               if (! ignoreformat) {
+                       if (regex_replace(t, t, "(.*[^\\\\])\\}$", "$1"))
+                               continue;
                }
                break;
        } while (true);
-       return open_braces;
+       return;
 }
 
 static int num_replaced = 0;
@@ -3564,7 +3563,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt)
        }
        opt.matchAtStart = false;
        if (!use_regexp) {
-               identifyClosing(par_as_string); // Removes math closings ($, ], ...) at end of string
+               identifyClosing(par_as_string, opt.ignoreformat); // Removes math closings ($, ], ...) at end of string
                if (opt.ignoreformat) {
                        lead_size = 0;
                }