Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Aug 2011 20:54:13 +0000 (UTC)
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r224869 - user/gabor/tre-integration/contrib/tre/lib
Message-ID:  <201108142054.p7EKsDpV079319@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gabor
Date: Sun Aug 14 20:54:13 2011
New Revision: 224869
URL: http://svn.freebsd.org/changeset/base/224869

Log:
  - Fix word boundary matching for the remaining case

Modified:
  user/gabor/tre-integration/contrib/tre/lib/fastmatch.c

Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/fastmatch.c	Sun Aug 14 16:17:00 2011	(r224868)
+++ user/gabor/tre-integration/contrib/tre/lib/fastmatch.c	Sun Aug 14 20:54:13 2011	(r224869)
@@ -459,29 +459,26 @@ tre_fastcomp(fastmatch_t *fg, const tre_
     continue;								\
   }
 
+#define _BBOUND_COND							\
+  ((type == STR_WIDE) ?							\
+    ((j == 0) || !(tre_isalnum(str_wide[j - 1]) ||			\
+      (str_wide[j - 1] == TRE_CHAR('_')))) :				\
+    ((j == 0) || !(tre_isalnum(str_byte[j - 1]) ||			\
+      (str_byte[j - 1] == '_'))))
+
+#define _EBOUND_COND							\
+  ((type == STR_WIDE) ?							\
+    ((j + fg->wlen == len) || !(tre_isalnum(str_wide[j + fg->wlen]) ||	\
+      (str_wide[j + fg->wlen] == TRE_CHAR('_')))) :			\
+    ((j + fg->len == len) || !(tre_isalnum(str_byte[j + fg->len]) ||	\
+      (str_byte[j + fg->len] == '_'))))
+
+#define IS_ON_WORD_BOUNDARY						\
+  (_BBOUND_COND && _EBOUND_COND)
+
 #define CHECK_WORD_BOUNDARY						\
-  {									\
-    bool bbound, ebound;						\
-									\
-    switch (type)							\
-      {									\
-	case STR_WIDE:							\
-	  bbound = (j == 0) || !(tre_isalnum(str_wide[j - 1]) ||	\
-	    (str_wide[j - 1] == TRE_CHAR('_')));			\
-	  ebound = (j + fg->wlen == len) ||				\
-	     !(tre_isalnum(str_wide[j + fg->wlen]) ||			\
-	     (str_wide[j + fg->wlen] == TRE_CHAR('_')));		\
-	  break;							\
-	default:							\
-	  bbound = (j == 0) || !(tre_isalnum(str_byte[j - 1]) ||	\
-	    (str_byte[j - 1] == '_'));					\
-	  ebound = (j + fg->len == len) ||				\
-	    !(tre_isalnum(str_byte[j + fg->len]) ||			\
-	    (str_byte[j + fg->len] == '_'));				\
-      }									\
-    if (!bbound || !ebound)						\
-      _SHIFT_ONE;							\
-  }
+    if (!IS_ON_WORD_BOUNDARY)						\
+      _SHIFT_ONE;
 
 #define _BOL_COND							\
   ((j == 0) || ((type == STR_WIDE) ? tre_isspace(str_wide[j - 1]) :	\
@@ -540,7 +537,6 @@ tre_fastexec(const fastmatch_t *fg, cons
 	shift = fg->len;
     }
 
-  /* XXX: Fix with word boundaries */
   /* Only try once at the beginning or ending of the line. */
   if (!fg->newline && (fg->bol || fg->eol))
     {
@@ -554,6 +550,8 @@ tre_fastexec(const fastmatch_t *fg, cons
 	  COMPARE;
 	  if (mismatch == REG_OK)
 	    {
+	      if (fg->word && !IS_ON_WORD_BOUNDARY)
+		return ret;
 	      pmatch[0].rm_so = j;
 	      pmatch[0].rm_eo = j + (type == STR_WIDE ? fg->wlen : fg->len);
 	      return REG_OK;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108142054.p7EKsDpV079319>