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
use crate::translate::*;
use crate::Error;
use std::mem;
use std::ptr;
crate::wrapper! {
#[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_end_parse")]
pub fn end_parse(&self) -> Result<(), crate::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::g_markup_parse_context_end_parse(self.to_glib_none().0, &mut error);
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_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,
))
}
}
#[doc(alias = "g_markup_parse_context_get_position")]
#[doc(alias = "get_position")]
pub fn position(&self) -> (i32, i32) {
unsafe {
let mut line_number = mem::MaybeUninit::uninit();
let mut char_number = 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())
}
}
#[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 = 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,
);
assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
}