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
/*!
# Boyer-Moore-MagicLen

This crate can be used to search substrings in a string or search any sub-sequences in any sequence by using boyer-moore-magiclen (which is sometimes faster than boyer-moore and boyer-moore-horspool).

## Usage

For binary data and UTF-8 data, use the `BMByte` struct. For character sequences, use the `BMCharacter` struct (however it is much slower than `BMByte`).

Every `BMXXX` has a `from` associated function to create the instance by a search pattern (the needle).

For example,

```rust
extern crate boyer_moore_magiclen;

use boyer_moore_magiclen::BMByte;

let bmb = BMByte::from("oocoo").unwrap();
```

Now, we can search any binary data or UTF-8 data for the pattern `oocoo`.

There are two search modes and two search directions. The first mode is called **full text search**, which finds the positions of the matched sub-sequences including the overlapping ones.

```rust
extern crate boyer_moore_magiclen;

use boyer_moore_magiclen::BMByte;

let bmb = BMByte::from("oocoo").unwrap();

assert_eq!(vec![1, 4], bmb.find_full_in("coocoocoocoo", 2));
```

The other mode is called **normal text search**, which finds the positions of the matched sub-sequences excluding the overlapping ones.

```rust
extern crate boyer_moore_magiclen;

use boyer_moore_magiclen::BMByte;

let bmb = BMByte::from("oocoo").unwrap();

assert_eq!(vec![1, 7], bmb.find_in("coocoocoocoo", 2));
```

The search direction can be from the head (searching forward, `find_xxx`) or from the tail (searching backward, `rfind_xxx`).

```rust
extern crate boyer_moore_magiclen;

use boyer_moore_magiclen::BMByte;

let bmb = BMByte::from("oocoo").unwrap();

assert_eq!(vec![7, 1], bmb.rfind_in("coocoocoocoo", 2));
```

To search all results at a time, use the `find_all_in`, `rfind_all_in`, `find_full_all_in` or `rfind_full_all_in` method.

```rust
extern crate boyer_moore_magiclen;

use boyer_moore_magiclen::BMByte;

let bmb = BMByte::from("oocoo").unwrap();

assert_eq!(vec![7, 4, 1], bmb.rfind_full_all_in("coocoocoocoo"));
```

*/

/// This module helps you search sub-sequences in any byte sequence, including self-synchronizing string encoding data such as UTF-8.
pub mod byte;
/// This module helps you search character sub-sequences in any character sequence.
pub mod character;

pub use byte::{BMByte, BMByteSearchable, BMByteBadCharShiftMap, BMByteBadCharShiftMapRev};
pub use character::{BMCharacter, BMCharacterSearchable, BMCharacterBadCharShiftMap, BMCharacterBadCharShiftMapRev};