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