Karsten Hopp 8395f7
To: vim_dev@googlegroups.com
Karsten Hopp 8395f7
Subject: Patch 7.4.771
Karsten Hopp 8395f7
Fcc: outbox
Karsten Hopp 8395f7
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 8395f7
Mime-Version: 1.0
Karsten Hopp 8395f7
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 8395f7
Content-Transfer-Encoding: 8bit
Karsten Hopp 8395f7
------------
Karsten Hopp 8395f7
Karsten Hopp 8395f7
Patch 7.4.771
Karsten Hopp 8395f7
Problem:    Search does not handle multi-byte character at the start position
Karsten Hopp 8395f7
            correctly.
Karsten Hopp 8395f7
Solution:   Take byte size of character into account. (Yukihiro Nakadaira)
Karsten Hopp 8395f7
Files:      src/search.c, src/testdir/Make_amiga.mak,
Karsten Hopp 8395f7
            src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
Karsten Hopp 8395f7
            src/testdir/Make_os2.mak, src/testdir/Make_vms.mms,
Karsten Hopp 8395f7
            src/testdir/Makefile, src/testdir/test_search_mbyte.in,
Karsten Hopp 8395f7
            src/testdir/test_search_mbyte.ok
Karsten Hopp 8395f7
Karsten Hopp 8395f7
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/search.c	2015-03-13 15:02:46.254059251 +0100
Karsten Hopp 8395f7
--- src/search.c	2015-07-10 14:37:49.055931842 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 548,553 ****
Karsten Hopp 8395f7
--- 548,554 ----
Karsten Hopp 8395f7
      pos_T	start_pos;
Karsten Hopp 8395f7
      int		at_first_line;
Karsten Hopp 8395f7
      int		extra_col;
Karsten Hopp 8395f7
+     int		start_char_len;
Karsten Hopp 8395f7
      int		match_ok;
Karsten Hopp 8395f7
      long	nmatched;
Karsten Hopp 8395f7
      int		submatch = 0;
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 574,596 ****
Karsten Hopp 8395f7
  	/* When not accepting a match at the start position set "extra_col" to
Karsten Hopp 8395f7
  	 * a non-zero value.  Don't do that when starting at MAXCOL, since
Karsten Hopp 8395f7
  	 * MAXCOL + 1 is zero. */
Karsten Hopp 8395f7
! 	if ((options & SEARCH_START) || pos->col == MAXCOL)
Karsten Hopp 8395f7
! 	    extra_col = 0;
Karsten Hopp 8395f7
  #ifdef FEAT_MBYTE
Karsten Hopp 8395f7
  	/* Watch out for the "col" being MAXCOL - 2, used in a closed fold. */
Karsten Hopp 8395f7
! 	else if (dir != BACKWARD && has_mbyte
Karsten Hopp 8395f7
! 		     && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count
Karsten Hopp 8395f7
! 						     && pos->col < MAXCOL - 2)
Karsten Hopp 8395f7
  	{
Karsten Hopp 8395f7
  	    ptr = ml_get_buf(buf, pos->lnum, FALSE) + pos->col;
Karsten Hopp 8395f7
  	    if (*ptr == NUL)
Karsten Hopp 8395f7
! 		extra_col = 1;
Karsten Hopp 8395f7
  	    else
Karsten Hopp 8395f7
! 		extra_col = (*mb_ptr2len)(ptr);
Karsten Hopp 8395f7
  	}
Karsten Hopp 8395f7
  #endif
Karsten Hopp 8395f7
  	else
Karsten Hopp 8395f7
! 	    extra_col = 1;
Karsten Hopp 8395f7
  
Karsten Hopp 8395f7
  	start_pos = *pos;	/* remember start pos for detecting no match */
Karsten Hopp 8395f7
  	found = 0;		/* default: not found */
Karsten Hopp 8395f7
--- 575,611 ----
Karsten Hopp 8395f7
  	/* When not accepting a match at the start position set "extra_col" to
Karsten Hopp 8395f7
  	 * a non-zero value.  Don't do that when starting at MAXCOL, since
Karsten Hopp 8395f7
  	 * MAXCOL + 1 is zero. */
Karsten Hopp 8395f7
! 	if (pos->col == MAXCOL)
Karsten Hopp 8395f7
! 	    start_char_len = 0;
Karsten Hopp 8395f7
  #ifdef FEAT_MBYTE
Karsten Hopp 8395f7
  	/* Watch out for the "col" being MAXCOL - 2, used in a closed fold. */
