4 * Copyright (C) 2011 Gabor Kovesdan <gabor@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <fastmatch.h>
36 #include "tre-fastmatch.h"
40 tre_fixncomp(fastmatch_t *preg, const char *regex, size_t n, int cflags)
48 ret = tre_convert_pattern(regex, n, &wregex, &wlen);
52 ret = tre_compile_literal(preg, wregex, wlen, cflags);
53 tre_free_pattern(wregex);
57 return tre_compile_literal(preg, NULL, 0, cflags);
61 tre_fastncomp(fastmatch_t *preg, const char *regex, size_t n, int cflags)
69 ret = tre_convert_pattern(regex, n, &wregex, &wlen);
73 ret = (cflags & REG_LITERAL)
74 ? tre_compile_literal(preg, wregex, wlen, cflags)
75 : tre_compile_fast(preg, wregex, wlen, cflags);
76 tre_free_pattern(wregex);
80 return tre_compile_literal(preg, NULL, 0, cflags);
85 tre_fixcomp(fastmatch_t *preg, const char *regex, int cflags)
87 return tre_fixncomp(preg, regex, regex ? strlen(regex) : 0, cflags);
91 tre_fastcomp(fastmatch_t *preg, const char *regex, int cflags)
93 return tre_fastncomp(preg, regex, regex ? strlen(regex) : 0, cflags);
97 tre_fixwncomp(fastmatch_t *preg, const wchar_t *regex, size_t n, int cflags)
99 return tre_compile_literal(preg, regex, n, cflags);
103 tre_fastwncomp(fastmatch_t *preg, const wchar_t *regex, size_t n, int cflags)
105 return (cflags & REG_LITERAL) ?
106 tre_compile_literal(preg, regex, n, cflags) :
107 tre_compile_fast(preg, regex, n, cflags);
111 tre_fixwcomp(fastmatch_t *preg, const wchar_t *regex, int cflags)
113 return tre_fixwncomp(preg, regex, regex ? tre_strlen(regex) : 0, cflags);
117 tre_fastwcomp(fastmatch_t *preg, const wchar_t *regex, int cflags)
119 return tre_fastwncomp(preg, regex, regex ? tre_strlen(regex) : 0, cflags);
123 tre_fastfree(fastmatch_t *preg)
129 tre_fastnexec(const fastmatch_t *preg, const char *string, size_t len,
130 size_t nmatch, regmatch_t pmatch[], int eflags)
132 tre_str_type_t type = (TRE_MB_CUR_MAX == 1) ? STR_BYTE : STR_MBS;
134 if (eflags & REG_STARTEND)
135 CALL_WITH_OFFSET(tre_match_fast(preg, &string[offset], slen,
136 type, nmatch, pmatch, eflags));
138 return tre_match_fast(preg, string, len, type, nmatch,
143 tre_fastexec(const fastmatch_t *preg, const char *string, size_t nmatch,
144 regmatch_t pmatch[], int eflags)
146 return tre_fastnexec(preg, string, (size_t)-1, nmatch, pmatch, eflags);
150 tre_fastwnexec(const fastmatch_t *preg, const wchar_t *string, size_t len,
151 size_t nmatch, regmatch_t pmatch[], int eflags)
153 tre_str_type_t type = STR_WIDE;
155 if (eflags & REG_STARTEND)
156 CALL_WITH_OFFSET(tre_match_fast(preg, &string[offset], slen,
157 type, nmatch, pmatch, eflags));
159 return tre_match_fast(preg, string, len, type, nmatch,
164 tre_fastwexec(const fastmatch_t *preg, const wchar_t *string,
165 size_t nmatch, regmatch_t pmatch[], int eflags)
167 return tre_fastwnexec(preg, string, (size_t)-1, nmatch, pmatch, eflags);