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