]> git.lyx.org Git - features.git/commitdiff
FindAdv: Amend 6c735efb: Resolve some conflicts regex vs. math meaning of '$'
authorKornel Benko <kornel@lyx.org>
Fri, 13 May 2022 10:00:47 +0000 (12:00 +0200)
committerKornel Benko <kornel@lyx.org>
Fri, 13 May 2022 10:00:47 +0000 (12:00 +0200)
src/lyxfind.cpp

index fddf398377d10cd11ca068f97c2229d63bb8b6b1..40d20c40da224c2310d44fda5b28ae57803ece5a 100644 (file)
@@ -892,6 +892,7 @@ string correctRegex(string t, bool withformat)
                buildAccentsMap();
 
        //LYXERR0("correctRegex input '" << t << "'");
+       int skip = 0;
        for (sregex_iterator it(t.begin(), t.end(), wordre), end; it != end; ++it) {
                sub = *it;
                string replace;
@@ -908,6 +909,10 @@ string correctRegex(string t, bool withformat)
                                                replace = "";
                                                backslashed = true;
                                        }
+                                       else if (withformat && next[0] == '$') {
+                                               replace = accents["lyxdollar"];
+                                               skip = 1;       // Skip following '$'
+                                       }
                                }
                        }
                        else if (sub.str(4) == "mathcircumflex")
@@ -960,7 +965,8 @@ string correctRegex(string t, bool withformat)
                if (lastpos < (size_t) sub.position(2))
                        s += std::regex_replace(t.substr(lastpos, sub.position(2) - lastpos), protectedSpace, R"( )");
                s += replace;
-               lastpos = sub.position(2) + sub.length(2);
+               lastpos = sub.position(2) + sub.length(2) + skip;
+               skip = 0;
        }
        if (lastpos == 0)
                s = std::regex_replace(t, protectedSpace, R"( )");
@@ -4069,14 +4075,14 @@ static string convertLF2Space(docstring const & s, bool ignore_format)
                                // Replace all other \n with spaces
                                t.replace(pos, 1, " ");
                        }
-               }
-               if (!ignore_format) {
-                       size_t count = 0;
-                       while ((pos > count + 1) && (t[pos - 1 -count] == '%')) {
-                               count++;
-                       }
-                       if (count > 0) {
-                               t.replace(pos - count, count, "");
+                       if (!ignore_format) {
+                               size_t count = 0;
+                               while ((pos > count + 1) && (t[pos - 1 -count] == '%')) {
+                                       count++;
+                               }
+                               if (count > 0) {
+                                       t.replace(pos - count, count, "");
+                               }
                        }
                }
        }