diff --git a/src/lib.rs b/src/lib.rs index d2e6c97..587ce8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,3 +2,4 @@ mod cxx; pub mod mgr; pub mod module; pub mod versekey; +pub mod versification; diff --git a/src/versification.rs b/src/versification.rs new file mode 100644 index 0000000..cc83b32 --- /dev/null +++ b/src/versification.rs @@ -0,0 +1,76 @@ +/// Rust-friendly wrapper for the CXX versification bridge. +use crate::cxx::ffi; +use cxx::UniquePtr; +use std::fmt; + +/// Represents a versification system (opaque pointer from C++). +pub struct VersificationSystem { + ptr: *const ffi::VersificationSystem, +} + +impl fmt::Debug for VersificationSystem { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "VersificationSystem({:p})", self.ptr) + } +} + +/// Safe Rust wrapper for the CXX Versification class. +pub struct Versification { + inner: UniquePtr, +} + +impl Versification { + /// Create a new Versification manager. + pub fn new() -> Self { + Self { + inner: ffi::new_versification(), + } + } + + /// Get the list of available versification system names. + pub fn versifications(&self) -> Vec { + self.inner.getVersifications() + } + + /// Get a versification system by name. + /// + /// Returns None if the system is not found. + pub fn get_system(&self, name: &str) -> Option { + let mut name_owned = name.to_string(); + let ptr = self.inner.getVersification(&mut name_owned); + if ptr.is_null() { + None + } else { + Some(VersificationSystem { ptr }) + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn knows_versifications() { + let v = Versification::new(); + let list = v.versifications(); + assert!(list.contains(&"KJV".to_string()) || !list.is_empty()); + } + + #[test] + fn get_system_returns_some_for_known() { + let v = Versification::new(); + let list = v.versifications(); + if let Some(first) = list.first() { + let sys = v.get_system(first); + assert!(sys.is_some()); + } + } + + #[test] + fn get_system_returns_none_for_unknown() { + let v = Versification::new(); + let sys = v.get_system("notarealversification"); + assert!(sys.is_none()); + } +}