mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-30 19:47:43 +03:00
add new Literal API for pure literal expressions:
Design compile time api hs_compile_lit() and hs_compile_lit_multi() to handle pure literal pattern sets. Corresponding option --literal-on is added for hyperscan testing suites. Extended parameters and part of flags are not supported for this api.
This commit is contained in:
committed by
Chang, Harry
parent
8bfbf07f75
commit
23e5f06594
@@ -43,6 +43,7 @@
|
||||
#include "parser/Parser.h"
|
||||
#include "parser/parse_error.h"
|
||||
#include "util/make_unique.h"
|
||||
#include "util/string_util.h"
|
||||
#include "util/unicode_def.h"
|
||||
#include "util/unordered.h"
|
||||
|
||||
@@ -111,6 +112,15 @@ bool decodeExprPcre(string &expr, unsigned *flags, bool *highlander,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (use_literal_api) {
|
||||
// filter out flags not supported by pure literal API.
|
||||
u32 not_supported = HS_FLAG_DOTALL | HS_FLAG_ALLOWEMPTY | HS_FLAG_UTF8 |
|
||||
HS_FLAG_UCP | HS_FLAG_PREFILTER;
|
||||
hs_flags &= ~not_supported;
|
||||
force_utf8 = false;
|
||||
force_prefilter = false;
|
||||
}
|
||||
|
||||
expr.swap(regex);
|
||||
|
||||
if (!getPcreFlags(hs_flags, flags, highlander, prefilter, som,
|
||||
@@ -260,9 +270,29 @@ GroundTruth::compile(unsigned id, bool no_callouts) {
|
||||
throw PcreCompileFailure("Unable to decode flags.");
|
||||
}
|
||||
|
||||
// When hyperscan literal api is on, transfer the regex string into hex.
|
||||
if (use_literal_api && !combination) {
|
||||
unsigned char *pat
|
||||
= reinterpret_cast<unsigned char *>(const_cast<char *>(re.c_str()));
|
||||
char *str = makeHex(pat, re.length());
|
||||
if (!str) {
|
||||
throw PcreCompileFailure("makeHex() malloc failure.");
|
||||
}
|
||||
re.assign(str);
|
||||
free(str);
|
||||
}
|
||||
|
||||
// filter out flags not supported by PCRE
|
||||
u64a supported = HS_EXT_FLAG_MIN_OFFSET | HS_EXT_FLAG_MAX_OFFSET |
|
||||
HS_EXT_FLAG_MIN_LENGTH;
|
||||
if (use_literal_api) {
|
||||
ext.flags &= 0ULL;
|
||||
ext.min_offset = 0;
|
||||
ext.max_offset = MAX_OFFSET;
|
||||
ext.min_length = 0;
|
||||
ext.edit_distance = 0;
|
||||
ext.hamming_distance = 0;
|
||||
}
|
||||
if (ext.flags & ~supported) {
|
||||
// edit distance is a known unsupported flag, so just throw a soft error
|
||||
if (ext.flags & HS_EXT_FLAG_EDIT_DISTANCE) {
|
||||
@@ -314,7 +344,6 @@ GroundTruth::compile(unsigned id, bool no_callouts) {
|
||||
return compiled;
|
||||
}
|
||||
|
||||
|
||||
compiled->bytecode =
|
||||
pcre_compile2(re.c_str(), flags, &errcode, &errptr, &errloc, nullptr);
|
||||
|
||||
|
Reference in New Issue
Block a user