commit 96f9c8fb19a75e35e274e9621ad0207e2d0662ca
Author: Kornel Benko <[email protected]>
Date:   Mon Jan 18 16:06:40 2021 +0100

    FindAdv: Amend2 dacd2c45: Handle search for '{' and '}'
    
    Allow for using 'a{2,7}' to find 2 to 7 consecutive chars 'a'
---
 src/lyxfind.cpp |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index d2c9891..ab20921 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -769,6 +769,7 @@ string correctRegex(string t, bool withformat)
        regex wordre("(\\\\)*(\\\\((backslash|mathcircumflex) 
?|[\\[\\]\\{\\}]))");
        size_t lastpos = 0;
        smatch sub;
+       bool backslashed = false;
        for (sregex_iterator it(t.begin(), t.end(), wordre), end; it != end; 
++it) {
                sub = *it;
                string replace;
@@ -779,21 +780,30 @@ string correctRegex(string t, bool withformat)
                        if (sub.str(4) == "backslash") {
                                replace = "\\";
                                if (withformat) {
+                                       // tranforms '\backslash \{' into '\{'
+                                       // and '\{' into '{'
                                        sregex_iterator it2 = it;
                                        ++it2;
                                        smatch sub2 = *it2;
-                                       if (sub2.str(3) == "{")
-                                               replace = "";
-                                       else if (sub2.str(3) == "}")
+                                       if ((sub2.str(3) == "{") ||  
(sub2.str(3) == "}")) {
                                                replace = "";
+                                               backslashed = true;
+                                       }
                                }
                        }
                        else if (sub.str(4) == "mathcircumflex")
                                replace = "^";
-                       else if (withformat && (sub.str(3) == "{"))
-                               replace = accents["braceleft"];
-                       else if (withformat && (sub.str(3) == "}"))
-                               replace = accents["braceright"];
+                       else if (backslashed) {
+                               backslashed = false;
+                               if (withformat && (sub.str(3) == "{"))
+                                       replace = accents["braceleft"];
+                               else if (withformat && (sub.str(3) == "}"))
+                                       replace = accents["braceright"];
+                               else {
+                                       // else part should not exist
+                                       LASSERT(1, /**/);
+                               }
+                       }
                        else
                                replace = sub.str(3);
                }
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to