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
extern crate libc;
use libc::{c_char, c_int, c_uchar, c_ulong, c_void};
use std::option::{Option};
use std::ptr;
#[allow(non_camel_case_types)]
pub type compile_options = c_int;
#[allow(non_camel_case_types)]
pub type exec_options = c_int;
#[allow(non_camel_case_types)]
pub type fullinfo_field = c_int;
#[allow(non_camel_case_types)]
pub type study_options = c_int;
pub const PCRE_UTF8: compile_options = 0x00000800;
pub const PCRE_NO_UTF8_CHECK: c_int = 0x00002000;
pub const PCRE_ERROR_NOMATCH: c_int = -1;
pub const PCRE_ERROR_NULL: c_int = -2;
pub const PCRE_INFO_CAPTURECOUNT: fullinfo_field = 2;
pub const PCRE_INFO_NAMEENTRYSIZE: fullinfo_field = 7;
pub const PCRE_INFO_NAMECOUNT: fullinfo_field = 8;
pub const PCRE_INFO_NAMETABLE: fullinfo_field = 9;
const PCRE_EXTRA_MATCH_LIMIT: c_ulong = 0x0002;
const PCRE_EXTRA_MATCH_LIMIT_RECURSION: c_ulong = 0x0010;
const PCRE_EXTRA_MARK: c_ulong = 0x0020;
#[allow(non_camel_case_types)]
pub enum pcre {}
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct pcre_extra {
flags: c_ulong,
study_data: *mut c_void,
match_limit_: c_ulong,
callout_data: *mut c_void,
tables: *const c_uchar,
match_limit_recursion_: c_ulong,
mark: *mut *mut c_uchar,
executable_jit: *mut c_void
}
impl pcre_extra {
pub fn match_limit(&self) -> Option<usize> {
if (self.flags & PCRE_EXTRA_MATCH_LIMIT) == 0 {
None
} else {
Some(self.match_limit_ as usize)
}
}
pub fn set_match_limit(&mut self, limit: u32) {
self.flags |= PCRE_EXTRA_MATCH_LIMIT;
self.match_limit_ = limit as c_ulong;
}
pub fn match_limit_recursion(&self) -> Option<usize> {
if (self.flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) == 0 {
None
} else {
Some(self.match_limit_recursion_ as usize)
}
}
pub fn set_match_limit_recursion(&mut self, limit: u32) {
self.flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
self.match_limit_ = limit as c_ulong;
}
pub unsafe fn set_mark(&mut self, mark: &mut *mut c_uchar) {
self.flags |= PCRE_EXTRA_MARK;
self.mark = mark as *mut *mut c_uchar;
}
pub fn unset_mark(&mut self) {
self.flags &= !PCRE_EXTRA_MARK;
self.mark = ptr::null_mut();
}
}
#[link(name = "pcre")]
extern {
pub static pcre_free: extern "C" fn(ptr: *mut c_void);
pub fn pcre_compile(pattern: *const c_char, options: compile_options, errptr: *mut *const c_char, erroffset: *mut c_int, tableptr: *const c_uchar) -> *mut pcre;
pub fn pcre_exec(code: *const pcre, extra: *const pcre_extra, subject: *const c_char, length: c_int, startoffset: c_int, options: exec_options, ovector: *mut c_int, ovecsize: c_int) -> c_int;
pub fn pcre_free_study(extra: *mut pcre_extra);
pub fn pcre_fullinfo(code: *const pcre, extra: *const pcre_extra, what: fullinfo_field, where_: *mut c_void) -> c_int;
pub fn pcre_refcount(code: *mut pcre, adjust: c_int) -> c_int;
pub fn pcre_study(code: *const pcre, options: study_options, errptr: *mut *const c_char) -> *mut pcre_extra;
pub fn pcre_version() -> *const c_char;
}