Skip to main content

gtk/
text_iter.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::TextAttributes;
4use crate::TextIter;
5use glib::translate::*;
6use std::convert::TryFrom;
7
8impl TextIter {
9    /// Computes the effect of any tags applied to this spot in the
10    /// text. The `values` parameter should be initialized to the default
11    /// settings you wish to use if no tags are in effect. You’d typically
12    /// obtain the defaults from [`TextViewExt::default_attributes()`][crate::prelude::TextViewExt::default_attributes()].
13    ///
14    /// [`is_attributes()`][Self::is_attributes()] will modify `values`, applying the
15    /// effects of any tags present at `self`. If any tags affected `values`,
16    /// the function returns [`true`].
17    ///
18    /// # Returns
19    ///
20    /// [`true`] if `values` was modified
21    ///
22    /// ## `values`
23    /// a [`TextAttributes`][crate::TextAttributes] to be filled in
24    #[doc(alias = "gtk_text_iter_get_attributes")]
25    #[doc(alias = "get_attributes")]
26    pub fn is_attributes(&self, values: &TextAttributes) -> bool {
27        unsafe {
28            from_glib(ffi::gtk_text_iter_get_attributes(
29                self.to_glib_none().0,
30                mut_override(values.to_glib_none().0),
31            ))
32        }
33    }
34
35    /// The Unicode character at this iterator is returned. (Equivalent to
36    /// operator* on a C++ iterator.) If the element at this iterator is a
37    /// non-character element, such as an image embedded in the buffer, the
38    /// Unicode “unknown” character 0xFFFC is returned. If invoked on
39    /// the end iterator, zero is returned; zero is not a valid Unicode character.
40    /// So you can write a loop which ends when [`char()`][Self::char()]
41    /// returns 0.
42    ///
43    /// # Returns
44    ///
45    /// a Unicode character, or 0 if `self` is not dereferenceable
46    #[doc(alias = "gtk_text_iter_get_char")]
47    #[doc(alias = "get_char")]
48    pub fn char(&self) -> Option<char> {
49        let ret = unsafe { ffi::gtk_text_iter_get_char(self.to_glib_none().0) };
50
51        if ret == 0 {
52            return None;
53        }
54
55        Some(TryFrom::try_from(ret).expect("conversion from an invalid Unicode value attempted"))
56    }
57}