]> granicus.if.org Git - vim/commitdiff
patch 7.4.771 v7.4.771
authorBram Moolenaar <Bram@vim.org>
Fri, 10 Jul 2015 12:43:35 +0000 (14:43 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 10 Jul 2015 12:43:35 +0000 (14:43 +0200)
Problem:    Search does not handle multi-byte character at the start position
            correctly.
Solution:   Take byte size of character into account. (Yukihiro Nakadaira)

src/search.c
src/testdir/Make_amiga.mak
src/testdir/Make_dos.mak
src/testdir/Make_ming.mak
src/testdir/Make_os2.mak
src/testdir/Make_vms.mms
src/testdir/Makefile
src/version.c

index 7022870c4c91815a67caa6499e2a9119706f1138..c9614ea525f0abf26798e177820441195c540caf 100644 (file)
@@ -548,6 +548,7 @@ searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum, tm)
     pos_T      start_pos;
     int                at_first_line;
     int                extra_col;
+    int                start_char_len;
     int                match_ok;
     long       nmatched;
     int                submatch = 0;
@@ -574,23 +575,37 @@ searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum, tm)
        /* When not accepting a match at the start position set "extra_col" to
         * a non-zero value.  Don't do that when starting at MAXCOL, since
         * MAXCOL + 1 is zero. */
-       if ((options & SEARCH_START) || pos->col == MAXCOL)
-           extra_col = 0;
+       if (pos->col == MAXCOL)
+           start_char_len = 0;
 #ifdef FEAT_MBYTE
        /* Watch out for the "col" being MAXCOL - 2, used in a closed fold. */
-       else if (dir != BACKWARD && has_mbyte
-                    && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count
-                                                    && pos->col < MAXCOL - 2)
+       else if (has_mbyte
+                   && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count
+                                                   && pos->col < MAXCOL - 2)
        {
            ptr = ml_get_buf(buf, pos->lnum, FALSE) + pos->col;
            if (*ptr == NUL)
-               extra_col = 1;
+               start_char_len = 1;
            else
-               extra_col = (*mb_ptr2len)(ptr);
+               start_char_len = (*mb_ptr2len)(ptr);
        }
 #endif
        else
-           extra_col = 1;
+           start_char_len = 1;
+       if (dir == FORWARD)
+       {
+           if (options & SEARCH_START)
+               extra_col = 0;
+           else
+               extra_col = start_char_len;
+       }
+       else
+       {
+           if (options & SEARCH_START)
+               extra_col = start_char_len;
+           else
+               extra_col = 0;
+       }
 
        start_pos = *pos;       /* remember start pos for detecting no match */
        found = 0;              /* default: not found */
@@ -779,15 +794,15 @@ searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum, tm)
                                        || (lnum + regmatch.endpos[0].lnum
                                                             == start_pos.lnum
                                             && (int)regmatch.endpos[0].col - 1
-                                                                  + extra_col
-                                                       <= (int)start_pos.col))
+                                                       < (int)start_pos.col
+                                                               + extra_col))
                                    : (lnum + regmatch.startpos[0].lnum
                                                              < start_pos.lnum
                                        || (lnum + regmatch.startpos[0].lnum
                                                             == start_pos.lnum
                                             && (int)regmatch.startpos[0].col
-                                                                  + extra_col
-                                                     <= (int)start_pos.col))))
+                                                     < (int)start_pos.col
+                                                             + extra_col))))
                            {
                                match_ok = TRUE;
                                matchpos = regmatch.startpos[0];
index 5d80c4baa44c591f338159b082c8e72322d3da97..eba28f83e8be39968b0556d7aaef86fcb0745add 100644 (file)
@@ -57,6 +57,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
                test_perl.out \
                test_qf_title.out \
                test_ruby.out \
+               test_search_mbyte.out \
                test_set.out \
                test_signs.out \
                test_textobjects.out \
@@ -205,6 +206,7 @@ test_options.out: test_options.in
 test_perl.out: test_perl.in
 test_qf_title.out: test_qf_title.in
 test_ruby.out: test_ruby.in
+test_search_mbyte.out: test_search_mbyte.in
 test_set.out: test_set.in
 test_signs.out: test_signs.in
 test_textobjects.out: test_textobjects.in
index 219b4bc9bceada215981f7b623df9bc6f246b9ed..eecb7354d9a28019a71432cdb30db67d72ddeaf6 100644 (file)
@@ -56,6 +56,7 @@ SCRIPTS =     test3.out test4.out test5.out test6.out test7.out \
                test_perl.out \
                test_qf_title.out \
                test_ruby.out \
+               test_search_mbyte.out \
                test_set.out \
                test_signs.out \
                test_textobjects.out \
index ba28cb5f6f7ad730b2cccd74627c6bdfa6cf851e..29d931d1e41e7ae8a72bda0e721981df2d1d9e4c 100644 (file)
@@ -78,6 +78,7 @@ SCRIPTS =     test3.out test4.out test5.out test6.out test7.out \
                test_perl.out \
                test_qf_title.out \
                test_ruby.out \
+               test_search_mbyte.out \
                test_set.out \
                test_signs.out \
                test_textobjects.out \
index 52addeef046679ef3d0d5a3ab2b75e38792d7ad5..f473d8983c1a1a9019f73180c13a893c0f177fce 100644 (file)
@@ -58,6 +58,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
                test_perl.out \
                test_qf_title.out \
                test_ruby.out \
+               test_search_mbyte.out \
                test_set.out \
                test_signs.out \
                test_textobjects.out \
index 6d1f73b460167ff8108413b418fdaeaf64fd7ad5..437f9b1a210e1633579a135a077273e40c734626 100644 (file)
@@ -4,7 +4,7 @@
 # Authors:     Zoltan Arpadffy, <arpadffy@polarhome.com>
 #              Sandor Kopanyi,  <sandor.kopanyi@mailbox.hu>
 #
-# Last change:  2015 Jun 19
+# Last change:  2015 Jul 10
 #
 # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
 # Edit the lines in the Configuration section below to select.
@@ -117,6 +117,7 @@ SCRIPT = test1.out  test2.out  test3.out  test4.out  test5.out  \
         test_perl.out \
         test_qf_title.out \
         test_ruby.out \
+        test_search_mbyte.out \
         test_set.out \
         test_signs.out \
         test_textobjects.out \
index f0a21387022a244dfb4c4f44b0845cf117aa2f19..656a744519875c00ecbcf61e218020440676775f 100644 (file)
@@ -54,6 +54,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
                test_perl.out \
                test_qf_title.out \
                test_ruby.out \
+               test_search_mbyte.out \
                test_set.out \
                test_signs.out \
                test_textobjects.out \
index 3e0984585620e0d0acdbeeee382be0c0a963569f..57740cf379b21c3a82d206fe6740aaa84cbb1588 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    771,
 /**/
     770,
 /**/