9c34900
To: vim-dev@vim.org
9c34900
Subject: Patch 7.1.240
9c34900
Fcc: outbox
9c34900
From: Bram Moolenaar <Bram@moolenaar.net>
9c34900
Mime-Version: 1.0
9c34900
Content-Type: text/plain; charset=ISO-8859-1
9c34900
Content-Transfer-Encoding: 8bit
9c34900
------------
9c34900
9c34900
Patch 7.1.240
9c34900
Problem:    When "gUe" turns a German sharp s into SS the operation stops
9c34900
            before the end of the word.  Latin2 has the same sharp s but it's
9c34900
            not changed to SS there.
9c34900
Solution:   Make sure all the characters are operated upon.  Detect the sharp
9c34900
            s in latin2.  Also fixes that changing case of a multi-byte
9c34900
            character that changes the byte cound doesn't always work.
9c34900
Files:      src/ops.c
9c34900
9c34900
9c34900
*** ../vim-7.1.239/src/ops.c	Wed Jan 16 20:01:14 2008
9c34900
--- src/ops.c	Tue Jan 22 16:00:07 2008
9c34900
***************
9c34900
*** 2184,2189 ****
9c34900
--- 2184,2191 ----
9c34900
  }
9c34900
  #endif
9c34900
  
9c34900
+ static int swapchars __ARGS((int op_type, pos_T *pos, int length));
9c34900
+ 
9c34900
  /*
9c34900
   * Handle the (non-standard vi) tilde operator.  Also for "gu", "gU" and "g?".
9c34900
   */
9c34900
***************
9c34900
*** 2194,2202 ****
9c34900
      pos_T		pos;
9c34900
  #ifdef FEAT_VISUAL
9c34900
      struct block_def	bd;
9c34900
-     int			todo;
9c34900
  #endif
9c34900
!     int			did_change = 0;
9c34900
  
9c34900
      if (u_save((linenr_T)(oap->start.lnum - 1),
9c34900
  				       (linenr_T)(oap->end.lnum + 1)) == FAIL)
9c34900
--- 2196,2203 ----
9c34900
      pos_T		pos;
9c34900
  #ifdef FEAT_VISUAL
9c34900
      struct block_def	bd;
9c34900
  #endif
9c34900
!     int			did_change;
9c34900
  
9c34900
      if (u_save((linenr_T)(oap->start.lnum - 1),
9c34900
  				       (linenr_T)(oap->end.lnum + 1)) == FAIL)
