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 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    /// Feed some data to the #GMarkupParseContext.
210    ///
211    /// The data need not be valid UTF-8; an error will be signaled if
212    /// it's invalid. The data need not be an entire document; you can
213    /// feed a document into the parser incrementally, via multiple calls
214    /// to this function. Typically, as you receive data from a network
215    /// connection or file, you feed each received chunk of data into this
216    /// function, aborting the process if an error occurs. Once an error
217    /// is reported, no further data may be fed to the #GMarkupParseContext;
218    /// all errors are fatal.
219    /// ## `text`
220    /// chunk of text to parse
221    /// ## `text_len`
222    /// length of @text in bytes
223    ///
224    /// # Returns
225    ///
226    /// [`false`] if an error occurred, [`true`] on success
227    // rustdoc-stripper-ignore-next-stop
228    /// Feed some data to the #GMarkupParseContext.
229    ///
230    /// The data need not be valid UTF-8; an error will be signaled if
231    /// it's invalid. The data need not be an entire document; you can
232    /// feed a document into the parser incrementally, via multiple calls
233    /// to this function. Typically, as you receive data from a network
234    /// connection or file, you feed each received chunk of data into this
235    /// function, aborting the process if an error occurs. Once an error
236    /// is reported, no further data may be fed to the #GMarkupParseContext;
237    /// all errors are fatal.
238    /// ## `text`
239    /// chunk of text to parse
240    /// ## `text_len`
241    /// length of @text in bytes
242    ///
243    /// # Returns
244    ///
245    /// [`false`] if an error occurred, [`true`] on success
246    #[doc(alias = "g_markup_parse_context_parse")]
247    pub fn parse(&self, text: &str) -> Result<(), crate::Error> {
248        let text_len = text.len() as _;
249        unsafe {
250            let mut error = std::ptr::null_mut();
251            let is_ok = ffi::g_markup_parse_context_parse(
252                self.to_glib_none().0,
253                text.to_glib_none().0,
254                text_len,
255                &mut error,
256            );
257            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
258            if error.is_null() {
259                Ok(())
260            } else {
261                Err(from_glib_full(error))
262            }
263        }
264    }
265
266    //#[doc(alias = "g_markup_parse_context_pop")]
267    //pub fn pop(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
268    //    unsafe { TODO: call ffi:g_markup_parse_context_pop() }
269    //}
270
271    //#[doc(alias = "g_markup_parse_context_push")]
272    //pub fn push(&self, parser: /*Ignored*/&MarkupParser, user_data: /*Unimplemented*/Option<Basic: Pointer>) {
273    //    unsafe { TODO: call ffi:g_markup_parse_context_push() }
274    //}
275}