use crate::str_processing::char_slices::*;
use std::cmp::Ordering;
pub(super) type Prefix = String;
pub(super) type PrefixStr = str;
pub(super) type Suffix = String;
pub(super) type SuffixStr = str;
pub trait PrefixMatch<PrefixTerm> {
fn get_prefix_from_term(term: &PrefixTerm) -> &PrefixStr;
fn prefix_terms<'a>(&'a self) -> impl Iterator<Item = &'a PrefixTerm> + 'a
where
PrefixTerm: 'a;
#[inline(always)]
fn cmp_prefix(term: &PrefixTerm, prefix: &PrefixStr) -> Ordering {
Self::get_prefix_from_term(term).cmp(prefix)
}
#[inline(always)]
fn match_prefix(&self, to_match: &str) -> Option<&PrefixTerm> {
self.prefix_terms()
.find(|&term| to_match.starts_with(Self::get_prefix_from_term(term)))
}
#[inline(always)]
fn match_prefix_char_slice(&self, to_match: &[char]) -> Option<&PrefixTerm> {
self.prefix_terms()
.find(|&term| char_slice_has_prefix(to_match, Self::get_prefix_from_term(term)))
}
}
pub trait SuffixMatch<SuffixTerm> {
fn get_suffix_from_term(term: &SuffixTerm) -> &SuffixStr;
fn suffix_terms<'a>(&'a self) -> impl Iterator<Item = &'a SuffixTerm> + 'a
where
SuffixTerm: 'a;
#[inline(always)]
fn cmp_suffix(term: &SuffixTerm, suffix: &SuffixStr) -> Ordering {
Self::get_suffix_from_term(term).cmp(suffix)
}
#[inline(always)]
fn match_suffix(&self, to_match: &str) -> Option<&SuffixTerm> {
self.suffix_terms()
.find(|&term| to_match.ends_with(Self::get_suffix_from_term(term)))
}
#[inline(always)]
fn match_suffix_char_slice(&self, to_match: &[char]) -> Option<&SuffixTerm> {
self.suffix_terms()
.find(|&term| char_slice_has_suffix(to_match, Self::get_suffix_from_term(term)))
}
}