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