use std::fmt;
use crate::{NCurseswWinError, form::{FieldType, FIELDTYPE_REGEXP, IsFieldType}};
use crate::cstring::*;
#[derive(PartialEq, Eq, Hash)]
pub struct RegularExpression<'a> {
fieldtype: &'a FieldType,
arguments: u8,
regexp: &'a [i8]
}
impl<'a> RegularExpression<'a> {
pub fn new<S: Into<String>>(regexp: S) -> result!(Self) {
let regexp = regexp.into().to_string();
Ok(Self { fieldtype: &*FIELDTYPE_REGEXP, arguments: 1, regexp: c_str_with_nul!(regexp) })
}
}
impl<'a> IsFieldType<'a, *const i8, i32, i32> for RegularExpression<'a> {
fn fieldtype(&self) -> &'a FieldType {
self.fieldtype
}
fn arguments(&self) -> u8 {
self.arguments
}
fn arg1(&self) -> *const i8 {
self.regexp.as_ptr()
}
fn arg2(&self) -> i32 { 0 }
fn arg3(&self) -> i32 { 0 }
}
unsafe impl<'a> Send for RegularExpression<'a> { } unsafe impl<'a> Sync for RegularExpression<'a> { }
impl <'a>AsRef<RegularExpression<'a>> for RegularExpression<'a> {
fn as_ref(&self) -> &Self {
self
}
}
impl <'a>AsMut<RegularExpression<'a>> for RegularExpression<'a> {
fn as_mut(&mut self) -> &mut Self {
self
}
}
impl<'a> fmt::Debug for RegularExpression<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{{ fieldtype: {:?}, arguments: {}, regexp: {:?} }}", self.fieldtype, self.arguments, self.regexp)
}
}