#[cfg(feature = "str_pattern_extensions")]
use std::str::pattern::*;
pub trait StrExt {
#[cfg(feature = "str_pattern_extensions")]
fn split1<'a, P>(&'a self, pat: P) -> (&'a Self, &'a Self)
where
P: Pattern<'a>;
#[cfg(feature = "str_pattern_extensions")]
#[deprecated(since = "0.6.1", note = "use `split_once` available in `std`")]
fn split1_opt<'a, P>(&'a self, pat: P) -> Option<(&'a Self, &'a Self)>
where
P: Pattern<'a>;
#[cfg(feature = "str_pattern_extensions")]
fn trim_start_match<'a, P>(&'a self, pat: P) -> &'a Self
where
P: Pattern<'a>;
#[cfg(feature = "str_pattern_extensions")]
#[deprecated(note = "Use str.strip_prefix instead")]
fn trim_start_match_opt<'a, P>(&'a self, pat: P) -> Option<&'a Self>
where
P: Pattern<'a>;
#[cfg(feature = "str_pattern_extensions")]
fn trim_end_match<'a, P>(&'a self, pat: P) -> &'a Self
where
P: Pattern<'a, Searcher: ReverseSearcher<'a>>;
#[cfg(feature = "str_pattern_extensions")]
#[deprecated(note = "Use str.strip_suffix instead")]
fn trim_end_match_opt<'a, P>(&'a self, pat: P) -> Option<&'a Self>
where
P: Pattern<'a, Searcher: ReverseSearcher<'a>>;
}
impl StrExt for str {
#[cfg(feature = "str_pattern_extensions")]
fn split1_opt<'a, P>(&'a self, pat: P) -> Option<(&'a Self, &'a Self)>
where
P: Pattern<'a>,
{
self.split_once(pat)
}
#[cfg(feature = "str_pattern_extensions")]
fn split1<'a, P>(&'a self, pat: P) -> (&'a Self, &'a Self)
where
P: Pattern<'a>,
{
self.split_once(pat).unwrap_or((self, ""))
}
#[cfg(feature = "str_pattern_extensions")]
fn trim_start_match_opt<'a, P>(&'a self, pat: P) -> Option<&'a Self>
where
P: Pattern<'a>,
{
let mut matcher = pat.into_searcher(self);
match matcher.next() {
SearchStep::Match(0, n) => Some(&self[n..]),
_ => None,
}
}
#[cfg(feature = "str_pattern_extensions")]
fn trim_start_match<'a, P>(&'a self, pat: P) -> &'a Self
where
P: Pattern<'a>,
{
#[allow(deprecated)]
self.trim_start_match_opt(pat).unwrap_or(self)
}
#[cfg(feature = "str_pattern_extensions")]
fn trim_end_match_opt<'a, P>(&'a self, pat: P) -> Option<&'a Self>
where
P: Pattern<'a, Searcher: ReverseSearcher<'a>>,
{
let mut matcher = pat.into_searcher(self);
match matcher.next_back() {
SearchStep::Match(n, _) => Some(&self[0..n]),
_ => None,
}
}
#[cfg(feature = "str_pattern_extensions")]
fn trim_end_match<'a, P>(&'a self, pat: P) -> &'a Self
where
P: Pattern<'a, Searcher: ReverseSearcher<'a>>,
{
#[allow(deprecated)]
self.trim_end_match_opt(pat).unwrap_or(self)
}
}