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
use crate::SearchContext;
use glib::translate::*;
use glib::IsA;

pub trait SearchContextExtManual: 'static {
    /// Replaces all search matches by another text. It is a synchronous function, so
    /// it can block the user interface.
    ///
    /// For a regular expression replacement, you can check if `replace` is valid by
    /// calling `g_regex_check_replacement()`. The `replace` text can contain
    /// backreferences; read the `g_regex_replace()` documentation for more details.
    /// ## `replace`
    /// the replacement text.
    /// ## `replace_length`
    /// the length of `replace` in bytes, or -1.
    ///
    /// # Returns
    ///
    /// the number of replaced matches.
    #[doc(alias = "gtk_source_search_context_replace_all")]
    fn replace_all(&self, replace: &str) -> Result<(), glib::Error>;
}

impl<O: IsA<SearchContext>> SearchContextExtManual for O {
    fn replace_all(&self, replace: &str) -> Result<(), glib::Error> {
        let replace_length = replace.len() as i32;
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::gtk_source_search_context_replace_all(
                self.as_ref().to_glib_none().0,
                replace.to_glib_none().0,
                replace_length,
                &mut error,
            );
            assert_eq!(is_ok == 0, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}