399 lines
9.7 KiB
Rust
399 lines
9.7 KiB
Rust
use crate::cxx::ffi;
|
|||
|
|
|
||
|
|
/// Safe wrapper for owned VerseKey instances
|
||
|
|
pub struct VerseKey {
|
||
|
|
inner: cxx::UniquePtr<ffi::VerseKey>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl VerseKey {
|
||
|
|
/// Create a new VerseKey
|
||
|
|
pub fn new() -> Self {
|
||
|
|
Self {
|
||
|
|
inner: ffi::new_verse_key(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Create a new VerseKey from text
|
||
|
|
pub fn from_text(text: &str) -> Self {
|
||
|
|
Self {
|
||
|
|
inner: ffi::new_verse_key_from_text(&text.to_string()),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the book name
|
||
|
|
pub fn get_book_name(&self) -> String {
|
||
|
|
self.inner.get_book_name()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the book abbreviation
|
||
|
|
pub fn get_book_abbrev(&self) -> String {
|
||
|
|
self.inner.get_book_abbrev()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the OSIS book name
|
||
|
|
pub fn get_osis_book_name(&self) -> String {
|
||
|
|
self.inner.get_osis_book_name()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the OSIS reference
|
||
|
|
pub fn get_osis_ref(&self) -> String {
|
||
|
|
self.inner.get_osis_ref()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the OSIS reference range text
|
||
|
|
pub fn get_osis_ref_range_text(&self) -> String {
|
||
|
|
self.inner.get_osis_ref_range_text()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the short range text
|
||
|
|
pub fn get_short_range_text(&self) -> String {
|
||
|
|
self.inner.get_short_range_text()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the testament number
|
||
|
|
pub fn get_testament(&self) -> u8 {
|
||
|
|
self.inner.get_testament()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the maximum testament number
|
||
|
|
pub fn get_testament_max(&self) -> u8 {
|
||
|
|
self.inner.get_testament_max()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the book number
|
||
|
|
pub fn get_book(&self) -> u8 {
|
||
|
|
self.inner.get_book()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the maximum book number
|
||
|
|
pub fn get_book_max(&self) -> u8 {
|
||
|
|
self.inner.get_book_max()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the chapter number
|
||
|
|
pub fn get_chapter(&self) -> u8 {
|
||
|
|
self.inner.get_chapter()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the maximum chapter number
|
||
|
|
pub fn get_chapter_max(&self) -> u8 {
|
||
|
|
self.inner.get_chapter_max()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the verse number
|
||
|
|
pub fn get_verse(&self) -> u8 {
|
||
|
|
self.inner.get_verse()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the maximum verse number
|
||
|
|
pub fn get_verse_max(&self) -> u8 {
|
||
|
|
self.inner.get_verse_max()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Check if auto-normalize is enabled
|
||
|
|
pub fn is_autonormalize(&self) -> bool {
|
||
|
|
self.inner.is_autonormalize()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Check if intros are enabled
|
||
|
|
pub fn is_intros(&self) -> bool {
|
||
|
|
self.inner.is_intros()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the error code
|
||
|
|
pub fn get_error(&self) -> u8 {
|
||
|
|
self.inner.get_error()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the locale
|
||
|
|
pub fn get_locale(&self) -> String {
|
||
|
|
self.inner.get_locale()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the range text
|
||
|
|
pub fn get_range_text(&self) -> String {
|
||
|
|
self.inner.get_range_text()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the short text
|
||
|
|
pub fn get_short_text(&self) -> String {
|
||
|
|
self.inner.get_short_text()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the text
|
||
|
|
pub fn get_text(&self) -> String {
|
||
|
|
self.inner.get_text()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Normalize the key
|
||
|
|
pub fn normalize(&mut self, autocheck: bool) {
|
||
|
|
self.inner.pin_mut().normalize(autocheck)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Pop an error
|
||
|
|
pub fn pop_error(&mut self) -> u8 {
|
||
|
|
self.inner.pin_mut().pop_error()
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set auto-normalize
|
||
|
|
pub fn set_autonormalize(&mut self, auto_normalize: bool) {
|
||
|
|
self.inner.pin_mut().set_autonormalize(auto_normalize)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the book name
|
||
|
|
pub fn set_book_name(&mut self, book_name: &str) {
|
||
|
|
self.inner.pin_mut().set_book_name(&book_name.to_string())
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set intros
|
||
|
|
pub fn set_intros(&mut self, intros: bool) {
|
||
|
|
self.inner.pin_mut().set_intros(intros)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the locale
|
||
|
|
pub fn set_locale(&mut self, locale: &str) {
|
||
|
|
self.inner.pin_mut().set_locale(&locale.to_string())
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the text
|
||
|
|
pub fn set_text(&mut self, text: &str) {
|
||
|
|
self.inner.pin_mut().set_text(&text.to_string())
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the testament
|
||
|
|
pub fn set_testament(&mut self, testament: u8) {
|
||
|
|
self.inner.pin_mut().set_testament(testament)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the book
|
||
|
|
pub fn set_book(&mut self, book: u8) {
|
||
|
|
self.inner.pin_mut().set_book(book)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the chapter
|
||
|
|
pub fn set_chapter(&mut self, chapter: u8) {
|
||
|
|
self.inner.pin_mut().set_chapter(chapter)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the verse
|
||
|
|
pub fn set_verse(&mut self, verse: u8) {
|
||
|
|
self.inner.pin_mut().set_verse(verse)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Default for VerseKey {
|
||
|
|
fn default() -> Self {
|
||
|
|
Self::new()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Wrapper for borrowed VerseKey instances (from modules)
|
||
|
|
pub struct BorrowedVerseKey {
|
||
|
|
ptr: *mut ffi::VerseKey,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl BorrowedVerseKey {
|
||
|
|
/// Create from a raw pointer (unsafe)
|
||
|
|
pub unsafe fn from_ptr(ptr: *mut ffi::VerseKey) -> Option<Self> {
|
||
|
|
if ptr.is_null() {
|
||
|
|
None
|
||
|
|
} else {
|
||
|
|
Some(Self { ptr })
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the book name
|
||
|
|
pub fn get_book_name(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_book_name() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the book abbreviation
|
||
|
|
pub fn get_book_abbrev(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_book_abbrev() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the OSIS book name
|
||
|
|
pub fn get_osis_book_name(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_osis_book_name() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the OSIS reference
|
||
|
|
pub fn get_osis_ref(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_osis_ref() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the OSIS reference range text
|
||
|
|
pub fn get_osis_ref_range_text(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_osis_ref_range_text() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the short range text
|
||
|
|
pub fn get_short_range_text(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_short_range_text() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the testament number
|
||
|
|
pub fn get_testament(&self) -> u8 {
|
||
|
|
unsafe { (&*self.ptr).get_testament() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the maximum testament number
|
||
|
|
pub fn get_testament_max(&self) -> u8 {
|
||
|
|
unsafe { (&*self.ptr).get_testament_max() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the book number
|
||
|
|
pub fn get_book(&self) -> u8 {
|
||
|
|
unsafe { (&*self.ptr).get_book() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the maximum book number
|
||
|
|
pub fn get_book_max(&self) -> u8 {
|
||
|
|
unsafe { (&*self.ptr).get_book_max() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the chapter number
|
||
|
|
pub fn get_chapter(&self) -> u8 {
|
||
|
|
unsafe { (&*self.ptr).get_chapter() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the maximum chapter number
|
||
|
|
pub fn get_chapter_max(&self) -> u8 {
|
||
|
|
unsafe { (&*self.ptr).get_chapter_max() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the verse number
|
||
|
|
pub fn get_verse(&self) -> u8 {
|
||
|
|
unsafe { (&*self.ptr).get_verse() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the maximum verse number
|
||
|
|
pub fn get_verse_max(&self) -> u8 {
|
||
|
|
unsafe { (&*self.ptr).get_verse_max() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Check if auto-normalize is enabled
|
||
|
|
pub fn is_autonormalize(&self) -> bool {
|
||
|
|
unsafe { (&*self.ptr).is_autonormalize() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Check if intros are enabled
|
||
|
|
pub fn is_intros(&self) -> bool {
|
||
|
|
unsafe { (&*self.ptr).is_intros() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the error code
|
||
|
|
pub fn get_error(&self) -> u8 {
|
||
|
|
unsafe { (&*self.ptr).get_error() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the locale
|
||
|
|
pub fn get_locale(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_locale() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the range text
|
||
|
|
pub fn get_range_text(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_range_text() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the short text
|
||
|
|
pub fn get_short_text(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_short_text() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get the text
|
||
|
|
pub fn get_text(&self) -> String {
|
||
|
|
unsafe { (&*self.ptr).get_text() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Normalize the key
|
||
|
|
pub fn normalize(&mut self, autocheck: bool) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).normalize(autocheck);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Pop an error
|
||
|
|
pub fn pop_error(&mut self) -> u8 {
|
||
|
|
unsafe { std::pin::Pin::new_unchecked(&mut *self.ptr).pop_error() }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set auto-normalize
|
||
|
|
pub fn set_autonormalize(&mut self, auto_normalize: bool) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).set_autonormalize(auto_normalize);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the book name
|
||
|
|
pub fn set_book_name(&mut self, book_name: &str) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).set_book_name(&book_name.to_string());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set intros
|
||
|
|
pub fn set_intros(&mut self, intros: bool) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).set_intros(intros);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the locale
|
||
|
|
pub fn set_locale(&mut self, locale: &str) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).set_locale(&locale.to_string());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the text
|
||
|
|
pub fn set_text(&mut self, text: &str) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).set_text(&text.to_string());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the testament
|
||
|
|
pub fn set_testament(&mut self, testament: u8) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).set_testament(testament);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the book
|
||
|
|
pub fn set_book(&mut self, book: u8) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).set_book(book);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the chapter
|
||
|
|
pub fn set_chapter(&mut self, chapter: u8) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).set_chapter(chapter);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Set the verse
|
||
|
|
pub fn set_verse(&mut self, verse: u8) {
|
||
|
|
unsafe {
|
||
|
|
std::pin::Pin::new_unchecked(&mut *self.ptr).set_verse(verse);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Drop for BorrowedVerseKey {
|
||
|
|
fn drop(&mut self) {
|
||
|
|
if !self.ptr.is_null() {
|
||
|
|
unsafe {
|
||
|
|
ffi::delete_verse_key(self.ptr);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Safety: BorrowedVerseKey can be sent between threads safely as long as
|
||
|
|
// the underlying SWORD library is thread-safe for reading
|
||
|
|
unsafe impl Send for BorrowedVerseKey {}
|