svn commit: r225087 - user/gabor/tre-integration/contrib/tre/lib
Gabor Kovesdan
gabor at FreeBSD.org
Mon Aug 22 20:25:55 UTC 2011
Author: gabor
Date: Mon Aug 22 20:25:55 2011
New Revision: 225087
URL: http://svn.freebsd.org/changeset/base/225087
Log:
- Partly fix offset handling
Modified:
user/gabor/tre-integration/contrib/tre/lib/regexec.c
Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/regexec.c Mon Aug 22 19:46:25 2011 (r225086)
+++ user/gabor/tre-integration/contrib/tre/lib/regexec.c Mon Aug 22 20:25:55 2011 (r225087)
@@ -162,42 +162,76 @@ tre_match(const tre_tnfa_t *tnfa, const
return tre_match_fast(shortcut, string, len, type, nmatch,
pmatch, eflags);
+#define FIX_OFFSETS \
+ if (ret == REG_NOMATCH) \
+ { \
+ st += n; \
+ continue; \
+ } \
+ else if ((ret == REG_OK) && !(tnfa->cflags & REG_NOSUB)) \
+ for (int i = 0; i < nmatch; i++) \
+ { \
+ pmatch[i].rm_so += st; \
+ pmatch[i].rm_eo += st; \
+ } \
+ return ret;
+
+#define SEEK_TO(off) \
+ string = (type == STR_WIDE) ? (void *)&data_wide[off] : \
+ (void *)&data_byte[off];
+
/* Check if we have a heuristic to speed up the search. */
if (heur != NULL)
{
int ret;
- size_t st = 0, j;
+ size_t st = 0, n;
const char *data_byte = string;
const tre_char_t *data_wide = string;
- const void *tmp;
- /* Look for the beginning of possibly matching text. */
- ret = tre_match_fast(heur->start, string, len, type, nmatch,
- pmatch, eflags);
- if (ret != REG_OK)
- return ret;
- st = pmatch[0].rm_so;
- j = pmatch[0].rm_eo;
- string = (type == STR_WIDE) ? (void *)&data_wide[st] :
- (void *)&data_byte[st];
-
- /* When having a fixed-length pattern there is only one heuristic. */
- if (heur->end == NULL)
- return tre_match(tnfa, string,
- heur->prefix ? (len - st) : (j - st),
- type, nmatch, pmatch, eflags, NULL, NULL);
-
- tmp = (type == STR_WIDE) ? (void *)&data_wide[j] :
- (void *)&data_byte[j];
-
- /* Look for the end of possibly matching text. */
- ret = tre_match_fast(heur->end, tmp, len - j, type, nmatch,
- pmatch, eflags);
- if (ret != REG_OK)
- return ret;
+ while (st < len)
+ {
+ SEEK_TO(st);
- return tre_match(tnfa, string, pmatch[0].rm_eo + j - st,
- type, nmatch, pmatch, eflags, NULL, NULL);
+ /* Look for the beginning of possibly matching text. */
+ ret = tre_match_fast(heur->start, string, len - st, type, nmatch,
+ pmatch, eflags);
+ if (ret != REG_OK)
+ return ret;
+ st += pmatch[0].rm_so;
+ n = pmatch[0].rm_eo;
+
+ /*
+ * When having a fixed-length pattern there is only
+ * one heuristic.
+ */
+ if (heur->end == NULL)
+ {
+ SEEK_TO(st);
+
+ ret = tre_match(tnfa, string,
+ heur->prefix ? (len - st) :
+ n, type, nmatch,
+ pmatch, eflags, NULL, NULL);
+
+ FIX_OFFSETS;
+ }
+
+ SEEK_TO(st + n);
+
+ /* Look for the end of possibly matching text. */
+ ret = tre_match_fast(heur->end, string, len - st - n, type,
+ nmatch, pmatch, eflags);
+
+ if (ret != REG_OK)
+ return ret;
+
+ SEEK_TO(st);
+
+ ret = tre_match(tnfa, string, pmatch[0].rm_eo + n,
+ type, nmatch, pmatch, eflags, NULL, NULL);
+
+ FIX_OFFSETS;
+ }
}
if (tnfa->num_tags > 0 && nmatch > 0)
More information about the svn-src-user
mailing list