From owner-svn-src-user@FreeBSD.ORG Tue Aug 23 00:12:25 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 13E8A1065689; Tue, 23 Aug 2011 00:12:25 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DE5448FC19; Tue, 23 Aug 2011 00:12:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p7N0COHv076424; Tue, 23 Aug 2011 00:12:24 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7N0COaY076422; Tue, 23 Aug 2011 00:12:24 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201108230012.p7N0COaY076422@svn.freebsd.org> From: Gabor Kovesdan Date: Tue, 23 Aug 2011 00:12:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225098 - user/gabor/tre-integration/contrib/tre/lib X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Aug 2011 00:12:25 -0000 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(®ex[i], len - i, TRE_CHAR("[.].]"), 5); \ + if (tmp) \ + { \ + i += (tmp - regex); \ + regex = tmp; \ + } \ + } while (tmp != NULL); \ + \ + do \ + { \ + tmp = tre_strnstr(®ex[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;