1use crate::{ffi, translate::*, Error, RegexCompileFlags, RegexMatchFlags};
6
7crate::wrapper! {
8 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 pub struct Regex(Shared<ffi::GRegex>);
10
11 match fn {
12 ref => |ptr| ffi::g_regex_ref(ptr),
13 unref => |ptr| ffi::g_regex_unref(ptr),
14 type_ => || ffi::g_regex_get_type(),
15 }
16}
17
18impl Regex {
19 #[doc(alias = "g_regex_new")]
20 pub fn new(
21 pattern: &str,
22 compile_options: RegexCompileFlags,
23 match_options: RegexMatchFlags,
24 ) -> Result<Option<Regex>, crate::Error> {
25 unsafe {
26 let mut error = std::ptr::null_mut();
27 let ret = ffi::g_regex_new(
28 pattern.to_glib_none().0,
29 compile_options.into_glib(),
30 match_options.into_glib(),
31 &mut error,
32 );
33 if error.is_null() {
34 Ok(from_glib_full(ret))
35 } else {
36 Err(from_glib_full(error))
37 }
38 }
39 }
40
41 #[doc(alias = "g_regex_get_capture_count")]
42 #[doc(alias = "get_capture_count")]
43 pub fn capture_count(&self) -> i32 {
44 unsafe { ffi::g_regex_get_capture_count(self.to_glib_none().0) }
45 }
46
47 #[doc(alias = "g_regex_get_compile_flags")]
48 #[doc(alias = "get_compile_flags")]
49 pub fn compile_flags(&self) -> RegexCompileFlags {
50 unsafe { from_glib(ffi::g_regex_get_compile_flags(self.to_glib_none().0)) }
51 }
52
53 #[doc(alias = "g_regex_get_has_cr_or_lf")]
54 #[doc(alias = "get_has_cr_or_lf")]
55 pub fn has_cr_or_lf(&self) -> bool {
56 unsafe { from_glib(ffi::g_regex_get_has_cr_or_lf(self.to_glib_none().0)) }
57 }
58
59 #[doc(alias = "g_regex_get_match_flags")]
60 #[doc(alias = "get_match_flags")]
61 pub fn match_flags(&self) -> RegexMatchFlags {
62 unsafe { from_glib(ffi::g_regex_get_match_flags(self.to_glib_none().0)) }
63 }
64
65 #[doc(alias = "g_regex_get_max_backref")]
66 #[doc(alias = "get_max_backref")]
67 pub fn max_backref(&self) -> i32 {
68 unsafe { ffi::g_regex_get_max_backref(self.to_glib_none().0) }
69 }
70
71 #[doc(alias = "g_regex_get_max_lookbehind")]
72 #[doc(alias = "get_max_lookbehind")]
73 pub fn max_lookbehind(&self) -> i32 {
74 unsafe { ffi::g_regex_get_max_lookbehind(self.to_glib_none().0) }
75 }
76
77 #[doc(alias = "g_regex_get_pattern")]
78 #[doc(alias = "get_pattern")]
79 pub fn pattern(&self) -> crate::GString {
80 unsafe { from_glib_none(ffi::g_regex_get_pattern(self.to_glib_none().0)) }
81 }
82
83 }