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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::ffi;
use glib::translate::*;

glib::wrapper! {
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct Regex(Shared<ffi::VteRegex>);

    match fn {
        ref => |ptr| ffi::vte_regex_ref(ptr),
        unref => |ptr| ffi::vte_regex_unref(ptr),
        type_ => || ffi::vte_regex_get_type(),
    }
}

impl Regex {
    /// Compiles @pattern into a regex for use as a match regex
    /// with vte_terminal_match_add_regex() or
    /// vte_terminal_event_check_regex_simple().
    ///
    /// See man:pcre2pattern(3) for information
    /// about the supported regex language, and man:pcre2api(3) for
    /// information about the supported @flags.
    ///
    /// The regex will be compiled using <literal>PCRE2_UTF</literal> and
    /// possibly other flags, in addition to the flags supplied in @flags.
    /// ## `pattern`
    /// a regex pattern string
    /// ## `pattern_length`
    /// the length of @pattern in bytes, or -1 if the
    ///  string is NUL-terminated and the length is unknown
    /// ## `flags`
    /// PCRE2 compile flags
    ///
    /// # Returns
    ///
    /// a newly created #VteRegex, or [`None`] with @error filled in
    #[doc(alias = "vte_regex_new_for_match")]
    #[doc(alias = "new_for_match")]
    pub fn for_match(pattern: &str, flags: u32) -> Result<Regex, glib::Error> {
        assert_initialized_main_thread!();
        let pattern_length = pattern.len() as _;
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::vte_regex_new_for_match(
                pattern.to_glib_none().0,
                pattern_length,
                flags,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Compiles @pattern into a regex for use as a match regex
    /// with vte_terminal_match_add_regex() or
    /// vte_terminal_event_check_regex_simple().
    ///
    /// See man:pcre2pattern(3) for information
    /// about the supported regex language, and man:pcre2api(3) for
    /// information about the supported @flags and @extra_flags.
    ///
    /// The regex will be compiled using <literal>PCRE2_UTF</literal> and
    /// possibly other flags, in addition to the flags supplied in @flags.
    ///
    /// If regex compilation fails, @error will be set and @error_offset point
    /// to error as an offset into @pattern.
    /// ## `pattern`
    /// a regex pattern string
    /// ## `pattern_length`
    /// the length of @pattern in bytes, or -1 if the
    ///  string is NUL-terminated and the length is unknown
    /// ## `flags`
    /// PCRE2 compile flags
    /// ## `extra_flags`
    /// PCRE2 extra compile flags
    ///
    /// # Returns
    ///
    /// a newly created #VteRegex, or [`None`]
    ///
    /// ## `error_offset`
    /// return location to store the error offset
    #[cfg(feature = "v0_76")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v0_76")))]
    #[doc(alias = "vte_regex_new_for_match_full")]
    #[doc(alias = "new_for_match_full")]
    pub fn for_match_full(
        pattern: &str,
        flags: u32,
        extra_flags: u32,
    ) -> Result<(Regex, usize), glib::Error> {
        assert_initialized_main_thread!();
        let pattern_length = pattern.len() as _;
        unsafe {
            let mut error_offset = std::mem::MaybeUninit::uninit();
            let mut error = std::ptr::null_mut();
            let ret = ffi::vte_regex_new_for_match_full(
                pattern.to_glib_none().0,
                pattern_length,
                flags,
                extra_flags,
                error_offset.as_mut_ptr(),
                &mut error,
            );
            if error.is_null() {
                Ok((from_glib_full(ret), error_offset.assume_init()))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Compiles @pattern into a regex for use as a search regex
    /// with vte_terminal_search_set_regex().
    ///
    /// See man:pcre2pattern(3) for information
    /// about the supported regex language, and man:pcre2api(3) for
    /// information about the supported @flags.
    ///
    /// The regex will be compiled using <literal>PCRE2_UTF</literal> and
    /// possibly other flags, in addition to the flags supplied in @flags.
    /// ## `pattern`
    /// a regex pattern string
    /// ## `pattern_length`
    /// the length of @pattern in bytes, or -1 if the
    ///  string is NUL-terminated and the length is unknown
    /// ## `flags`
    /// PCRE2 compile flags
    ///
    /// # Returns
    ///
    /// a newly created #VteRegex, or [`None`] with @error filled in
    #[doc(alias = "vte_regex_new_for_search")]
    #[doc(alias = "new_for_search")]
    pub fn for_search(pattern: &str, flags: u32) -> Result<Regex, glib::Error> {
        assert_initialized_main_thread!();
        let pattern_length = pattern.len() as _;
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::vte_regex_new_for_search(
                pattern.to_glib_none().0,
                pattern_length,
                flags,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Compiles @pattern into a regex for use as a search regex
    /// with vte_terminal_search_set_regex().
    ///
    /// See man:pcre2pattern(3) for information
    /// about the supported regex language, and man:pcre2api(3) for
    /// information about the supported @flags and @extra_flags.
    ///
    /// The regex will be compiled using <literal>PCRE2_UTF</literal> and
    /// possibly other flags, in addition to the flags supplied in @flags.
    ///
    /// If regex compilation fails, @error will be set and @error_offset point
    /// to error as an offset into @pattern.
    /// ## `pattern`
    /// a regex pattern string
    /// ## `pattern_length`
    /// the length of @pattern in bytes, or -1 if the
    ///  string is NUL-terminated and the length is unknown
    /// ## `flags`
    /// PCRE2 compile flags
    ///
    /// # Returns
    ///
    /// a newly created #VteRegex, or [`None`]
    ///
    /// ## `error_offset`
    /// return location to store the error offset
    #[cfg(feature = "v0_76")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v0_76")))]
    #[doc(alias = "vte_regex_new_for_search_full")]
    #[doc(alias = "new_for_search_full")]
    pub fn for_search_full(
        pattern: &str,
        flags: u32,
        extra_flags: u32,
    ) -> Result<(Regex, usize), glib::Error> {
        assert_initialized_main_thread!();
        let pattern_length = pattern.len() as _;
        unsafe {
            let mut error_offset = std::mem::MaybeUninit::uninit();
            let mut error = std::ptr::null_mut();
            let ret = ffi::vte_regex_new_for_search_full(
                pattern.to_glib_none().0,
                pattern_length,
                flags,
                extra_flags,
                error_offset.as_mut_ptr(),
                &mut error,
            );
            if error.is_null() {
                Ok((from_glib_full(ret), error_offset.assume_init()))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// If the platform supports JITing, JIT compiles @self.
    /// ## `flags`
    /// PCRE2 JIT flags, or 0
    ///
    /// # Returns
    ///
    /// [`true`] if JITing succeeded (or PCRE2 was built without
    ///   JIT support), or [`false`] with @error filled in
    #[doc(alias = "vte_regex_jit")]
    pub fn jit(&self, flags: u32) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::vte_regex_jit(self.to_glib_none().0, flags, &mut error);
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// See man:pcre2api(3) and man:pcre2_substitute(3) for more information.
    /// ## `subject`
    /// the subject string
    /// ## `replacement`
    /// the replacement string
    /// ## `flags`
    /// PCRE2 match flags
    ///
    /// # Returns
    ///
    /// the substituted string, or [`None`]
    ///   if an error occurred
    #[doc(alias = "vte_regex_substitute")]
    pub fn substitute(
        &self,
        subject: &str,
        replacement: &str,
        flags: u32,
    ) -> Result<glib::GString, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::vte_regex_substitute(
                self.to_glib_none().0,
                subject.to_glib_none().0,
                replacement.to_glib_none().0,
                flags,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}