svn commit: r225098 - user/gabor/tre-integration/contrib/tre/lib

Gabor Kovesdan gabor at FreeBSD.org
Tue Aug 23 00:12:25 UTC 2011


Author: gabor
Date: Tue Aug 23 00:12:24 2011
New Revision: 225098
URL: http://svn.freebsd.org/changeset/base/225098

Log:
  - [] brackets are parsed differently than other brackets because [ and ]
    are interpreted differently in some special cases

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

Modified: user/gabor/tre-integration/contrib/tre/lib/tre-heuristic.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre-heuristic.c	Mon Aug 22 23:54:12 2011	(r225097)
+++ user/gabor/tre-integration/contrib/tre/lib/tre-heuristic.c	Tue Aug 23 00:12:24 2011	(r225098)
@@ -39,6 +39,13 @@
 #include "tre-internal.h"
 #include "xmalloc.h"
 
+#ifdef TRE_WCHAR
+#define tre_strnstr(big, s1, little, s2)				\
+  memmem(big, s1 * sizeof(tre_char_t), little, s2 * sizeof(tre_char_t))
+#else
+#define tre_strnstr(big, s1, little, s2) strnstr(big, little, s1)
+#endif
+
 /*
  * A full regex implementation requires a finite state automaton
  * and using an automaton is always about a trade-off. A DFA is
@@ -75,6 +82,40 @@
       }									\
   }
 
+#define PARSE_BRACKETS							\
+  {									\
+    tre_char_t *tmp;							\
+									\
+    i++;								\
+    if (regex[i] == TRE_CHAR('^'))					\
+      i++;								\
+    if (regex[i] == TRE_CHAR(']'))					\
+      i++;								\
+									\
+    do									\
+      {									\
+	tmp = tre_strnstr(&regex[i], len - i, TRE_CHAR("[.].]"), 5);	\
+	if (tmp)							\
+	  {								\
+	    i += (tmp - regex);						\
+	    regex = tmp;						\
+	  }								\
+      } while (tmp != NULL);						\
+									\
+    do									\
+      {									\
+	tmp = tre_strnstr(&regex[i], len - i, TRE_CHAR("[=]=]"), 5);	\
+	if (tmp)							\
+	  {								\
+	    i += (tmp - regex);						\
+	    regex = tmp;						\
+	  }								\
+      } while (tmp != NULL);						\
+									\
+    for (; (i != TRE_CHAR(']')) && (i < len); i++);			\
+  }
+
+
 /*
  * Finishes a segment (fixed-length text fragment).
  */
@@ -129,7 +170,7 @@ tre_compile_heur(heur_t *h, const tre_ch
 
 	      /* Bracketed expression is substituted with a dot. */
 	      case TRE_CHAR('['):
-		PARSE_UNIT('[', ']');
+		PARSE_BRACKETS;
 		heur[pos++] = TRE_CHAR('.');
 		continue;
 


More information about the svn-src-user mailing list