use crate::enums::StringBounds;
#[derive(Debug, Clone)]
pub struct BoundsBuilder<'a> {
string_bounds: Vec<StringBounds<'a>>,
}
impl<'a> BoundsBuilder<'a> {
pub fn new() -> Self {
BoundsBuilder {
string_bounds: Vec::new()
}
}
pub fn as_vec(&self) -> Vec<StringBounds<'a>> {
self.string_bounds.clone()
}
fn starts_with(&mut self, pattern: &'a str, is_positive: bool, case_insensitive: bool) -> Self {
let sb = if case_insensitive {
StringBounds::StartsWithCi(pattern, is_positive)
} else {
StringBounds::StartsWithCs(pattern, is_positive)
};
self.string_bounds.push(sb);
self.to_owned()
}
pub fn starts_with_ci(&mut self, pattern: &'a str, is_positive: bool) -> Self {
self.starts_with(pattern, is_positive, true)
}
pub fn starts_with_cs(&mut self, pattern: &'a str, is_positive: bool) -> Self {
self.starts_with(pattern, is_positive, false)
}
pub fn starting_with(&mut self, pattern: &'a str, case_insensitive: bool) -> Self {
self.starts_with(pattern, true, case_insensitive)
}
pub fn starting_with_ci(&mut self, pattern: &'a str) -> Self {
self.starting_with(pattern, true)
}
pub fn starting_with_cs(&mut self, pattern: &'a str) -> Self {
self.starting_with(pattern, false)
}
pub fn not_starting_with(&mut self, pattern: &'a str, case_insensitive: bool) -> Self {
self.starts_with(pattern, false, case_insensitive)
}
pub fn not_starting_with_ci(&mut self, pattern: &'a str) -> Self {
self.not_starting_with(pattern, true)
}
pub fn not_starting_with_cs(&mut self, pattern: &'a str) -> Self {
self.not_starting_with(pattern, false)
}
pub fn contains(&mut self, pattern: &'a str, is_positive: bool, case_insensitive: bool) -> Self {
let sb = if case_insensitive {
StringBounds::ContainsCi(pattern, is_positive)
} else {
StringBounds::ContainsCs(pattern, is_positive)
};
self.string_bounds.push(sb);
self.to_owned()
}
pub fn contains_ci(&mut self, pattern: &'a str, is_positive: bool) -> Self {
self.contains(pattern, is_positive, true)
}
pub fn contains_cs(&mut self, pattern: &'a str, is_positive: bool) -> Self {
self.contains(pattern, is_positive, false)
}
pub fn containing(&mut self, pattern: &'a str, case_insensitive: bool) -> Self {
self.contains(pattern, true, case_insensitive)
}
pub fn containing_ci(&mut self, pattern: &'a str) -> Self {
self.containing(pattern, true)
}
pub fn containing_cs(&mut self, pattern: &'a str) -> Self {
self.containing(pattern, false)
}
pub fn not_containing(&mut self, pattern: &'a str, case_insensitive: bool) -> Self {
self.contains(pattern, false, case_insensitive)
}
pub fn not_containing_ci(&mut self, pattern: &'a str) -> Self {
self.not_containing(pattern, true)
}
pub fn not_containing_cs(&mut self, pattern: &'a str) -> Self {
self.not_containing(pattern, false)
}
fn ends_with(&mut self, pattern: &'a str, is_positive: bool, case_insensitive: bool) -> Self {
let sb = if case_insensitive {
StringBounds::EndsWithCi(pattern, is_positive)
} else {
StringBounds::EndsWithCs(pattern, is_positive)
};
self.string_bounds.push(sb);
self.to_owned()
}
pub fn ends_with_ci(&mut self, pattern: &'a str, is_positive: bool) -> Self {
self.ends_with(pattern, is_positive, true)
}
pub fn ends_with_cs(&mut self, pattern: &'a str, is_positive: bool) -> Self {
self.ends_with(pattern, is_positive, false)
}
pub fn ending_with(&mut self, pattern: &'a str, case_insensitive: bool) -> Self {
self.ends_with(pattern, true, case_insensitive)
}
pub fn ending_with_ci(&mut self, pattern: &'a str) -> Self {
self.ending_with(pattern, true)
}
pub fn ending_with_cs(&mut self, pattern: &'a str) -> Self {
self.ending_with(pattern, false)
}
pub fn not_ending_with(&mut self, pattern: &'a str, case_insensitive: bool) -> Self {
self.ends_with(pattern, false, case_insensitive)
}
pub fn not_ending_with_ci(&mut self, pattern: &'a str) -> Self {
self.not_ending_with(pattern, true)
}
pub fn not_ending_with_cs(&mut self, pattern: &'a str) -> Self {
self.not_ending_with(pattern, false)
}
pub fn matches_whole(&mut self, pattern: &'a str, is_positive: bool, case_insensitive: bool) -> Self {
let sb = if case_insensitive {
StringBounds::WholeCi(pattern, is_positive)
} else {
StringBounds::WholeCs(pattern, is_positive)
};
self.string_bounds.push(sb);
self.to_owned()
}
pub fn matches_whole_ci(&mut self, pattern: &'a str, is_positive: bool) -> Self {
self.matches_whole(pattern, is_positive, true)
}
pub fn matches_whole_cs(&mut self, pattern: &'a str, is_positive: bool) -> Self {
self.matches_whole(pattern, is_positive, false)
}
pub fn is(&mut self, pattern: &'a str, case_insensitive: bool) -> Self {
self.matches_whole(pattern, true, case_insensitive)
}
pub fn is_ci(&mut self, pattern: &'a str) -> Self {
self.matches_whole(pattern, true, true)
}
pub fn is_not(&mut self, pattern: &'a str, case_insensitive: bool) -> Self {
self.matches_whole(pattern, false, case_insensitive)
}
pub fn is_not_ci(&mut self, pattern: &'a str) -> Self {
self.matches_whole(pattern, false, true)
}
pub fn is_not_cs(&mut self, pattern: &'a str) -> Self {
self.matches_whole(pattern, false, false)
}
}
pub fn bounds_builder<'a>() -> BoundsBuilder<'a> {
BoundsBuilder::new()
}