boyer_moore_magiclen/
lib.rs

1/*!
2# Boyer-Moore-MagicLen
3
4This 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).
5
6## Usage
7
8For binary data and UTF-8 data, use the `BMByte` struct. For character sequences, use the `BMCharacter` struct (however it is much slower than `BMByte`). The `BMCharacter` struct needs the standard library support, and you have to enable the `character` feature to make it available.
9
10Every `BMXXX` has a `from` associated function to create the instance by a search pattern (the needle).
11
12For example,
13
14```rust
15use boyer_moore_magiclen::BMByte;
16
17let bmb = BMByte::from("oocoo").unwrap();
18```
19
20Now, we can search any binary data or UTF-8 data for the pattern `oocoo`.
21
22There 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.
23
24```rust
25use boyer_moore_magiclen::BMByte;
26
27let bmb = BMByte::from("oocoo").unwrap();
28
29assert_eq!(vec![1, 4], bmb.find_full_in("coocoocoocoo", 2));
30```
31
32The other mode is called **normal text search**, which finds the positions of the matched sub-sequences excluding the overlapping ones.
33
34```rust
35use boyer_moore_magiclen::BMByte;
36
37let bmb = BMByte::from("oocoo").unwrap();
38
39assert_eq!(vec![1, 7], bmb.find_in("coocoocoocoo", 2));
40```
41
42The search direction can be from the head (searching forward, `find_xxx`) or from the tail (searching backward, `rfind_xxx`).
43
44```rust
45use boyer_moore_magiclen::BMByte;
46
47let bmb = BMByte::from("oocoo").unwrap();
48
49assert_eq!(vec![7, 1], bmb.rfind_in("coocoocoocoo", 2));
50```
51
52To search all results at a time, use the `find_all_in`, `rfind_all_in`, `find_full_all_in` or `rfind_full_all_in` method.
53
54```rust
55use boyer_moore_magiclen::BMByte;
56
57let bmb = BMByte::from("oocoo").unwrap();
58
59assert_eq!(vec![7, 4, 1], bmb.rfind_full_all_in("coocoocoocoo"));
60```
61*/
62
63#![cfg_attr(not(feature = "character"), no_std)]
64#![cfg_attr(docsrs, feature(doc_cfg))]
65
66#[macro_use]
67extern crate alloc;
68
69/// This module helps you search sub-sequences in any byte sequence, including self-synchronizing string encoding data such as UTF-8.
70pub mod byte;
71#[cfg(feature = "character")]
72/// This module helps you search character sub-sequences in any character sequence.
73pub mod character;
74
75pub use byte::{BMByte, BMByteBadCharShiftMap, BMByteBadCharShiftMapRev, BMByteSearchable};
76#[cfg(feature = "character")]
77pub use character::{
78    BMCharacter, BMCharacterBadCharShiftMap, BMCharacterBadCharShiftMapRev, BMCharacterSearchable,
79};