use crate::utf8::CharEncodeUtf8;
pub struct Contains<'a, P>(pub &'a str, pub P);
impl<'a, 'b> Contains<'a, &'b str> {
pub const fn const_eval(&self) -> bool {
crate::str::contains(self.0, self.1)
}
}
impl<'a> Contains<'a, char> {
pub const fn const_eval(&self) -> bool {
let haystack = self.0;
let ch = CharEncodeUtf8::new(self.1);
let needle = ch.as_str();
crate::str::contains(haystack, needle)
}
}
#[macro_export]
macro_rules! contains {
($haystack: expr, $pattern: expr) => {{
$crate::__ctfe::Contains($haystack, $pattern).const_eval()
}};
}
pub struct StartsWith<'a, P>(pub &'a str, pub P);
impl<'a, 'b> StartsWith<'a, &'b str> {
pub const fn const_eval(&self) -> bool {
crate::str::starts_with(self.0, self.1)
}
}
impl<'a> StartsWith<'a, char> {
pub const fn const_eval(&self) -> bool {
let haystack = self.0.as_bytes();
let ch = CharEncodeUtf8::new(self.1);
let needle = ch.as_bytes();
crate::bytes::starts_with(haystack, needle)
}
}
#[macro_export]
macro_rules! starts_with {
($haystack: expr, $pattern: expr) => {{
$crate::__ctfe::StartsWith($haystack, $pattern).const_eval()
}};
}
pub struct EndsWith<'a, P>(pub &'a str, pub P);
impl<'a, 'b> EndsWith<'a, &'b str> {
pub const fn const_eval(&self) -> bool {
crate::str::ends_with(self.0, self.1)
}
}
impl<'a> EndsWith<'a, char> {
pub const fn const_eval(&self) -> bool {
let haystack = self.0.as_bytes();
let ch = CharEncodeUtf8::new(self.1);
let needle = ch.as_bytes();
crate::bytes::ends_with(haystack, needle)
}
}
#[macro_export]
macro_rules! ends_with {
($haystack: expr, $pattern: expr) => {{
$crate::__ctfe::EndsWith($haystack, $pattern).const_eval()
}};
}
pub struct StripPrefix<'a, P>(pub &'a str, pub P);
impl<'a, 'b> StripPrefix<'a, &'b str> {
pub const fn const_eval(&self) -> Option<&'a str> {
crate::str::strip_prefix(self.0, self.1)
}
}
pub struct StripSuffix<'a, P>(pub &'a str, pub P);
impl<'a, 'b> StripSuffix<'a, &'b str> {
pub const fn const_eval(&self) -> Option<&'a str> {
crate::str::strip_suffix(self.0, self.1)
}
}
#[macro_export]
macro_rules! strip_prefix {
($s: expr, $prefix: expr) => {{
$crate::__ctfe::StripPrefix($s, $prefix).const_eval()
}};
}
#[macro_export]
macro_rules! strip_suffix {
($s: expr, $suffix: expr) => {{
$crate::__ctfe::StripSuffix($s, $suffix).const_eval()
}};
}