Blame SOURCES/7.4.057

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.057
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.057                                 
22c937
Problem:    byteidx() does not work for composing characters.
22c937
Solution:   Add byteidxcomp().
22c937
Files:      src/eval.c, src/testdir/test69.in, src/testdir/test69.ok,
22c937
            runtime/doc/eval.txt
22c937
22c937
22c937
*** ../vim-7.4.056/src/eval.c	2013-10-02 16:46:23.000000000 +0200
22c937
--- src/eval.c	2013-11-02 22:30:08.000000000 +0100
22c937
***************
22c937
*** 474,480 ****
22c937
--- 474,482 ----
22c937
  static void f_bufnr __ARGS((typval_T *argvars, typval_T *rettv));
22c937
  static void f_bufwinnr __ARGS((typval_T *argvars, typval_T *rettv));
22c937
  static void f_byte2line __ARGS((typval_T *argvars, typval_T *rettv));
22c937
+ static void byteidx __ARGS((typval_T *argvars, typval_T *rettv, int comp));
22c937
  static void f_byteidx __ARGS((typval_T *argvars, typval_T *rettv));
22c937
+ static void f_byteidxcomp __ARGS((typval_T *argvars, typval_T *rettv));
22c937
  static void f_call __ARGS((typval_T *argvars, typval_T *rettv));
22c937
  #ifdef FEAT_FLOAT
22c937
  static void f_ceil __ARGS((typval_T *argvars, typval_T *rettv));
22c937
***************
22c937
*** 7861,7866 ****
22c937
--- 7863,7869 ----
22c937
      {"bufwinnr",	1, 1, f_bufwinnr},
22c937
      {"byte2line",	1, 1, f_byte2line},
22c937
      {"byteidx",		2, 2, f_byteidx},
22c937
+     {"byteidxcomp",	2, 2, f_byteidxcomp},
22c937
      {"call",		2, 3, f_call},
22c937
  #ifdef FEAT_FLOAT
22c937
      {"ceil",		1, 1, f_ceil},
22c937
***************
22c937
*** 9177,9189 ****
22c937
  #endif
22c937
  }
22c937
  
22c937
- /*
22c937
-  * "byteidx()" function
22c937
-  */
22c937
      static void
22c937
! f_byteidx(argvars, rettv)
22c937
      typval_T	*argvars;
22c937
      typval_T	*rettv;
22c937
  {
22c937
  #ifdef FEAT_MBYTE
22c937
      char_u	*t;
22c937
--- 9180,9190 ----
22c937
  #endif
22c937
  }
22c937
  
22c937
      static void
22c937
! byteidx(argvars, rettv, comp)
22c937
      typval_T	*argvars;
22c937
      typval_T	*rettv;
22c937
+     int		comp;
22c937
  {
22c937
  #ifdef FEAT_MBYTE
22c937
      char_u	*t;
22c937
***************
22c937
*** 9203,9209 ****
22c937
      {
22c937
  	if (*t == NUL)		/* EOL reached */
22c937
  	    return;
22c937
! 	t += (*mb_ptr2len)(t);
22c937
      }
22c937
      rettv->vval.v_number = (varnumber_T)(t - str);
22c937
  #else
22c937
--- 9204,9213 ----
22c937
      {
22c937
  	if (*t == NUL)		/* EOL reached */
22c937
  	    return;
22c937
! 	if (enc_utf8 && comp)
22c937
! 	    t += utf_ptr2len(t);
22c937
! 	else
22c937
! 	    t += (*mb_ptr2len)(t);
22c937
      }
22c937
      rettv->vval.v_number = (varnumber_T)(t - str);
22c937
  #else
22c937
***************
22c937
*** 9212,9217 ****
22c937
--- 9216,9243 ----
22c937
  #endif
22c937
  }
22c937
  
22c937
+ /*
22c937
+  * "byteidx()" function
22c937
+  */
22c937
+     static void
22c937
+ f_byteidx(argvars, rettv)
22c937
+     typval_T	*argvars;
22c937
+     typval_T	*rettv;
22c937
+ {
22c937
+     byteidx(argvars, rettv, FALSE);
22c937
+ }
22c937
+ 
22c937
+ /*
22c937
+  * "byteidxcomp()" function
22c937
+  */
22c937
+     static void
22c937
+ f_byteidxcomp(argvars, rettv)
22c937
+     typval_T	*argvars;
22c937
+     typval_T	*rettv;
22c937
+ {
22c937
+     byteidx(argvars, rettv, TRUE);
22c937
+ }
22c937
+ 
22c937
      int
22c937
  func_call(name, args, selfdict, rettv)
22c937
      char_u	*name;
22c937
*** ../vim-7.4.056/src/testdir/test69.in	2013-03-07 18:30:50.000000000 +0100
22c937
--- src/testdir/test69.in	2013-11-02 22:46:02.000000000 +0100
22c937
***************
22c937
*** 1,6 ****
22c937
--- 1,7 ----
22c937
  Test for multi-byte text formatting.
22c937
  Also test, that 'mps' with multibyte chars works.
22c937
  And test "ra" on multi-byte characters.
22c937
+ Also test byteidx() and byteidxcomp()
22c937
  
22c937
  STARTTEST
22c937
  :so mbyte.vim
22c937
***************
22c937
*** 154,159 ****
22c937
--- 155,175 ----
22c937
  aab
22c937
  
22c937
  STARTTEST
