lkundrak / rpms / vim

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