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::{Error, ffi, translate::*};
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 offset from the beginning of the document,
139 /// in bytes.
140 ///
141 /// The information is meant to accompany the values returned by
142 /// [`position()`][Self::position()], and comes with the
143 /// same accuracy guarantees.
144 ///
145 /// # Returns
146 ///
147 /// the offset
148 // rustdoc-stripper-ignore-next-stop
149 /// Retrieves the current offset from the beginning of the document,
150 /// in bytes.
151 ///
152 /// The information is meant to accompany the values returned by
153 /// [`position()`][Self::position()], and comes with the
154 /// same accuracy guarantees.
155 ///
156 /// # Returns
157 ///
158 /// the offset
159 #[cfg(feature = "v2_88")]
160 #[cfg_attr(docsrs, doc(cfg(feature = "v2_88")))]
161 #[doc(alias = "g_markup_parse_context_get_offset")]
162 #[doc(alias = "get_offset")]
163 pub fn offset(&self) -> usize {
164 unsafe { ffi::g_markup_parse_context_get_offset(self.to_glib_none().0) }
165 }
166
167 /// Retrieves the current line number and the number of the character on
168 /// that line. Intended for use in error messages; there are no strict
169 /// semantics for what constitutes the "current" line number other than
170 /// "the best number we could come up with for error messages."
171 ///
172 /// # Returns
173 ///
174 ///
175 /// ## `line_number`
176 /// return location for a line number, or [`None`]
177 ///
178 /// ## `char_number`
179 /// return location for a char-on-line number, or [`None`]
180 // rustdoc-stripper-ignore-next-stop
181 /// Retrieves the current line number and the number of the character on
182 /// that line. Intended for use in error messages; there are no strict
183 /// semantics for what constitutes the "current" line number other than
184 /// "the best number we could come up with for error messages."
185 ///
186 /// # Returns
187 ///
188 ///
189 /// ## `line_number`
190 /// return location for a line number, or [`None`]
191 ///
192 /// ## `char_number`
193 /// return location for a char-on-line number, or [`None`]
194 #[doc(alias = "g_markup_parse_context_get_position")]
195 #[doc(alias = "get_position")]
196 pub fn position(&self) -> (i32, i32) {
197 unsafe {
198 let mut line_number = std::mem::MaybeUninit::uninit();
199 let mut char_number = std::mem::MaybeUninit::uninit();
200 ffi::g_markup_parse_context_get_position(
201 self.to_glib_none().0,
202 line_number.as_mut_ptr(),
203 char_number.as_mut_ptr(),
204 );
205 (line_number.assume_init(), char_number.assume_init())
206 }
207 }
208
209 /// Retrieves the start position of the current start or end tag.
210 ///
211 /// This function can be used in the `start_element` or `end_element`
212 /// callbacks to obtain location information for error reporting.
213 ///
214 /// Note that @line_number and @char_number are intended for human
215 /// readable error messages and are therefore 1-based and in Unicode
216 /// characters. @offset on the other hand is meant for programmatic
217 /// use, and thus is 0-based and in bytes.
218 ///
219 /// The information is meant to accompany the values returned by
220 /// [`position()`][Self::position()], and comes with the
221 /// same accuracy guarantees.
222 ///
223 /// # Returns
224 ///
225 ///
226 /// ## `line_number`
227 /// return location for the line number
228 ///
229 /// ## `char_number`
230 /// return location for the character number
231 ///
232 /// ## `offset`
233 /// return location for offset from the beginning of the document
234 // rustdoc-stripper-ignore-next-stop
235 /// Retrieves the start position of the current start or end tag.
236 ///
237 /// This function can be used in the `start_element` or `end_element`
238 /// callbacks to obtain location information for error reporting.
239 ///
240 /// Note that @line_number and @char_number are intended for human
241 /// readable error messages and are therefore 1-based and in Unicode
242 /// characters. @offset on the other hand is meant for programmatic
243 /// use, and thus is 0-based and in bytes.
244 ///
245 /// The information is meant to accompany the values returned by
246 /// [`position()`][Self::position()], and comes with the
247 /// same accuracy guarantees.
248 ///
249 /// # Returns
250 ///
251 ///
252 /// ## `line_number`
253 /// return location for the line number
254 ///
255 /// ## `char_number`
256 /// return location for the character number
257 ///
258 /// ## `offset`
259 /// return location for offset from the beginning of the document
260 #[cfg(feature = "v2_88")]
261 #[cfg_attr(docsrs, doc(cfg(feature = "v2_88")))]
262 #[doc(alias = "g_markup_parse_context_get_tag_start")]
263 #[doc(alias = "get_tag_start")]
264 pub fn tag_start(&self) -> (usize, usize, usize) {
265 unsafe {
266 let mut line_number = std::mem::MaybeUninit::uninit();
267 let mut char_number = std::mem::MaybeUninit::uninit();
268 let mut offset = std::mem::MaybeUninit::uninit();
269 ffi::g_markup_parse_context_get_tag_start(
270 self.to_glib_none().0,
271 line_number.as_mut_ptr(),
272 char_number.as_mut_ptr(),
273 offset.as_mut_ptr(),
274 );
275 (
276 line_number.assume_init(),
277 char_number.assume_init(),
278 offset.assume_init(),
279 )
280 }
281 }
282
283 /// Feed some data to the #GMarkupParseContext.
284 ///
285 /// The data need not be valid UTF-8; an error will be signaled if
286 /// it's invalid. The data need not be an entire document; you can
287 /// feed a document into the parser incrementally, via multiple calls
288 /// to this function. Typically, as you receive data from a network
289 /// connection or file, you feed each received chunk of data into this
290 /// function, aborting the process if an error occurs. Once an error
291 /// is reported, no further data may be fed to the #GMarkupParseContext;
292 /// all errors are fatal.
293 /// ## `text`
294 /// chunk of text to parse
295 /// ## `text_len`
296 /// length of @text in bytes
297 ///
298 /// # Returns
299 ///
300 /// [`false`] if an error occurred, [`true`] on success
301 // rustdoc-stripper-ignore-next-stop
302 /// Feed some data to the #GMarkupParseContext.
303 ///
304 /// The data need not be valid UTF-8; an error will be signaled if
305 /// it's invalid. The data need not be an entire document; you can
306 /// feed a document into the parser incrementally, via multiple calls
307 /// to this function. Typically, as you receive data from a network
308 /// connection or file, you feed each received chunk of data into this
309 /// function, aborting the process if an error occurs. Once an error
310 /// is reported, no further data may be fed to the #GMarkupParseContext;
311 /// all errors are fatal.
312 /// ## `text`
313 /// chunk of text to parse
314 /// ## `text_len`
315 /// length of @text in bytes
316 ///
317 /// # Returns
318 ///
319 /// [`false`] if an error occurred, [`true`] on success
320 #[doc(alias = "g_markup_parse_context_parse")]
321 pub fn parse(&self, text: &str) -> Result<(), crate::Error> {
322 let text_len = text.len() as _;
323 unsafe {
324 let mut error = std::ptr::null_mut();
325 let is_ok = ffi::g_markup_parse_context_parse(
326 self.to_glib_none().0,
327 text.to_glib_none().0,
328 text_len,
329 &mut error,
330 );
331 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
332 if error.is_null() {
333 Ok(())
334 } else {
335 Err(from_glib_full(error))
336 }
337 }
338 }
339
340 //#[doc(alias = "g_markup_parse_context_pop")]
341 //pub fn pop(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
342 // unsafe { TODO: call ffi:g_markup_parse_context_pop() }
343 //}
344
345 //#[doc(alias = "g_markup_parse_context_push")]
346 //pub fn push(&self, parser: /*Ignored*/&MarkupParser, user_data: /*Unimplemented*/Option<Basic: Pointer>) {
347 // unsafe { TODO: call ffi:g_markup_parse_context_push() }
348 //}
349}