]> git.neil.brown.name Git - edlib.git/commitdiff
Quote regex chars when they are included from doc into search string.
authorNeilBrown <neil@brown.name>
Tue, 1 Dec 2015 20:53:00 +0000 (07:53 +1100)
committerNeilBrown <neil@brown.name>
Tue, 1 Dec 2015 20:53:00 +0000 (07:53 +1100)
Also handle unicode search properly.

Signed-off-by: NeilBrown <neil@brown.name>
emacs-search.c
rexel.c

index d48ff8354f1d9978dcb9085b2c614cff5348016c..4ecef74778ef3679062784cc406329b1aef652d4 100644 (file)
@@ -102,6 +102,8 @@ DEF_CMD(search_add)
        struct doc *d = doc_from_pane(esi->target);
        wint_t wch;
        char b[5];
+       mbstate_t ps = {0};
+       int l;
        struct cmd_info ci2 = {0};
 
        if (!d)
@@ -121,8 +123,12 @@ DEF_CMD(search_add)
                        return 1;
                }
                /* FIXME utf-8! and quote regexp chars */
-               b[0] = wch;
-               b[1] = 0;
+               if (strchr("|*+?{}()?^$\\", wch)) {
+                       b[0] = '\\';
+                       l = wcrtomb(b+1, wch, &ps) + 1;
+               } else
+                       l = wcrtomb(b, wch, &ps);
+               b[l] = 0;
                ci2.key = "Replace";
                ci2.str = b;
                ci2.numeric = 1;
diff --git a/rexel.c b/rexel.c
index 329c7cbf407b40eb07c150d6ceda84d88bc83189..de38803b804939adeb92021e2ad1bb39315693e3 100644 (file)
--- a/rexel.c
+++ b/rexel.c
@@ -916,7 +916,7 @@ static int parse_atom(struct parse_state *st)
                st->patn++;
                ch = *st->patn;
                switch (ch) {
-                       /* These just fall through are are interpreted literally */
+                       /* These just fall through and are interpreted literally */
                case '^':
                case '.':
                case '[':
@@ -928,6 +928,7 @@ static int parse_atom(struct parse_state *st)
                case '+':
                case '?':
                case '{':
+               case '}':
                case '\\':
                        break;
                        /* These are simple translations */