1extern crate libc;
10
11use libc::{c_char, c_int, c_uchar, c_ulong, c_void};
12use std::option::{Option};
13use std::ptr;
14
15#[allow(non_camel_case_types)]
16pub type compile_options = c_int;
17#[allow(non_camel_case_types)]
18pub type exec_options = c_int;
19#[allow(non_camel_case_types)]
20pub type fullinfo_field = c_int;
21#[allow(non_camel_case_types)]
22pub type study_options = c_int;
23
24pub const PCRE_UTF8: compile_options = 0x00000800;
25
26pub const PCRE_NO_UTF8_CHECK: c_int = 0x00002000;
28
29pub const PCRE_ERROR_NOMATCH: c_int = -1;
30pub const PCRE_ERROR_NULL: c_int = -2;
31
32pub const PCRE_INFO_CAPTURECOUNT: fullinfo_field = 2;
33pub const PCRE_INFO_NAMEENTRYSIZE: fullinfo_field = 7;
34pub const PCRE_INFO_NAMECOUNT: fullinfo_field = 8;
35pub const PCRE_INFO_NAMETABLE: fullinfo_field = 9;
36
37const PCRE_EXTRA_MATCH_LIMIT: c_ulong = 0x0002;
39const PCRE_EXTRA_MATCH_LIMIT_RECURSION: c_ulong = 0x0010;
42const PCRE_EXTRA_MARK: c_ulong = 0x0020;
43#[allow(non_camel_case_types)]
46pub enum pcre {}
47
48#[allow(non_camel_case_types)]
49#[repr(C)]
50pub struct pcre_extra {
51 flags: c_ulong,
52 study_data: *mut c_void,
53 match_limit_: c_ulong,
54 callout_data: *mut c_void,
55 tables: *const c_uchar,
56 match_limit_recursion_: c_ulong,
57 mark: *mut *mut c_uchar,
58 executable_jit: *mut c_void
59}
60
61impl pcre_extra {
62 pub fn match_limit(&self) -> Option<usize> {
66 if (self.flags & PCRE_EXTRA_MATCH_LIMIT) == 0 {
67 None
68 } else {
69 Some(self.match_limit_ as usize)
70 }
71 }
72
73 pub fn set_match_limit(&mut self, limit: u32) {
75 self.flags |= PCRE_EXTRA_MATCH_LIMIT;
76 self.match_limit_ = limit as c_ulong;
77 }
78
79 pub fn match_limit_recursion(&self) -> Option<usize> {
83 if (self.flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) == 0 {
84 None
85 } else {
86 Some(self.match_limit_recursion_ as usize)
87 }
88 }
89
90 pub fn set_match_limit_recursion(&mut self, limit: u32) {
92 self.flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
93 self.match_limit_ = limit as c_ulong;
94 }
95
96 pub unsafe fn set_mark(&mut self, mark: &mut *mut c_uchar) {
98 self.flags |= PCRE_EXTRA_MARK;
99 self.mark = mark as *mut *mut c_uchar;
100 }
101
102 pub fn unset_mark(&mut self) {
104 self.flags &= !PCRE_EXTRA_MARK;
105 self.mark = ptr::null_mut();
106 }
107}
108
109#[link(name = "pcre")]
110extern {
111 pub static pcre_free: extern "C" fn(ptr: *mut c_void);
112
113 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;
114 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;
115 pub fn pcre_free_study(extra: *mut pcre_extra);
116 pub fn pcre_fullinfo(code: *const pcre, extra: *const pcre_extra, what: fullinfo_field, where_: *mut c_void) -> c_int;
117 pub fn pcre_refcount(code: *mut pcre, adjust: c_int) -> c_int;
119 pub fn pcre_study(code: *const pcre, options: study_options, errptr: *mut *const c_char) -> *mut pcre_extra;
120 pub fn pcre_version() -> *const c_char;
121}