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