1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! Hyperscan is a high-performance regular expression matching library.
//!
//! # Usage
//!
//! This crate is on crates.io and can be used by adding `hyperscan` to your dependencies in your project's Cargo.toml.
//!
//! ```toml
//! [dependencies]
//! hyperscan = "0.3"
//! ```
//!
//! # Examples
//!
//! ```
//! #[macro_use]
//! extern crate hyperscan;
//!
//! use hyperscan::prelude::*;
//!
//! fn main() {
//!     let pattern = pattern! {"test"; CASELESS | SOM_LEFTMOST};
//!     let db: BlockDatabase = pattern.build().unwrap();
//!     let scratch = db.alloc_scratch().unwrap();
//!
//!     db.scan("some test data", &scratch, |id, from, to, _flags| {
//!         assert_eq!(id, 0);
//!         assert_eq!(from, 5);
//!         assert_eq!(to, 9);
//!
//!         println!("found pattern {} : {} @ [{}, {})", id, pattern.expression, from, to);
//!
//!         Matching::Continue
//!     }).unwrap();
//! }
//! ```
#![deny(missing_docs, rust_2018_compatibility, rust_2018_idioms)]
#![cfg_attr(test, deny(warnings))]
#![cfg_attr(feature = "pattern", feature(pattern))]

mod ffi {
    pub use hyperscan_sys::*;
}

mod common;
mod error;
#[cfg(feature = "compile")]
#[macro_use]
mod compile;
#[cfg(feature = "chimera")]
pub mod chimera;
#[cfg(all(feature = "compile", feature = "runtime"))]
pub mod regex;
#[cfg(feature = "runtime")]
mod runtime;

#[doc(hidden)]
#[deprecated = "use `BlockMode` instead"]
pub use crate::common::Block;
#[doc(hidden)]
#[deprecated = "use `SerializedDatabase` instead"]
pub use crate::common::Serialized;
#[doc(hidden)]
#[deprecated = "use `StreamingMode` instead"]
pub use crate::common::Streaming;
#[doc(hidden)]
#[deprecated = "use `VectoredMode` instead"]
pub use crate::common::Vectored;
pub use crate::common::{
    version, version_str, Block as BlockMode, BlockDatabase, Database, DatabaseRef, Error as HsError, Mode,
    Serialized as SerializedDatabase, Streaming as StreamingMode, StreamingDatabase, Vectored as VectoredMode,
    VectoredDatabase,
};
pub use crate::error::{Error, Result};

cfg_if::cfg_if! {
    if #[cfg(feature = "compile")] {
        #[doc(hidden)]
        #[deprecated = "use `ExprExt` instead"]
        pub use crate::compile::ExprExt as ExpressionExt;
        #[doc(hidden)]
        #[deprecated = "use `ExprInfo` instead"]
        pub use crate::compile::ExprInfo as ExpressionInfo;
        #[doc(hidden)]
        #[deprecated = "use `PatternFlags` instead"]
        pub use crate::compile::Flags as CompileFlags;
        pub use crate::compile::{
            compile, Builder as DatabaseBuilder, Builder, CpuFeatures, Error as CompileError, ExprExt, ExprInfo,
            Flags as PatternFlags, Pattern, Patterns, Platform, PlatformRef, SomHorizon, Tune,
        };
        #[cfg(feature = "literal")]
        pub use crate::compile::{Literal, LiteralFlags, Literals};
    }
}

#[cfg(feature = "runtime")]
pub use crate::runtime::{MatchEventHandler, Matching, Scratch, ScratchRef, Stream, StreamRef};

/// The `hyperscan` Prelude
pub mod prelude {
    #[cfg(feature = "compile")]
    pub use crate::{compile, pattern, Builder, CompileFlags, Pattern, Patterns};

    #[cfg(feature = "runtime")]
    pub use crate::{Matching, Scratch, Stream};

    pub use crate::{BlockDatabase, Database, Mode, StreamingDatabase, VectoredDatabase};
}

#[cfg(doctest)]
#[macro_use]
extern crate doc_comment;

#[cfg(doctest)]
doctest!("../../README.md");

#[cfg(test)]
mod tests {
    pub use super::common::tests::*;
}