glib/auto/
markup_parse_context.rs1use crate::{Error, ffi, translate::*};
6
7crate::wrapper! {
8 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 pub struct MarkupParseContext(Shared<ffi::GMarkupParseContext>);
10
11 match fn {
12 ref => |ptr| ffi::g_markup_parse_context_ref(ptr),
13 unref => |ptr| ffi::g_markup_parse_context_unref(ptr),
14 type_ => || ffi::g_markup_parse_context_get_type(),
15 }
16}
17
18impl MarkupParseContext {
19 #[doc(alias = "g_markup_parse_context_end_parse")]
25 pub fn end_parse(&self) -> Result<(), crate::Error> {
26 unsafe {
27 let mut error = std::ptr::null_mut();
28 let is_ok = ffi::g_markup_parse_context_end_parse(self.to_glib_none().0, &mut error);
29 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
30 if error.is_null() {
31 Ok(())
32 } else {
33 Err(from_glib_full(error))
34 }
35 }
36 }
37
38 #[doc(alias = "g_markup_parse_context_get_element")]
39 #[doc(alias = "get_element")]
40 pub fn element(&self) -> crate::GString {
41 unsafe {
42 from_glib_none(ffi::g_markup_parse_context_get_element(
43 self.to_glib_none().0,
44 ))
45 }
46 }
47
48 #[doc(alias = "g_markup_parse_context_get_element_stack")]
49 #[doc(alias = "get_element_stack")]
50 pub fn element_stack(&self) -> Vec<crate::GString> {
51 unsafe {
52 FromGlibPtrContainer::from_glib_none(ffi::g_markup_parse_context_get_element_stack(
53 self.to_glib_none().0,
54 ))
55 }
56 }
57
58 #[cfg(feature = "v2_88")]
59 #[cfg_attr(docsrs, doc(cfg(feature = "v2_88")))]
60 #[doc(alias = "g_markup_parse_context_get_offset")]
61 #[doc(alias = "get_offset")]
62 pub fn offset(&self) -> usize {
63 unsafe { ffi::g_markup_parse_context_get_offset(self.to_glib_none().0) }
64 }
65
66 #[doc(alias = "g_markup_parse_context_get_position")]
67 #[doc(alias = "get_position")]
68 pub fn position(&self) -> (i32, i32) {
69 unsafe {
70 let mut line_number = std::mem::MaybeUninit::uninit();
71 let mut char_number = std::mem::MaybeUninit::uninit();
72 ffi::g_markup_parse_context_get_position(
73 self.to_glib_none().0,
74 line_number.as_mut_ptr(),
75 char_number.as_mut_ptr(),
76 );
77 (line_number.assume_init(), char_number.assume_init())
78 }
79 }
80
81 #[cfg(feature = "v2_88")]
82 #[cfg_attr(docsrs, doc(cfg(feature = "v2_88")))]
83 #[doc(alias = "g_markup_parse_context_get_tag_start")]
84 #[doc(alias = "get_tag_start")]
85 pub fn tag_start(&self) -> (usize, usize, usize) {
86 unsafe {
87 let mut line_number = std::mem::MaybeUninit::uninit();
88 let mut char_number = std::mem::MaybeUninit::uninit();
89 let mut offset = std::mem::MaybeUninit::uninit();
90 ffi::g_markup_parse_context_get_tag_start(
91 self.to_glib_none().0,
92 line_number.as_mut_ptr(),
93 char_number.as_mut_ptr(),
94 offset.as_mut_ptr(),
95 );
96 (
97 line_number.assume_init(),
98 char_number.assume_init(),
99 offset.assume_init(),
100 )
101 }
102 }
103
104 #[doc(alias = "g_markup_parse_context_parse")]
105 pub fn parse(&self, text: &str) -> Result<(), crate::Error> {
106 let text_len = text.len() as _;
107 unsafe {
108 let mut error = std::ptr::null_mut();
109 let is_ok = ffi::g_markup_parse_context_parse(
110 self.to_glib_none().0,
111 text.to_glib_none().0,
112 text_len,
113 &mut error,
114 );
115 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
116 if error.is_null() {
117 Ok(())
118 } else {
119 Err(from_glib_full(error))
120 }
121 }
122 }
123
124 }