| To: vim_dev@googlegroups.com |
| Subject: Patch 7.4.771 |
| Fcc: outbox |
| From: Bram Moolenaar <Bram@moolenaar.net> |
| Mime-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| |
| |
| Patch 7.4.771 |
| Problem: Search does not handle multi-byte character at the start position |
| correctly. |
| Solution: Take byte size of character into account. (Yukihiro Nakadaira) |
| Files: 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/testdir/test_search_mbyte.in, |
| src/testdir/test_search_mbyte.ok |
| |
| |
| |
| |
| |
| *** 548,553 **** |
| --- 548,554 ---- |
| pos_T start_pos; |
| int at_first_line; |
| int extra_col; |
| + int start_char_len; |
| int match_ok; |
| long nmatched; |
| int submatch = 0; |
| |
| *** 574,596 **** |
| /* 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; |
| #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) |
| { |
| ptr = ml_get_buf(buf, pos->lnum, FALSE) + pos->col; |
| if (*ptr == NUL) |
| ! extra_col = 1; |
| else |
| ! extra_col = (*mb_ptr2len)(ptr); |
| } |
| #endif |
| else |
| ! extra_col = 1; |
| |
| start_pos = *pos; /* remember start pos for detecting no match */ |
| found = 0; /* default: not found */ |
| --- 575,611 ---- |
| /* 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 (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 (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) |
| ! start_char_len = 1; |
| else |
| ! start_char_len = (*mb_ptr2len)(ptr); |
| } |
| #endif |
| else |
| ! 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,793 **** |
| || (lnum + regmatch.endpos[0].lnum |
| == start_pos.lnum |
| && (int)regmatch.endpos[0].col - 1 |
| ! + extra_col |
| ! <= (int)start_pos.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)))) |
| { |
| match_ok = TRUE; |
| matchpos = regmatch.startpos[0]; |
| --- 794,808 ---- |
| || (lnum + regmatch.endpos[0].lnum |
| == start_pos.lnum |
| && (int)regmatch.endpos[0].col - 1 |
| ! < (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 |
| ! < (int)start_pos.col |
| ! + extra_col)))) |
| { |
| match_ok = TRUE; |
| matchpos = regmatch.startpos[0]; |
| |
| |
| |
| *** 57,62 **** |
| --- 57,63 ---- |
| test_perl.out \ |
| test_qf_title.out \ |
| test_ruby.out \ |
| + test_search_mbyte.out \ |
| test_set.out \ |
| test_signs.out \ |
| test_textobjects.out \ |
| |
| *** 205,210 **** |
| --- 206,212 ---- |
| 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 |
| |
| |
| |
| *** 56,61 **** |
| --- 56,62 ---- |
| test_perl.out \ |
| test_qf_title.out \ |
| test_ruby.out \ |
| + test_search_mbyte.out \ |
| test_set.out \ |
| test_signs.out \ |
| test_textobjects.out \ |
| |
| |
| |
| *** 78,83 **** |
| --- 78,84 ---- |
| test_perl.out \ |
| test_qf_title.out \ |
| test_ruby.out \ |
| + test_search_mbyte.out \ |
| test_set.out \ |
| test_signs.out \ |
| test_textobjects.out \ |
| |
| |
| |
| *** 58,63 **** |
| --- 58,64 ---- |
| test_perl.out \ |
| test_qf_title.out \ |
| test_ruby.out \ |
| + test_search_mbyte.out \ |
| test_set.out \ |
| test_signs.out \ |
| test_textobjects.out \ |
| |
| |
| |
| *** 4,10 **** |
| # Authors: Zoltan Arpadffy, <arpadffy@polarhome.com> |
| # Sandor Kopanyi, <sandor.kopanyi@mailbox.hu> |
| # |
| ! # Last change: 2015 Jun 19 |
| # |
| # 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. |
| --- 4,10 ---- |
| # Authors: Zoltan Arpadffy, <arpadffy@polarhome.com> |
| # Sandor Kopanyi, <sandor.kopanyi@mailbox.hu> |
| # |
| ! # 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,122 **** |
| --- 117,123 ---- |
| test_perl.out \ |
| test_qf_title.out \ |
| test_ruby.out \ |
| + test_search_mbyte.out \ |
| test_set.out \ |
| test_signs.out \ |
| test_textobjects.out \ |
| |
| |
| |
| *** 54,59 **** |
| --- 54,60 ---- |
| test_perl.out \ |
| test_qf_title.out \ |
| test_ruby.out \ |
| + test_search_mbyte.out \ |
| test_set.out \ |
| test_signs.out \ |
| test_textobjects.out \ |
| |
| |
| |
| |
| --- 1,15 ---- |
| + Test for search('multi-byte char', 'bce') |
| + |
| + STARTTEST |
| + :source small.vim |
| + :source mbyte.vim |
| + :set encoding=utf-8 |
| + :/^Test bce:/+1 |
| + :$put =search('A', 'bce', line('.')) |
| + :1;/^Results:/,$wq! test.out |
| + ENDTEST |
| + |
| + Results: |
| + |
| + Test bce: |
| + A |
| |
| |
| |
| |
| --- 1,5 ---- |
| + Results: |
| + |
| + Test bce: |
| + A |
| + 15 |
| |
| |
| |
| *** 743,744 **** |
| --- 743,746 ---- |
| { /* Add new patch number below this line */ |
| + /**/ |
| + 771, |
| /**/ |
| |
| -- |
| hundred-and-one symptoms of being an internet addict: |
| 197. Your desk collapses under the weight of your computer peripherals. |
| |
| /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ |
| /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ |
| \\\ an exciting new programming language -- http://www.Zimbu.org /// |
| \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |