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
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::TextAttributes;
use crate::TextIter;
use glib::translate::*;
use std::convert::TryFrom;

impl TextIter {
    #[doc(alias = "gtk_text_iter_get_attributes")]
    #[doc(alias = "get_attributes")]
    pub fn is_attributes(&self, values: &TextAttributes) -> bool {
        unsafe {
            from_glib(ffi::gtk_text_iter_get_attributes(
                self.to_glib_none().0,
                mut_override(values.to_glib_none().0),
            ))
        }
    }

    /// The Unicode character at this iterator is returned. (Equivalent to
    /// operator* on a C++ iterator.) If the element at this iterator is a
    /// non-character element, such as an image embedded in the buffer, the
    /// Unicode “unknown” character 0xFFFC is returned. If invoked on
    /// the end iterator, zero is returned; zero is not a valid Unicode character.
    /// So you can write a loop which ends when [`char()`][Self::char()]
    /// returns 0.
    ///
    /// # Returns
    ///
    /// a Unicode character, or 0 if `self` is not dereferenceable
    #[doc(alias = "gtk_text_iter_get_char")]
    #[doc(alias = "get_char")]
    pub fn char(&self) -> Option<char> {
        let ret = unsafe { ffi::gtk_text_iter_get_char(self.to_glib_none().0) };

        if ret == 0 {
            return None;
        }

        Some(TryFrom::try_from(ret).expect("conversion from an invalid Unicode value attempted"))
    }
}