lkundrak / rpms / vim

Forked from rpms/vim 4 years ago
Clone
b9a68ff
To: vim_dev@googlegroups.com
b9a68ff
Subject: Patch 7.4.293
b9a68ff
Fcc: outbox
b9a68ff
From: Bram Moolenaar <Bram@moolenaar.net>
b9a68ff
Mime-Version: 1.0
b9a68ff
Content-Type: text/plain; charset=UTF-8
b9a68ff
Content-Transfer-Encoding: 8bit
b9a68ff
------------
b9a68ff
b9a68ff
Patch 7.4.293
b9a68ff
Problem:    It is not possible to ignore composing characters at a specific
b9a68ff
	    point in a pattern.
b9a68ff
Solution:   Add the %C item.
b9a68ff
Files:	    src/regexp.c, src/regexp_nfa.c, src/testdir/test95.in,
b9a68ff
	    src/testdir/test95.ok, runtime/doc/pattern.txt
b9a68ff
b9a68ff
b9a68ff
*** ../vim-7.4.292/src/regexp.c	2014-05-13 18:03:55.729737466 +0200
b9a68ff
--- src/regexp.c	2014-05-13 18:27:08.725749659 +0200
b9a68ff
***************
b9a68ff
*** 244,249 ****
b9a68ff
--- 244,250 ----
b9a68ff
  
b9a68ff
  #define RE_MARK		207	/* mark cmp  Match mark position */
b9a68ff
  #define RE_VISUAL	208	/*	Match Visual area */
b9a68ff
+ #define RE_COMPOSING	209	/* any composing characters */
b9a68ff
  
b9a68ff
  /*
b9a68ff
   * Magic characters have a special meaning, they don't match literally.
b9a68ff
***************
b9a68ff
*** 2208,2213 ****
b9a68ff
--- 2209,2218 ----
b9a68ff
  		    ret = regnode(RE_VISUAL);
b9a68ff
  		    break;
b9a68ff
  
b9a68ff
+ 		case 'C':
b9a68ff
+ 		    ret = regnode(RE_COMPOSING);
b9a68ff
+ 		    break;
b9a68ff
+ 
b9a68ff
  		/* \%[abc]: Emit as a list of branches, all ending at the last
b9a68ff
  		 * branch which matches nothing. */
b9a68ff
  		case '[':
b9a68ff
***************
b9a68ff
*** 4710,4720 ****
b9a68ff
  			    status = RA_NOMATCH;
b9a68ff
  		    }
b9a68ff
  #ifdef FEAT_MBYTE