Karsten Hopp 8395f7
! 	else if (has_mbyte
Karsten Hopp 8395f7
! 		    && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count
Karsten Hopp 8395f7
! 						    && pos->col < MAXCOL - 2)
Karsten Hopp 8395f7
  	{
Karsten Hopp 8395f7
  	    ptr = ml_get_buf(buf, pos->lnum, FALSE) + pos->col;
Karsten Hopp 8395f7
  	    if (*ptr == NUL)
Karsten Hopp 8395f7
! 		start_char_len = 1;
Karsten Hopp 8395f7
  	    else
Karsten Hopp 8395f7
! 		start_char_len = (*mb_ptr2len)(ptr);
Karsten Hopp 8395f7
  	}
Karsten Hopp 8395f7
  #endif
Karsten Hopp 8395f7
  	else
Karsten Hopp 8395f7
! 	    start_char_len = 1;
Karsten Hopp 8395f7
! 	if (dir == FORWARD)
Karsten Hopp 8395f7
! 	{
Karsten Hopp 8395f7
! 	    if (options & SEARCH_START)
Karsten Hopp 8395f7
! 		extra_col = 0;
Karsten Hopp 8395f7
! 	    else
Karsten Hopp 8395f7
! 		extra_col = start_char_len;
Karsten Hopp 8395f7
! 	}
Karsten Hopp 8395f7
! 	else
Karsten Hopp 8395f7
! 	{
Karsten Hopp 8395f7
! 	    if (options & SEARCH_START)
Karsten Hopp 8395f7
! 		extra_col = start_char_len;
Karsten Hopp 8395f7
! 	    else
Karsten Hopp 8395f7
! 		extra_col = 0;
Karsten Hopp 8395f7
! 	}
Karsten Hopp 8395f7
  
Karsten Hopp 8395f7
  	start_pos = *pos;	/* remember start pos for detecting no match */
