Hyperscan (hyperscan v0.1.1)
Summary
Functions
Allocate a scratch memory buffer for running the regex.
Create a new scratch buffer of the same size.
Compile a regular expression into a database.
Compile a regular expression into a database.
Returns a map with debugging info about a regular expression.
Look up a flag constant by name.
Test whether the given compiled regex matches a string.
Test whether multiple compiled regexes match a string.
Look up a mode constant by name.
Re-allocate a scratch memory buffer.
Check the size of a scratch buffer.
Check if the current system architecture supports Hyperscan.
Returns the compiled Hyperscan version as a string.
Functions
alloc_scratch(db)
Allocate a scratch memory buffer for running the regex.
clone_scratch(scratch)
Create a new scratch buffer of the same size.
compile(expression, flags, mode, platform)
Compile a regular expression into a database.
expression
is a regular expression, without the leading/trailing/
characters or flags.flags
is an integer. Use 0 for no flags, or bitwise-or together one or more results of the flags/1 function.mode
is an integer similar toflags
.platform
. Either the result ofpopulate_platform
or nil.
See the docs for more information: http://intel.github.io/hyperscan/dev-reference/api_files.html#c.hs_compile
compile_multi(expression_list, flags_list, id_list, mode, platform)
Compile a regular expression into a database.
expression
is a regular expression, without the leading/trailing/
characters or flags.flags
is an integer. Use 0 for no flags, or bitwise-or together one or more results of the flags/1 function.mode
is an integer similar toflags
.platform
. Either the result ofpopulate_platform
or nil.
See the docs for more information: http://intel.github.io/hyperscan/dev-reference/api_files.html#c.hs_compile
expression_info(expression, flags)
Returns a map with debugging info about a regular expression.
flag(name)
Look up a flag constant by name.
Returns the integer value of the Hyperscan flag constant with the given name. Names follow the pattern HSFLAG*. See the docs for available flag names.
The value is used by the compile and compile_multi functions. To use multiple flags simultaneously, combine their values with Bitwise.bor/2.
Raises :badarg if it is not a valid flag name.
Example
iex> Hyperscan.flag("HS_FLAG_CASELESS")
1
match(db, string, scratch)
Test whether the given compiled regex matches a string.
Requires a scratch buffer allocated by alloc_scratch/1.
match_multi(db, string, scratch)
Test whether multiple compiled regexes match a string.
The regex should be compiled by compile_multi. Returns a list of expression IDs that matched the string. Note that the order of the returned IDs is undefined.
mode(name)
Look up a mode constant by name.
Returns the integer value of the Hyperscan mode constant with the given name. Names follow the pattern HSMODE*. See the docs for available mode names.
The value is used by the compile and compile_multi functions. To use multiple modes simultaneously, combine their values with Bitwise.bor/2.
Raises :badarg if it is not a valid mode name.
Example
iex> Hyperscan.mode("HS_MODE_BLOCK")
1
realloc_scratch(db, scratch)
Re-allocate a scratch memory buffer.
If the scratch was allocated for a different database and is too small for the given one, it will be reallocated. Either way, the scratch is now safe to use for the given database. Returns :ok.
scratch_size(scratch)
Check the size of a scratch buffer.
valid_platform()
Check if the current system architecture supports Hyperscan.
version()
Returns the compiled Hyperscan version as a string.