Date: Mon, 22 Aug 2011 20:25:55 +0000 (UTC) From: Gabor Kovesdan <gabor@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r225087 - user/gabor/tre-integration/contrib/tre/lib Message-ID: <201108222025.p7MKPt57067131@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108222025.p7MKPt57067131>