#![allow(unsafe_code, clippy::missing_safety_doc)]
pub mod c14n;
pub mod catalog;
pub mod css;
pub mod document;
pub mod html5;
pub mod push;
pub mod reader;
pub mod sax;
pub mod serial;
pub mod strings;
pub mod tree;
pub mod validation;
pub mod xinclude;
pub mod xpath;
use std::cell::RefCell;
use std::ffi::CString;
use std::os::raw::c_char;
struct StructuredError {
message: CString,
line: u32,
column: u32,
severity: i32, }
pub const XMLOXIDE_ERR_WARNING: i32 = 0;
pub const XMLOXIDE_ERR_ERROR: i32 = 1;
pub const XMLOXIDE_ERR_FATAL: i32 = 2;
thread_local! {
static LAST_ERROR: RefCell<Option<StructuredError>> = const { RefCell::new(None) };
}
fn set_last_error(msg: &str) {
LAST_ERROR.with(|cell| {
*cell.borrow_mut() = CString::new(msg).ok().map(|message| StructuredError {
message,
line: 0,
column: 0,
severity: XMLOXIDE_ERR_FATAL,
});
});
}
fn set_last_error_structured(msg: &str, line: u32, column: u32, severity: i32) {
LAST_ERROR.with(|cell| {
*cell.borrow_mut() = CString::new(msg).ok().map(|message| StructuredError {
message,
line,
column,
severity,
});
});
}
fn clear_last_error() {
LAST_ERROR.with(|cell| {
*cell.borrow_mut() = None;
});
}
#[no_mangle]
pub extern "C" fn xmloxide_last_error() -> *const c_char {
LAST_ERROR.with(|cell| {
let borrow = cell.borrow();
match borrow.as_ref() {
Some(e) => e.message.as_ptr(),
None => std::ptr::null(),
}
})
}
#[no_mangle]
pub extern "C" fn xmloxide_last_error_line() -> u32 {
LAST_ERROR.with(|cell| {
let borrow = cell.borrow();
borrow.as_ref().map_or(0, |e| e.line)
})
}
#[no_mangle]
pub extern "C" fn xmloxide_last_error_column() -> u32 {
LAST_ERROR.with(|cell| {
let borrow = cell.borrow();
borrow.as_ref().map_or(0, |e| e.column)
})
}
#[no_mangle]
pub extern "C" fn xmloxide_last_error_severity() -> i32 {
LAST_ERROR.with(|cell| {
let borrow = cell.borrow();
borrow.as_ref().map_or(-1, |e| e.severity)
})
}