1use std::ffi::{CStr, CString};
2use std::mem;
3
4pub fn version() -> String {
9 let raw_version = unsafe { CStr::from_ptr(onig_sys::onig_version()) };
10 raw_version.to_string_lossy().into_owned()
11}
12
13pub fn copyright() -> String {
19 let raw_copy = unsafe { CStr::from_ptr(onig_sys::onig_copyright()) };
20 raw_copy.to_string_lossy().into_owned()
21}
22
23pub type CodePointRange = (onig_sys::OnigCodePoint, onig_sys::OnigCodePoint);
24
25pub fn define_user_property(name: &str, ranges: &[CodePointRange]) -> i32 {
29 let mut raw_ranges = vec![ranges.len() as onig_sys::OnigCodePoint];
30 for &(start, end) in ranges {
31 raw_ranges.push(start);
32 raw_ranges.push(end);
33 }
34 let name = CString::new(name).unwrap();
35 let r = unsafe {
36 onig_sys::onig_unicode_define_user_property(name.as_ptr(), raw_ranges.as_mut_ptr())
37 };
38
39 mem::forget(raw_ranges);
44 r
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 pub fn utils_get_copyright_is_not_emtpy() {
53 let copyright = copyright();
54 assert!(copyright.len() > 0);
55 }
56}