Mercurial > vim
comparison src/search.c @ 6903:dd923806ae3b v7.4.771
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)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 10 Jul 2015 14:43:35 +0200 |
parents | 24e0b6dd52e1 |
children | 1e621b31948b |
comparison
equal
deleted
inserted
replaced
6902:f3baff59f22a | 6903:dd923806ae3b |
---|---|
546 lpos_T matchpos; | 546 lpos_T matchpos; |
547 int loop; | 547 int loop; |
548 pos_T start_pos; | 548 pos_T start_pos; |
549 int at_first_line; | 549 int at_first_line; |
550 int extra_col; | 550 int extra_col; |
551 int start_char_len; | |
551 int match_ok; | 552 int match_ok; |
552 long nmatched; | 553 long nmatched; |
553 int submatch = 0; | 554 int submatch = 0; |
554 int first_match = TRUE; | 555 int first_match = TRUE; |
555 int save_called_emsg = called_emsg; | 556 int save_called_emsg = called_emsg; |
572 do /* loop for count */ | 573 do /* loop for count */ |
573 { | 574 { |
574 /* When not accepting a match at the start position set "extra_col" to | 575 /* When not accepting a match at the start position set "extra_col" to |
575 * a non-zero value. Don't do that when starting at MAXCOL, since | 576 * a non-zero value. Don't do that when starting at MAXCOL, since |
576 * MAXCOL + 1 is zero. */ | 577 * MAXCOL + 1 is zero. */ |
577 if ((options & SEARCH_START) || pos->col == MAXCOL) | 578 if (pos->col == MAXCOL) |
578 extra_col = 0; | 579 start_char_len = 0; |
579 #ifdef FEAT_MBYTE | 580 #ifdef FEAT_MBYTE |
580 /* Watch out for the "col" being MAXCOL - 2, used in a closed fold. */ | 581 /* Watch out for the "col" being MAXCOL - 2, used in a closed fold. */ |
581 else if (dir != BACKWARD && has_mbyte | 582 else if (has_mbyte |
582 && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count | 583 && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count |
583 && pos->col < MAXCOL - 2) | 584 && pos->col < MAXCOL - 2) |
584 { | 585 { |
585 ptr = ml_get_buf(buf, pos->lnum, FALSE) + pos->col; | 586 ptr = ml_get_buf(buf, pos->lnum, FALSE) + pos->col; |
586 if (*ptr == NUL) | 587 if (*ptr == NUL) |
587 extra_col = 1; | 588 start_char_len = 1; |
588 else | 589 else |
589 extra_col = (*mb_ptr2len)(ptr); | 590 start_char_len = (*mb_ptr2len)(ptr); |
590 } | 591 } |
591 #endif | 592 #endif |
592 else | 593 else |
593 extra_col = 1; | 594 start_char_len = 1; |
595 if (dir == FORWARD) | |
596 { | |
597 if (options & SEARCH_START) | |
598 extra_col = 0; | |
599 else | |
600 extra_col = start_char_len; | |
601 } | |
602 else | |
603 { | |
604 if (options & SEARCH_START) | |
605 extra_col = start_char_len; | |
606 else | |
607 extra_col = 0; | |
608 } | |
594 | 609 |
595 start_pos = *pos; /* remember start pos for detecting no match */ | 610 start_pos = *pos; /* remember start pos for detecting no match */ |
596 found = 0; /* default: not found */ | 611 found = 0; /* default: not found */ |
597 at_first_line = TRUE; /* default: start in first line */ | 612 at_first_line = TRUE; /* default: start in first line */ |
598 if (pos->lnum == 0) /* correct lnum for when starting in line 0 */ | 613 if (pos->lnum == 0) /* correct lnum for when starting in line 0 */ |
777 ? (lnum + regmatch.endpos[0].lnum | 792 ? (lnum + regmatch.endpos[0].lnum |
778 < start_pos.lnum | 793 < start_pos.lnum |
779 || (lnum + regmatch.endpos[0].lnum | 794 || (lnum + regmatch.endpos[0].lnum |
780 == start_pos.lnum | 795 == start_pos.lnum |
781 && (int)regmatch.endpos[0].col - 1 | 796 && (int)regmatch.endpos[0].col - 1 |
782 + extra_col | 797 < (int)start_pos.col |
783 <= (int)start_pos.col)) | 798 + extra_col)) |
784 : (lnum + regmatch.startpos[0].lnum | 799 : (lnum + regmatch.startpos[0].lnum |
785 < start_pos.lnum | 800 < start_pos.lnum |
786 || (lnum + regmatch.startpos[0].lnum | 801 || (lnum + regmatch.startpos[0].lnum |
787 == start_pos.lnum | 802 == start_pos.lnum |
788 && (int)regmatch.startpos[0].col | 803 && (int)regmatch.startpos[0].col |
789 + extra_col | 804 < (int)start_pos.col |
790 <= (int)start_pos.col)))) | 805 + extra_col)))) |
791 { | 806 { |
792 match_ok = TRUE; | 807 match_ok = TRUE; |
793 matchpos = regmatch.startpos[0]; | 808 matchpos = regmatch.startpos[0]; |
794 endpos = regmatch.endpos[0]; | 809 endpos = regmatch.endpos[0]; |
795 # ifdef FEAT_EVAL | 810 # ifdef FEAT_EVAL |