b9a68ff
! 		    /* Check for following composing character. */
b9a68ff
  		    if (status != RA_NOMATCH
b9a68ff
  			    && enc_utf8
b9a68ff
  			    && UTF_COMPOSINGLIKE(reginput, reginput + len)
b9a68ff
! 			    && !ireg_icombine)
b9a68ff
  		    {
b9a68ff
  			/* raaron: This code makes a composing character get
b9a68ff
  			 * ignored, which is the correct behavior (sometimes)
b9a68ff
--- 4715,4727 ----
b9a68ff
  			    status = RA_NOMATCH;
b9a68ff
  		    }
b9a68ff
  #ifdef FEAT_MBYTE
b9a68ff
! 		    /* Check for following composing character, unless %C
b9a68ff
! 		     * follows (skips over all composing chars). */
b9a68ff
  		    if (status != RA_NOMATCH
b9a68ff
  			    && enc_utf8
b9a68ff
  			    && UTF_COMPOSINGLIKE(reginput, reginput + len)
b9a68ff
! 			    && !ireg_icombine
b9a68ff
! 			    && OP(next) != RE_COMPOSING)
b9a68ff
  		    {
b9a68ff
  			/* raaron: This code makes a composing character get
b9a68ff
  			 * ignored, which is the correct behavior (sometimes)
b9a68ff
***************
b9a68ff
*** 4791,4796 ****
b9a68ff
--- 4798,4813 ----
b9a68ff
  		status = RA_NOMATCH;
b9a68ff
  	    break;
b9a68ff
  #endif
b9a68ff
+ 	  case RE_COMPOSING:
b9a68ff
+ #ifdef FEAT_MBYTE
b9a68ff
+ 	    if (enc_utf8)
b9a68ff
+ 	    {
b9a68ff
+ 		/* Skip composing characters. */
b9a68ff
+ 		while (utf_iscomposing(utf_ptr2char(reginput)))
b9a68ff
+ 		    mb_cptr_adv(reginput);
b9a68ff
+ 	    }
b9a68ff
+ #endif
b9a68ff
+ 	    break;
b9a68ff
  
b9a68ff
  	  case NOTHING:
b9a68ff
  	    break;
b9a68ff
*** ../vim-7.4.292/src/regexp_nfa.c	2014-05-13 16:44:25.633695709 +0200
b9a68ff
--- src/regexp_nfa.c	2014-05-13 19:25:58.285780556 +0200
b9a68ff
***************
b9a68ff
*** 81,86 ****
b9a68ff
--- 81,87 ----
b9a68ff
      NFA_COMPOSING,		    /* Next nodes in NFA are part of the
b9a68ff
  				       composing multibyte char */
b9a68ff
      NFA_END_COMPOSING,		    /* End of a composing char in the NFA */
b9a68ff
+     NFA_ANY_COMPOSING,		    /* \%C: Any composing characters. */
b9a68ff
      NFA_OPT_CHARS,		    /* \%[abc] */
b9a68ff
  
b9a68ff
      /* The following are used only in the postfix form, not in the NFA */
b9a68ff
***************
b9a68ff
*** 1418,1423 ****
b9a68ff
--- 1419,1428 ----
b9a68ff
  		    EMIT(NFA_VISUAL);
b9a68ff
  		    break;
b9a68ff
  
b9a68ff
+ 		case 'C':
b9a68ff
+ 		    EMIT(NFA_ANY_COMPOSING);
b9a68ff
+ 		    break;
b9a68ff
+ 
b9a68ff
  		case '[':
b9a68ff
  		    {
b9a68ff
  			int	    n;
b9a68ff
***************
b9a68ff
*** 2429,2434 ****
b9a68ff
--- 2434,2440 ----
b9a68ff
  	case NFA_MARK_LT:	STRCPY(code, "NFA_MARK_LT "); break;
b9a68ff
  	case NFA_CURSOR:	STRCPY(code, "NFA_CURSOR "); break;
b9a68ff
  	case NFA_VISUAL:	STRCPY(code, "NFA_VISUAL "); break;
b9a68ff
+ 	case NFA_ANY_COMPOSING:	STRCPY(code, "NFA_ANY_COMPOSING "); break;
b9a68ff
  
b9a68ff
  	case NFA_STAR:		STRCPY(code, "NFA_STAR "); break;
b9a68ff
  	case NFA_STAR_NONGREEDY: STRCPY(code, "NFA_STAR_NONGREEDY "); break;
b9a68ff
***************
b9a68ff
*** 2967,2972 ****
b9a68ff
--- 2973,2979 ----
b9a68ff
  	    case NFA_NLOWER_IC:
b9a68ff
  	    case NFA_UPPER_IC:
b9a68ff
  	    case NFA_NUPPER_IC:
b9a68ff
+ 	    case NFA_ANY_COMPOSING:
b9a68ff
  		/* possibly non-ascii */
b9a68ff
  #ifdef FEAT_MBYTE
b9a68ff
  		if (has_mbyte)
b9a68ff
***************
b9a68ff
*** 4152,4157 ****
b9a68ff
--- 4159,4165 ----
b9a68ff
  		continue;
b9a68ff
  
b9a68ff
  	    case NFA_ANY:
b9a68ff
+ 	    case NFA_ANY_COMPOSING:
b9a68ff
  	    case NFA_IDENT:
b9a68ff
  	    case NFA_SIDENT:
b9a68ff
  	    case NFA_KWORD:
b9a68ff
***************
b9a68ff
*** 4395,4401 ****
b9a68ff
      switch (state->c)
b9a68ff
      {
b9a68ff
  	case NFA_MATCH:
b9a68ff
! 	    nfa_match = TRUE;
b9a68ff
  	    break;
b9a68ff
  
b9a68ff
  	case NFA_SPLIT:
b9a68ff
--- 4403,4409 ----
b9a68ff
      switch (state->c)
b9a68ff
      {
b9a68ff
  	case NFA_MATCH:
b9a68ff
! //	    nfa_match = TRUE;
b9a68ff
  	    break;
b9a68ff
  
b9a68ff
  	case NFA_SPLIT:
b9a68ff
***************
b9a68ff
*** 5151,5156 ****
b9a68ff
--- 5159,5165 ----
b9a68ff
  
b9a68ff
  	case NFA_MATCH:
b9a68ff
  	case NFA_MCLOSE:
b9a68ff
+ 	case NFA_ANY_COMPOSING:
b9a68ff
  	    /* empty match works always */
b9a68ff
  	    return 0;
b9a68ff
  
b9a68ff
***************
b9a68ff
*** 5573,5578 ****
b9a68ff
--- 5582,5593 ----
b9a68ff
  	    {
b9a68ff
  	    case NFA_MATCH:
b9a68ff
  	      {
b9a68ff
+ #ifdef FEAT_MBYTE
b9a68ff
+ 		/* If the match ends before a composing characters and
b9a68ff
+ 		 * ireg_icombine is not set, that is not really a match. */
b9a68ff
+ 		if (enc_utf8 && !ireg_icombine && utf_iscomposing(curc))
b9a68ff
+ 		    break;
b9a68ff
+ #endif
b9a68ff
  		nfa_match = TRUE;
b9a68ff
  		copy_sub(&submatch->norm, &t->subs.norm);
b9a68ff
  #ifdef FEAT_SYN_HL
b9a68ff
***************
b9a68ff
*** 6120,6125 ****
b9a68ff
--- 6135,6157 ----
b9a68ff
  		}
b9a68ff
  		break;
b9a68ff
  
b9a68ff
+ 	    case NFA_ANY_COMPOSING:
b9a68ff
+ 		/* On a composing character skip over it.  Otherwise do
b9a68ff
+ 		 * nothing.  Always matches. */
b9a68ff
+ #ifdef FEAT_MBYTE
b9a68ff
+ 		if (enc_utf8 && utf_iscomposing(curc))
b9a68ff
+ 		{
b9a68ff
+ 		    add_off = clen;
b9a68ff
+ 		}
b9a68ff
+ 		else
b9a68ff
+ #endif
b9a68ff
+ 		{
b9a68ff
+ 		    add_here = TRUE;
b9a68ff
+ 		    add_off = 0;
b9a68ff
+ 		}
b9a68ff
+ 		add_state = t->state->out;
b9a68ff
+ 		break;
b9a68ff
+ 
b9a68ff
  	    /*
b9a68ff
  	     * Character classes like \a for alpha, \d for digit etc.
b9a68ff
  	     */
b9a68ff
***************
b9a68ff
*** 6484,6495 ****
b9a68ff
  		if (!result && ireg_ic)
b9a68ff
  		    result = MB_TOLOWER(c) == MB_TOLOWER(curc);
b9a68ff
  #ifdef FEAT_MBYTE
b9a68ff
! 		/* If there is a composing character which is not being
b9a68ff
! 		 * ignored there can be no match. Match with composing
b9a68ff
! 		 * character uses NFA_COMPOSING above. */
b9a68ff
! 		if (result && enc_utf8 && !ireg_icombine
b9a68ff
! 						&& clen != utf_char2len(curc))
b9a68ff
! 		    result = FALSE;
b9a68ff
  #endif
b9a68ff
  		ADD_STATE_IF_MATCH(t->state);
b9a68ff
  		break;
b9a68ff
--- 6516,6525 ----
b9a68ff
  		if (!result && ireg_ic)
b9a68ff
  		    result = MB_TOLOWER(c) == MB_TOLOWER(curc);
b9a68ff
  #ifdef FEAT_MBYTE
b9a68ff
! 		/* If ireg_icombine is not set only skip over the character
b9a68ff
! 		 * itself.  When it is set skip over composing characters. */
b9a68ff
! 		if (result && enc_utf8 && !ireg_icombine)
b9a68ff
! 		    clen = utf_char2len(curc);
b9a68ff
  #endif
b9a68ff
  		ADD_STATE_IF_MATCH(t->state);
b9a68ff
  		break;
b9a68ff
diff: ../vim-7.4.292/src/testdir/test95.insrc/testdir/test95.ok,: No such file or directory
b9a68ff
diff: src/testdir/test95.insrc/testdir/test95.ok,: No such file or directory
b9a68ff
*** ../vim-7.4.292/runtime/doc/pattern.txt	2013-08-10 13:24:59.000000000 +0200
b9a68ff
--- runtime/doc/pattern.txt	2014-05-13 18:59:57.621766895 +0200
b9a68ff
***************
b9a68ff
*** 545,550 ****
b9a68ff
--- 545,551 ----
b9a68ff
  |/\%u|	\%u	\%u	match specified multibyte character (eg \%u20ac)
b9a68ff
  |/\%U|	\%U	\%U	match specified large multibyte character (eg
b9a68ff
  			\%U12345678)
b9a68ff
+ |/\%C|	\%C	\%C	match any composing characters
b9a68ff
  
b9a68ff
  Example			matches ~
b9a68ff
  \<\I\i*		or
b9a68ff
***************
b9a68ff
*** 1207,1218 ****
b9a68ff
  8. Composing characters					*patterns-composing*
b9a68ff
  
b9a68ff
  							*/\Z*
b9a68ff
! When "\Z" appears anywhere in the pattern, composing characters are ignored.
b9a68ff
! Thus only the base characters need to match, the composing characters may be
b9a68ff
! different and the number of composing characters may differ.  Only relevant
b9a68ff
! when 'encoding' is "utf-8".
b9a68ff
  Exception: If the pattern starts with one or more composing characters, these
b9a68ff
  must match.
b9a68ff
  
b9a68ff
  When a composing character appears at the start of the pattern of after an
b9a68ff
  item that doesn't include the composing character, a match is found at any
b9a68ff
--- 1208,1225 ----
b9a68ff
  8. Composing characters					*patterns-composing*
b9a68ff
  
b9a68ff
  							*/\Z*
b9a68ff
! When "\Z" appears anywhere in the pattern, all composing characters are
b9a68ff
! ignored.  Thus only the base characters need to match, the composing
b9a68ff
! characters may be different and the number of composing characters may differ.
b9a68ff
! Only relevant when 'encoding' is "utf-8".
b9a68ff
  Exception: If the pattern starts with one or more composing characters, these
b9a68ff
  must match.
b9a68ff
+ 							*/\%C*
b9a68ff
+ Use "\%C" to skip any composing characters.  For example, the pattern "a" does
b9a68ff
+ not match in "càt" (where the a has the composing character 0x0300), but
b9a68ff
+ "a\%C" does.  Note that this does not match "cát" (where the á is character
b9a68ff
+ 0xe1, it does not have a compositing character).  It does match "cat" (where
b9a68ff
+ the a is just an a).
b9a68ff
  
b9a68ff
  When a composing character appears at the start of the pattern of after an
b9a68ff
  item that doesn't include the composing character, a match is found at any
b9a68ff
*** ../vim-7.4.292/src/version.c	2014-05-13 18:03:55.729737466 +0200
b9a68ff
--- src/version.c	2014-05-13 18:28:45.885750510 +0200
b9a68ff
***************
b9a68ff
*** 736,737 ****
b9a68ff
--- 736,739 ----
b9a68ff
  {   /* Add new patch number below this line */
b9a68ff
+ /**/
b9a68ff
+     293,
b9a68ff
  /**/
b9a68ff
b9a68ff
-- 
b9a68ff
hundred-and-one symptoms of being an internet addict:
b9a68ff
155. You forget to eat because you're too busy surfing the net.
b9a68ff
b9a68ff
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
b9a68ff
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
b9a68ff
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
b9a68ff
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///