glib/auto/markup_parse_context.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, translate::*, Error};
6
7crate::wrapper! {
8 /// A parse context is used to parse a stream of bytes that
9 /// you expect to contain marked-up text.
10 ///
11 /// See g_markup_parse_context_new(), #GMarkupParser, and so
12 /// on for more details.
13 // rustdoc-stripper-ignore-next-stop
14 /// A parse context is used to parse a stream of bytes that
15 /// you expect to contain marked-up text.
16 ///
17 /// See g_markup_parse_context_new(), #GMarkupParser, and so
18 /// on for more details.
19 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
20 pub struct MarkupParseContext(Shared<ffi::GMarkupParseContext>);
21
22 match fn {
23 ref => |ptr| ffi::g_markup_parse_context_ref(ptr),
24 unref => |ptr| ffi::g_markup_parse_context_unref(ptr),
25 type_ => || ffi::g_markup_parse_context_get_type(),
26 }
27}
28
29impl MarkupParseContext {
30 //#[doc(alias = "g_markup_parse_context_new")]
31 //pub fn new(parser: /*Ignored*/&MarkupParser, flags: /*Ignored*/MarkupParseFlags, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> MarkupParseContext {
32 // unsafe { TODO: call ffi:g_markup_parse_context_new() }
33 //}
34
35 /// Signals to the #GMarkupParseContext that all data has been
36 /// fed into the parse context with g_markup_parse_context_parse().
37 ///
38 /// This function reports an error if the document isn't complete,
39 /// for example if elements are still open.
40 ///
41 /// # Returns
42 ///
43 /// [`true`] on success, [`false`] if an error was set
44 // rustdoc-stripper-ignore-next-stop
45 /// Signals to the #GMarkupParseContext that all data has been
46 /// fed into the parse context with g_markup_parse_context_parse().
47 ///
48 /// This function reports an error if the document isn't complete,
49 /// for example if elements are still open.
50 ///
51 /// # Returns
52 ///
53 /// [`true`] on success, [`false`] if an error was set
54 #[doc(alias = "g_markup_parse_context_end_parse")]
55 pub fn end_parse(&self) -> Result<(), crate::Error> {
56 unsafe {
57 let mut error = std::ptr::null_mut();
58 let is_ok = ffi::g_markup_parse_context_end_parse(self.to_glib_none().0, &mut error);
59 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
60 if error.is_null() {
61 Ok(())
62 } else {
63 Err(from_glib_full(error))
64 }
65 }
66 }
67
68 /// Retrieves the name of the currently open element.
69 ///
70 /// If called from the start_element or end_element handlers this will
71 /// give the element_name as passed to those functions. For the parent
72 /// elements, see g_markup_parse_context_get_element_stack().
73 ///
74 /// # Returns
75 ///
76 /// the name of the currently open element, or [`None`]
77 // rustdoc-stripper-ignore-next-stop
78 /// Retrieves the name of the currently open element.
79 ///
80 /// If called from the start_element or end_element handlers this will
81 /// give the element_name as passed to those functions. For the parent
82 /// elements, see g_markup_parse_context_get_element_stack().
83 ///
84 /// # Returns
85 ///
86 /// the name of the currently open element, or [`None`]
87 #[doc(alias = "g_markup_parse_context_get_element")]
88 #[doc(alias = "get_element")]
89 pub fn element(&self) -> crate::GString {
90 unsafe {
91 from_glib_none(ffi::g_markup_parse_context_get_element(
92 self.to_glib_none().0,
93 ))
94 }
95 }
96
97 /// Retrieves the element stack from the internal state of the parser.
98 ///
99 /// The returned #GSList is a list of strings where the first item is
100 /// the currently open tag (as would be returned by
101 /// g_markup_parse_context_get_element()) and the next item is its
102 /// immediate parent.
103 ///
104 /// This function is intended to be used in the start_element and
105 /// end_element handlers where g_markup_parse_context_get_element()
106 /// would merely return the name of the element that is being
107 /// processed.
108 ///
109 /// # Returns
110 ///
111 /// the element stack, which must not be modified
112 // rustdoc-stripper-ignore-next-stop
113 /// Retrieves the element stack from the internal state of the parser.
114 ///
115 /// The returned #GSList is a list of strings where the first item is
116 /// the currently open tag (as would be returned by
117 /// g_markup_parse_context_get_element()) and the next item is its
118 /// immediate parent.
119 ///
120 /// This function is intended to be used in the start_element and
121 /// end_element handlers where g_markup_parse_context_get_element()
122 /// would merely return the name of the element that is being
123 /// processed.
124 ///
125 /// # Returns
126 ///
127 /// the element stack, which must not be modified
128 #[doc(alias = "g_markup_parse_context_get_element_stack")]
129 #[doc(alias = "get_element_stack")]
130 pub fn element_stack(&self) -> Vec<crate::GString> {
131 unsafe {
132 FromGlibPtrContainer::from_glib_none(ffi::g_markup_parse_context_get_element_stack(
133 self.to_glib_none().0,
134 ))
135 }
136 }
137
138 /// Retrieves the current line number and the number of the character on
139 /// that line. Intended for use in error messages; there are no strict
140 /// semantics for what constitutes the "current" line number other than
141 /// "the best number we could come up with for error messages."
142 ///
143 /// # Returns
144 ///
145 ///
146 /// ## `line_number`
147 /// return location for a line number, or [`None`]
148 ///
149 /// ## `char_number`
150 /// return location for a char-on-line number, or [`None`]
151 // rustdoc-stripper-ignore-next-stop
152 /// Retrieves the current line number and the number of the character on
153 /// that line. Intended for use in error messages; there are no strict
154 /// semantics for what constitutes the "current" line number other than
155 /// "the best number we could come up with for error messages."
156 ///
157 /// # Returns
158 ///
159 ///
160 /// ## `line_number`
161 /// return location for a line number, or [`None`]
162 ///
163 /// ## `char_number`
164 /// return location for a char-on-line number, or [`None`]
165 #[doc(alias = "g_markup_parse_context_get_position")]
166 #[doc(alias = "get_position")]
167 pub fn position(&self) -> (i32, i32) {
168 unsafe {
169 let mut line_number = std::mem::MaybeUninit::uninit();
170 let mut char_number = std::mem::MaybeUninit::uninit();
171 ffi::g_markup_parse_context_get_position(
172 self.to_glib_none().0,
173 line_number.as_mut_ptr(),
174 char_number.as_mut_ptr(),
175 );
176 (line_number.assume_init(), char_number.assume_init())
177 }
178 }
179
180 /// Feed some data to the #GMarkupParseContext.
181 ///
182 /// The data need not be valid UTF-8; an error will be signaled if
183 /// it's invalid. The data need not be an entire document; you can
184 /// feed a document into the parser incrementally, via multiple calls
185 /// to this function. Typically, as you receive data from a network
186 /// connection or file, you feed each received chunk of data into this
187 /// function, aborting the process if an error occurs. Once an error
188 /// is reported, no further data may be fed to the #GMarkupParseContext;
189 /// all errors are fatal.
190 /// ## `text`
191 /// chunk of text to parse
192 /// ## `text_len`
193 /// length of @text in bytes
194 ///
195 /// # Returns
196 ///
197 /// [`false`] if an error occurred, [`true`] on success
198 // rustdoc-stripper-ignore-next-stop
199 /// Feed some data to the #GMarkupParseContext.
200 ///
201 /// The data need not be valid UTF-8; an error will be signaled if
202 /// it's invalid. The data need not be an entire document; you can
203 /// feed a document into the parser incrementally, via multiple calls
204 /// to this function. Typically, as you receive data from a network
205 /// connection or file, you feed each received chunk of data into this
206 /// function, aborting the process if an error occurs. Once an error
207 /// is reported, no further data may be fed to the #GMarkupParseContext;
208 /// all errors are fatal.
209 /// ## `text`
210 /// chunk of text to parse
211 /// ## `text_len`
212 /// length of @text in bytes
213 ///
214 /// # Returns
215 ///
216 /// [`false`] if an error occurred, [`true`] on success
217 #[doc(alias = "g_markup_parse_context_parse")]
218 pub fn parse(&self, text: &str) -> Result<(), crate::Error> {
219 let text_len = text.len() as _;
220 unsafe {
221 let mut error = std::ptr::null_mut();
222 let is_ok = ffi::g_markup_parse_context_parse(
223 self.to_glib_none().0,
224 text.to_glib_none().0,
225 text_len,
226 &mut error,
227 );
228 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
229 if error.is_null() {
230 Ok(())
231 } else {
232 Err(from_glib_full(error))
233 }
234 }
235 }
236
237 //#[doc(alias = "g_markup_parse_context_pop")]
238 //pub fn pop(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
239 // unsafe { TODO: call ffi:g_markup_parse_context_pop() }
240 //}
241
242 //#[doc(alias = "g_markup_parse_context_push")]
243 //pub fn push(&self, parser: /*Ignored*/&MarkupParser, user_data: /*Unimplemented*/Option<Basic: Pointer>) {
244 // unsafe { TODO: call ffi:g_markup_parse_context_push() }
245 //}
246}