pub(crate) fn char_offset_to_byte_index(s: &str, offset: usize) -> usize {
s.char_indices()
.nth(offset)
.map(|(i, _)| i)
.unwrap_or(s.len())
}
pub(crate) fn starts_with_ignore_ascii_case(s: &str, prefix: &str) -> bool {
if prefix.len() > s.len() {
return false;
}
s[..prefix.len()].eq_ignore_ascii_case(prefix)
}
pub(crate) fn starts_with_ignore_case(s: &str, prefix: &str) -> bool {
s.to_lowercase().starts_with(&prefix.to_lowercase())
}
pub(crate) fn ends_with_ignore_ascii_case(s: &str, suffix: &str) -> bool {
if suffix.len() > s.len() {
return false;
}
s[s.len() - suffix.len()..].eq_ignore_ascii_case(suffix)
}
pub(crate) fn ends_with_ignore_case(s: &str, suffix: &str) -> bool {
s.to_lowercase().ends_with(&suffix.to_lowercase())
}
#[macro_export]
macro_rules! guard_empty {
($self:expr, $other:expr, $default:expr) => {
if $self.is_empty() || $other.is_empty() {
return $default;
}
};
}