9c34900
***************
9c34900
*** 2210,2225 ****
9c34900
  	{
9c34900
  	    block_prep(oap, &bd, pos.lnum, FALSE);
9c34900
  	    pos.col = bd.textcol;
9c34900
! 	    for (todo = bd.textlen; todo > 0; --todo)
9c34900
! 	    {
9c34900
! # ifdef FEAT_MBYTE
9c34900
! 		if (has_mbyte)
9c34900
! 		    todo -= (*mb_ptr2len)(ml_get_pos(&pos)) - 1;
9c34900
! # endif
9c34900
! 		did_change |= swapchar(oap->op_type, &pos;;
9c34900
! 		if (inc(&pos) == -1)	    /* at end of file */
9c34900
! 		    break;
9c34900
! 	    }
9c34900
  # ifdef FEAT_NETBEANS_INTG
9c34900
  	    if (usingNetbeans && did_change)
9c34900
  	    {
9c34900
--- 2211,2218 ----
9c34900
  	{
9c34900
  	    block_prep(oap, &bd, pos.lnum, FALSE);
9c34900
  	    pos.col = bd.textcol;
9c34900
! 	    did_change = swapchars(oap->op_type, &pos, bd.textlen);
9c34900
! 
9c34900
  # ifdef FEAT_NETBEANS_INTG
9c34900
  	    if (usingNetbeans && did_change)
9c34900
  	    {
9c34900
***************
9c34900
*** 2249,2261 ****
9c34900
  	else if (!oap->inclusive)
9c34900
  	    dec(&(oap->end));
9c34900
  
9c34900
! 	while (ltoreq(pos, oap->end))
9c34900
! 	{
9c34900
! 	    did_change |= swapchar(oap->op_type, &pos;;
9c34900
! 	    if (inc(&pos) == -1)    /* at end of file */
9c34900
! 		break;
9c34900
! 	}
9c34900
! 
9c34900
  	if (did_change)
9c34900
  	{
9c34900
  	    changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1,
9c34900
--- 2242,2248 ----
9c34900
  	else if (!oap->inclusive)
9c34900
  	    dec(&(oap->end));
9c34900
  
9c34900
! 	did_change = swapchars(oap->op_type, &pos, oap->end.col - pos.col + 1);
9c34900
  	if (did_change)
9c34900
  	{
9c34900
  	    changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1,
9c34900
***************
9c34900
*** 2309,2314 ****
9c34900
--- 2296,2337 ----
9c34900
  }
9c34900
  
9c34900
  /*
9c34900
+  * Invoke swapchar() on "length" bytes at position "pos".
9c34900
+  * "pos" is advanced to just after the changed characters.
9c34900
+  * "length" is rounded up to include the whole last multi-byte character.
9c34900
+  * Also works correctly when the number of bytes changes.
9c34900
+  * Returns TRUE if some character was changed.
9c34900
+  */
9c34900
+     static int
9c34900
+ swapchars(op_type, pos, length)
9c34900
+     int		op_type;
9c34900
+     pos_T	*pos;
9c34900
+     int		length;
9c34900
+ {
9c34900
+     int todo;
9c34900
+     int	did_change = 0;
9c34900
+ 
9c34900
+     for (todo = length; todo > 0; --todo)
9c34900
+     {
9c34900
+ # ifdef FEAT_MBYTE
9c34900
+ 	int pos_col = pos->col;
9c34900
+ 
9c34900
+ 	if (has_mbyte)
9c34900
+ 	    /* we're counting bytes, not characters */
9c34900
+ 	    todo -= (*mb_ptr2len)(ml_get_pos(pos)) - 1;
9c34900
+ # endif
9c34900
+ 	did_change |= swapchar(op_type, pos);
9c34900
+ # ifdef FEAT_MBYTE
9c34900
+ 	/* Changing German sharp s to SS increases the column. */
9c34900
+ 	todo += pos->col - pos_col;
9c34900
+ # endif
9c34900
+ 	if (inc(pos) == -1)    /* at end of file */
9c34900
+ 	    break;
9c34900
+     }
9c34900
+     return did_change;
9c34900
+ }
9c34900
+ 
9c34900
+ /*
9c34900
   * If op_type == OP_UPPER: make uppercase,
9c34900
   * if op_type == OP_LOWER: make lowercase,
9c34900
   * if op_type == OP_ROT13: do rot13 encoding,
9c34900
***************
9c34900
*** 2330,2336 ****
9c34900
  	return FALSE;
9c34900
  
9c34900
  #ifdef FEAT_MBYTE
9c34900
!     if (op_type == OP_UPPER && enc_latin1like && c == 0xdf)
9c34900
      {
9c34900
  	pos_T   sp = curwin->w_cursor;
9c34900
  
9c34900
--- 2353,2360 ----
9c34900
  	return FALSE;
9c34900
  
9c34900
  #ifdef FEAT_MBYTE
9c34900
!     if (op_type == OP_UPPER && c == 0xdf
9c34900
! 		      && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0))
9c34900
      {
9c34900
  	pos_T   sp = curwin->w_cursor;
9c34900
  
9c34900
*** ../vim-7.1.239/src/version.c	Tue Jan 22 12:44:03 2008
9c34900
--- src/version.c	Tue Jan 22 15:36:36 2008
9c34900
***************
9c34900
*** 668,669 ****
9c34900
--- 668,671 ----
9c34900
  {   /* Add new patch number below this line */
9c34900
+ /**/
9c34900
+     240,
9c34900
  /**/
9c34900
9c34900
-- 
9c34900
ARTHUR: It is I, Arthur, son of Uther Pendragon, from the castle of Camelot.
9c34900
        King of all Britons, defeator of the Saxons, sovereign of all England!
9c34900
   [Pause]
9c34900
SOLDIER: Get away!
9c34900
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
9c34900
9c34900
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
9c34900
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
9c34900
\\\        download, build and distribute -- http://www.A-A-P.org        ///
9c34900
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///