]> git.lyx.org Git - features.git/commitdiff
Find: Advanced + Quick:
authorKornel Benko <kornel@lyx.org>
Fri, 8 Apr 2022 06:40:32 +0000 (08:40 +0200)
committerKornel Benko <kornel@lyx.org>
Fri, 8 Apr 2022 06:40:32 +0000 (08:40 +0200)
Expand list of quotes to include also '» « › ‹'
Enable quick find to search for quotes too

src/Paragraph.cpp
src/lyxfind.cpp

index be133b12c5cebb3788fac6622c21bbba361033b1..92bb883710f8c7e05fdfb7b6ccc5866b91343468 100644 (file)
@@ -4560,6 +4560,23 @@ void Paragraph::changeCase(BufferParams const & bparams, pos_type pos,
        }
 }
 
+static char_type matchquote(char_type in)
+{
+       switch (in) {
+               case 0x2018:
+               case 0x201a:
+               case 0x203a:
+               case 0x2039:
+                       return '\'';    // ‘ ‚ › ‹
+               case 0x00bb:
+               case 0x00ab:
+               case 0x201e:
+               case 0x201c:
+                       return '"';     // » « „ “
+               default:
+                       return in;
+       }
+}
 
 int Paragraph::find(docstring const & str, bool cs, bool mw,
                pos_type start_pos, bool del) const
@@ -4590,8 +4607,9 @@ int Paragraph::find(docstring const & str, bool cs, bool mw,
                        if (!insetstring.empty()) {
                                int const insetstringsize = insetstring.length();
                                for (int j = 0; j < insetstringsize && pos < parsize; ++i, ++j) {
-                                       if ((cs && str[i] != insetstring[j])
-                                           || (!cs && uppercase(str[i]) != uppercase(insetstring[j]))) {
+                                       char_type ij = matchquote(insetstring[j]);
+                                       if ((cs && str[i] != ij)
+                                           || (!cs && uppercase(str[i]) != uppercase(ij))) {
                                                nonmatch = true;
                                                break;
                                        }
@@ -4601,9 +4619,10 @@ int Paragraph::find(docstring const & str, bool cs, bool mw,
                }
                if (nonmatch || i == strsize)
                        break;
-               if (cs && str[i] != d->text_[pos])
+               char_type dp = matchquote(d->text_[pos]);
+               if (cs && str[i] != dp)
                        break;
-               if (!cs && uppercase(str[i]) != uppercase(d->text_[pos]))
+               if (!cs && uppercase(str[i]) != uppercase(dp))
                        break;
        }
 
index 0f02a3991615e17ae29f67ff53875847a5c0f163..c3f2b77929cd05d193646982d968528b7cb034c7 100644 (file)
@@ -913,10 +913,10 @@ string correctRegex(string t, bool withformat)
        else if (lastpos < t.length())
                s += t.substr(lastpos, t.length() - lastpos);
        // Handle quotes in regex
-       // substitute all '„', '“' with '"'
-       // and all '‚', '‘' with "\'"
-       static std::regex plainquotes { R"(„|“)" };
-       static std::regex innerquotes { R"(‚|‘)" };
+       // substitute all '„', '“', '»', '«' with '"'
+       // and all '‚', '‘', '›', '‹' with "\'"
+       static std::regex plainquotes { R"(„|“|»|«)" };
+       static std::regex innerquotes { R"(‚|‘|›|‹)" };
        t = std::regex_replace(s, plainquotes, R"(")");
        s = std::regex_replace(t, innerquotes, R"(')");
        //LYXERR0("correctRegex output '" << s << "'");