22c937
+ :let a = '.é.' " one char of two bytes
22c937
+ :let b = '.é.' " normal e with composing char
22c937
+ /^byteidx
22c937
+ :put =string([byteidx(a, 0), byteidx(a, 1), byteidx(a, 2), byteidx(a, 3), byteidx(a, 4)])
22c937
+ :put =string([byteidx(b, 0), byteidx(b, 1), byteidx(b, 2), byteidx(b, 3), byteidx(b, 4)])
22c937
+ /^byteidxcomp
22c937
+ :put =string([byteidxcomp(a, 0), byteidxcomp(a, 1), byteidxcomp(a, 2), byteidxcomp(a, 3), byteidxcomp(a, 4)])
22c937
+ :let b = '.é.'
22c937
+ :put =string([byteidxcomp(b, 0), byteidxcomp(b, 1), byteidxcomp(b, 2), byteidxcomp(b, 3), byteidxcomp(b, 4), byteidxcomp(b, 5)])
22c937
+ ENDTEST
22c937
+ 
22c937
+ byteidx
22c937
+ byteidxcomp
22c937
+ 
22c937
+ STARTTEST
22c937
  :g/^STARTTEST/.,/^ENDTEST/d
22c937
  :1;/^Results/,$wq! test.out
22c937
  ENDTEST
22c937
*** ../vim-7.4.056/src/testdir/test69.ok	2013-03-07 18:31:32.000000000 +0100
22c937
--- src/testdir/test69.ok	2013-11-02 22:43:25.000000000 +0100
22c937
***************
22c937
*** 149,151 ****
22c937
--- 149,159 ----
22c937
  aaaa
22c937
  aaa
22c937
  
22c937
+ 
22c937
+ byteidx
22c937
+ [0, 1, 3, 4, -1]
22c937
+ [0, 1, 4, 5, -1]
22c937
+ byteidxcomp
22c937
+ [0, 1, 3, 4, -1]
22c937
+ [0, 1, 2, 4, 5, -1]
22c937
+ 
22c937
*** ../vim-7.4.056/runtime/doc/eval.txt	2013-08-10 13:24:53.000000000 +0200
22c937
--- runtime/doc/eval.txt	2013-11-02 23:27:24.000000000 +0100
22c937
***************
22c937
*** 1712,1717 ****
22c937
--- 1713,1719 ----
22c937
  bufwinnr( {expr})		Number	window number of buffer {expr}
22c937
  byte2line( {byte})		Number	line number at byte count {byte}
22c937
  byteidx( {expr}, {nr})		Number	byte index of {nr}'th char in {expr}
22c937
+ byteidxcomp( {expr}, {nr})	Number	byte index of {nr}'th char in {expr}
22c937
  call( {func}, {arglist} [, {dict}])
22c937
  				any	call {func} with arguments {arglist}
22c937
  ceil( {expr})			Float	round {expr} up
22c937
***************
22c937
*** 2260,2266 ****
22c937
  		{expr}.  Use zero for the first character, it returns zero.
22c937
  		This function is only useful when there are multibyte
22c937
  		characters, otherwise the returned value is equal to {nr}.
22c937
! 		Composing characters are counted as a separate character.
22c937
  		Example : >
22c937
  			echo matchstr(str, ".", byteidx(str, 3))
22c937
  <		will display the fourth character.  Another way to do the
22c937
--- 2262,2271 ----
22c937
  		{expr}.  Use zero for the first character, it returns zero.
22c937
  		This function is only useful when there are multibyte
22c937
  		characters, otherwise the returned value is equal to {nr}.
22c937
! 		Composing characters are not counted separately, their byte
22c937
! 		length is added to the preceding base character.  See
22c937
! 		|byteidxcomp()| below for counting composing characters
22c937
! 		separately.
22c937
  		Example : >
22c937
  			echo matchstr(str, ".", byteidx(str, 3))
22c937
  <		will display the fourth character.  Another way to do the
22c937
***************
22c937
*** 2269,2275 ****
22c937
  			echo strpart(s, 0, byteidx(s, 1))
22c937
  <		If there are less than {nr} characters -1 is returned.
22c937
  		If there are exactly {nr} characters the length of the string
22c937
! 		is returned.
22c937
  
22c937
  call({func}, {arglist} [, {dict}])			*call()* *E699*
22c937
  		Call function {func} with the items in |List| {arglist} as
22c937
--- 2274,2293 ----
22c937
  			echo strpart(s, 0, byteidx(s, 1))
22c937
  <		If there are less than {nr} characters -1 is returned.
22c937
  		If there are exactly {nr} characters the length of the string
22c937
! 		in bytes is returned.
22c937
! 
22c937
! byteidxcomp({expr}, {nr})					*byteidxcomp()*
22c937
! 		Like byteidx(), except that a composing character is counted
22c937
! 		as a separate character.  Example: >
22c937
! 			let s = 'e' . nr2char(0x301)
22c937
! 			echo byteidx(s, 1)
22c937
! 			echo byteidxcomp(s, 1)
22c937
! 			echo byteidxcomp(s, 2)
22c937
! <		The first and third echo result in 3 ('e' plus composing
22c937
! 		character is 3 bytes), the second echo results in 1 ('e' is
22c937
! 		one byte).
22c937
! 		Only works different from byteidx() when 'encoding' is set to
22c937
! 		a Unicode encoding.
22c937
  
22c937
  call({func}, {arglist} [, {dict}])			*call()* *E699*
22c937
  		Call function {func} with the items in |List| {arglist} as
22c937
*** ../vim-7.4.056/src/version.c	2013-11-02 21:49:28.000000000 +0100
22c937
--- src/version.c	2013-11-02 22:45:13.000000000 +0100
22c937
***************
22c937
*** 740,741 ****
22c937
--- 740,743 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     57,
22c937
  /**/
22c937
22c937
-- 
22c937
Any sufficiently advanced technology is indistinguishable from magic.
22c937
					Arthur C. Clarke
22c937
Any sufficiently advanced bug is indistinguishable from a feature.
22c937
                                        Rich Kulawiec
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///