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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! These are safe bindings to the [`tre_regex_sys`] module.
//!
//! These bindings are designed to provide an idiomatic Rust-like API to the [TRE library] as much
//! as possible. Most of the TRE API is suported, except [`reguexec`] from TRE; that is tricky to
//! implement, although should be fairly simple to use yourself.
//!
//! This library uses Rust [`std::borrow::Cow`] strings to enable zero-copy of regex matches.
//!
//! # Examples
//! Two API's are presented: the function API, and the object API. Whichever one you choose to use
//! is up to you, although the function API is implemented as a thin wrapper around the object API.
//!
//! ## Object API
//! ```
//! # use tre_regex::Result;
//! # fn main() -> Result<()> {
//! use tre_regex::{RegcompFlags, RegexecFlags, Regex};
//!
//! let regcomp_flags = RegcompFlags::new().add(RegcompFlags::EXTENDED);
//! let regexec_flags = RegexecFlags::new().add(RegexecFlags::NONE);
//!
//! let compiled_reg = Regex::new("^([[:alnum:]]+)[[:space:]]*([[:alnum:]]+)$", regcomp_flags)?;
//! let matches = compiled_reg.regexec("hello world", 2, regexec_flags)?;
//!
//! for (i, matched) in matches.into_iter().enumerate() {
//! match matched {
//! Some(res) => {
//! match res {
//! Ok(substr) => println!("Match {i}: '{}'", substr),
//! Err(e) => println!("Match {i}: <Error: {e}>"),
//! }
//! },
//! None => println!("Match {i}: <None>"),
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Function API
//! ```
//! # use tre_regex::Result;
//! # fn main() -> Result<()> {
//! use tre_regex::{RegcompFlags, RegexecFlags, regcomp, regexec};
//!
//! let regcomp_flags = RegcompFlags::new().add(RegcompFlags::EXTENDED);
//! let regexec_flags = RegexecFlags::new().add(RegexecFlags::NONE);
//!
//! let compiled_reg = regcomp("^([[:alnum:]]+)[[:space:]]*([[:alnum:]]+)$", regcomp_flags)?;
//! let matches = regexec(&compiled_reg, "hello world", 2, regexec_flags)?;
//!
//! for (i, matched) in matches.into_iter().enumerate() {
//! match matched {
//! Some(res) => {
//! match res {
//! Ok(substr) => println!("Match {i}: '{}'", substr),
//! Err(e) => println!("Match {i}: <Error: {e}>"),
//! }
//! },
//! None => println!("Match {i}: <None>"),
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! [TRE library]: <https://laurikari.net/tre/>
//! [`reguexec`]: tre_regex_sys::tre_reguexec
/// Public re-export of the [`tre_regex_sys`] module.
pub use tre_regex_sys as tre;
pub use crate*;
pub use crate*;
pub use crate*;
pub use crate*;
pub use crate*;
pub use crate*;
/// The base regex object.
///
/// This object takes care of freeing itself upon dropping, so you don't have to call
/// [`tre_regfree`](tre_regex_sys::tre_regfree) yourself.
///
/// This object provides an API similar to the function API. See the documentation on the
/// individual functions for more information.
;