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

Link to this function

alloc_scratch(db)

Allocate a scratch memory buffer for running the regex.

Link to this function

clone_scratch(scratch)

Create a new scratch buffer of the same size.

Link to this function

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 to flags.
  • platform. Either the result of populate_platform or nil.

See the docs for more information: http://intel.github.io/hyperscan/dev-reference/api_files.html#c.hs_compile

Link to this function

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 to flags.
  • platform. Either the result of populate_platform or nil.

See the docs for more information: http://intel.github.io/hyperscan/dev-reference/api_files.html#c.hs_compile

Link to this function

expression_info(expression, flags)

Returns a map with debugging info about a regular expression.

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
Link to this function

match(db, string, scratch)

Test whether the given compiled regex matches a string.

Requires a scratch buffer allocated by alloc_scratch/1.

Link to this function

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.

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
Link to this function

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.

Link to this function

scratch_size(scratch)

Check the size of a scratch buffer.

Link to this function

valid_platform()

Check if the current system architecture supports Hyperscan.

Returns the compiled Hyperscan version as a string.