Karsten Hopp 8395f7
  	found = 0;		/* default: not found */
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 779,793 ****
Karsten Hopp 8395f7
  					|| (lnum + regmatch.endpos[0].lnum
Karsten Hopp 8395f7
  							     == start_pos.lnum
Karsten Hopp 8395f7
  					     && (int)regmatch.endpos[0].col - 1
Karsten Hopp 8395f7
! 								   + extra_col
Karsten Hopp 8395f7
! 							<= (int)start_pos.col))
Karsten Hopp 8395f7
  				    : (lnum + regmatch.startpos[0].lnum
Karsten Hopp 8395f7
  							      < start_pos.lnum
Karsten Hopp 8395f7
  					|| (lnum + regmatch.startpos[0].lnum
Karsten Hopp 8395f7
  							     == start_pos.lnum
Karsten Hopp 8395f7
  					     && (int)regmatch.startpos[0].col
Karsten Hopp 8395f7
! 								   + extra_col
Karsten Hopp 8395f7
! 						      <= (int)start_pos.col))))
Karsten Hopp 8395f7
  			    {
Karsten Hopp 8395f7
  				match_ok = TRUE;
Karsten Hopp 8395f7
  				matchpos = regmatch.startpos[0];
Karsten Hopp 8395f7
--- 794,808 ----
Karsten Hopp 8395f7
  					|| (lnum + regmatch.endpos[0].lnum
Karsten Hopp 8395f7
  							     == start_pos.lnum
Karsten Hopp 8395f7
  					     && (int)regmatch.endpos[0].col - 1
Karsten Hopp 8395f7
! 							< (int)start_pos.col
Karsten Hopp 8395f7
! 								+ extra_col))
Karsten Hopp 8395f7
  				    : (lnum + regmatch.startpos[0].lnum
Karsten Hopp 8395f7
  							      < start_pos.lnum
Karsten Hopp 8395f7
  					|| (lnum + regmatch.startpos[0].lnum
Karsten Hopp 8395f7
  							     == start_pos.lnum
Karsten Hopp 8395f7
  					     && (int)regmatch.startpos[0].col
Karsten Hopp 8395f7
! 						      < (int)start_pos.col
Karsten Hopp 8395f7
! 							      + extra_col))))
Karsten Hopp 8395f7
  			    {
Karsten Hopp 8395f7
  				match_ok = TRUE;
Karsten Hopp 8395f7
  				matchpos = regmatch.startpos[0];
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/testdir/Make_amiga.mak	2015-06-25 13:57:20.033431073 +0200
Karsten Hopp 8395f7
--- src/testdir/Make_amiga.mak	2015-07-10 14:36:33.776641084 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 57,62 ****
Karsten Hopp 8395f7
--- 57,63 ----
Karsten Hopp 8395f7
  		test_perl.out \
Karsten Hopp 8395f7
  		test_qf_title.out \
Karsten Hopp 8395f7
  		test_ruby.out \
Karsten Hopp 8395f7
+ 		test_search_mbyte.out \
Karsten Hopp 8395f7
  		test_set.out \
Karsten Hopp 8395f7
  		test_signs.out \
Karsten Hopp 8395f7
  		test_textobjects.out \
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 205,210 ****
Karsten Hopp 8395f7
--- 206,212 ----
Karsten Hopp 8395f7
  test_perl.out: test_perl.in
Karsten Hopp 8395f7
  test_qf_title.out: test_qf_title.in
Karsten Hopp 8395f7
  test_ruby.out: test_ruby.in
Karsten Hopp 8395f7
+ test_search_mbyte.out: test_search_mbyte.in
Karsten Hopp 8395f7
  test_set.out: test_set.in
Karsten Hopp 8395f7
  test_signs.out: test_signs.in
Karsten Hopp 8395f7
  test_textobjects.out: test_textobjects.in
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/testdir/Make_dos.mak	2015-06-25 13:57:20.033431073 +0200
Karsten Hopp 8395f7
--- src/testdir/Make_dos.mak	2015-07-10 14:36:43.384550582 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 56,61 ****
Karsten Hopp 8395f7
--- 56,62 ----
Karsten Hopp 8395f7
  		test_perl.out \
Karsten Hopp 8395f7
  		test_qf_title.out \
Karsten Hopp 8395f7
  		test_ruby.out \
Karsten Hopp 8395f7
+ 		test_search_mbyte.out \
Karsten Hopp 8395f7
  		test_set.out \
Karsten Hopp 8395f7
  		test_signs.out \
Karsten Hopp 8395f7
  		test_textobjects.out \
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/testdir/Make_ming.mak	2015-06-25 13:57:20.033431073 +0200
Karsten Hopp 8395f7
--- src/testdir/Make_ming.mak	2015-07-10 14:36:50.716481518 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 78,83 ****
Karsten Hopp 8395f7
--- 78,84 ----
Karsten Hopp 8395f7
  		test_perl.out \
Karsten Hopp 8395f7
  		test_qf_title.out \
Karsten Hopp 8395f7
  		test_ruby.out \
Karsten Hopp 8395f7
+ 		test_search_mbyte.out \
Karsten Hopp 8395f7
  		test_set.out \
Karsten Hopp 8395f7
  		test_signs.out \
Karsten Hopp 8395f7
  		test_textobjects.out \
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/testdir/Make_os2.mak	2015-06-25 13:57:20.033431073 +0200
Karsten Hopp 8395f7
--- src/testdir/Make_os2.mak	2015-07-10 14:36:52.820461700 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 58,63 ****
Karsten Hopp 8395f7
--- 58,64 ----
Karsten Hopp 8395f7
  		test_perl.out \
Karsten Hopp 8395f7
  		test_qf_title.out \
Karsten Hopp 8395f7
  		test_ruby.out \
Karsten Hopp 8395f7
+ 		test_search_mbyte.out \
Karsten Hopp 8395f7
  		test_set.out \
Karsten Hopp 8395f7
  		test_signs.out \
Karsten Hopp 8395f7
  		test_textobjects.out \
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/testdir/Make_vms.mms	2015-06-25 13:57:20.033431073 +0200
Karsten Hopp 8395f7
--- src/testdir/Make_vms.mms	2015-07-10 14:36:58.240410647 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 4,10 ****
Karsten Hopp 8395f7
  # Authors:	Zoltan Arpadffy, <arpadffy@polarhome.com>
Karsten Hopp 8395f7
  #		Sandor Kopanyi,  <sandor.kopanyi@mailbox.hu>
Karsten Hopp 8395f7
  #
Karsten Hopp 8395f7
! # Last change:  2015 Jun 19
Karsten Hopp 8395f7
  #
Karsten Hopp 8395f7
  # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
Karsten Hopp 8395f7
  # Edit the lines in the Configuration section below to select.
Karsten Hopp 8395f7
--- 4,10 ----
Karsten Hopp 8395f7
  # Authors:	Zoltan Arpadffy, <arpadffy@polarhome.com>
Karsten Hopp 8395f7
  #		Sandor Kopanyi,  <sandor.kopanyi@mailbox.hu>
Karsten Hopp 8395f7
  #
Karsten Hopp 8395f7
! # Last change:  2015 Jul 10
Karsten Hopp 8395f7
  #
Karsten Hopp 8395f7
  # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
Karsten Hopp 8395f7
  # Edit the lines in the Configuration section below to select.
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 117,122 ****
Karsten Hopp 8395f7
--- 117,123 ----
Karsten Hopp 8395f7
  	 test_perl.out \
Karsten Hopp 8395f7
  	 test_qf_title.out \
Karsten Hopp 8395f7
  	 test_ruby.out \
Karsten Hopp 8395f7
+ 	 test_search_mbyte.out \
Karsten Hopp 8395f7
  	 test_set.out \
Karsten Hopp 8395f7
  	 test_signs.out \
Karsten Hopp 8395f7
  	 test_textobjects.out \
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/testdir/Makefile	2015-06-25 13:57:20.033431073 +0200
Karsten Hopp 8395f7
--- src/testdir/Makefile	2015-07-10 14:37:09.404305492 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 54,59 ****
Karsten Hopp 8395f7
--- 54,60 ----
Karsten Hopp 8395f7
  		test_perl.out \
Karsten Hopp 8395f7
  		test_qf_title.out \
Karsten Hopp 8395f7
  		test_ruby.out \
Karsten Hopp 8395f7
+ 		test_search_mbyte.out \
Karsten Hopp 8395f7
  		test_set.out \
Karsten Hopp 8395f7
  		test_signs.out \
Karsten Hopp 8395f7
  		test_textobjects.out \
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/testdir/test_search_mbyte.in	2015-07-10 14:42:43.513156459 +0200
Karsten Hopp 8395f7
--- src/testdir/test_search_mbyte.in	2015-07-10 14:33:38.430293025 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 0 ****
Karsten Hopp 8395f7
--- 1,15 ----
Karsten Hopp 8395f7
+ Test for search('multi-byte char', 'bce')
Karsten Hopp 8395f7
+ 
Karsten Hopp 8395f7
+ STARTTEST
Karsten Hopp 8395f7
+ :source small.vim
Karsten Hopp 8395f7
+ :source mbyte.vim
Karsten Hopp 8395f7
+ :set encoding=utf-8
Karsten Hopp 8395f7
+ :/^Test bce:/+1
Karsten Hopp 8395f7
+ :$put =search('A', 'bce', line('.'))
Karsten Hopp 8395f7
+ :1;/^Results:/,$wq! test.out
Karsten Hopp 8395f7
+ ENDTEST
Karsten Hopp 8395f7
+ 
Karsten Hopp 8395f7
+ Results:
Karsten Hopp 8395f7
+ 
Karsten Hopp 8395f7
+ Test bce:
Karsten Hopp 8395f7
+ A
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/testdir/test_search_mbyte.ok	2015-07-10 14:42:43.517156422 +0200
Karsten Hopp 8395f7
--- src/testdir/test_search_mbyte.ok	2015-07-10 14:34:23.409869226 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 0 ****
Karsten Hopp 8395f7
--- 1,5 ----
Karsten Hopp 8395f7
+ Results:
Karsten Hopp 8395f7
+ 
Karsten Hopp 8395f7
+ Test bce:
Karsten Hopp 8395f7
+ A
Karsten Hopp 8395f7
+ 15
Karsten Hopp 8395f7
*** ../vim-7.4.770/src/version.c	2015-07-10 14:05:03.930436893 +0200
Karsten Hopp 8395f7
--- src/version.c	2015-07-10 14:37:46.207958692 +0200
Karsten Hopp 8395f7
***************
Karsten Hopp 8395f7
*** 743,744 ****
Karsten Hopp 8395f7
--- 743,746 ----
Karsten Hopp 8395f7
  {   /* Add new patch number below this line */
Karsten Hopp 8395f7
+ /**/
Karsten Hopp 8395f7
+     771,
Karsten Hopp 8395f7
  /**/
Karsten Hopp 8395f7
Karsten Hopp 8395f7
-- 
Karsten Hopp 8395f7
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 8395f7
197. Your desk collapses under the weight of your computer peripherals.
Karsten Hopp 8395f7
Karsten Hopp 8395f7
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 8395f7
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 8395f7
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 8395f7
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///