pub(crate) trait Splitter: Copy { /// If any of the needles was found in the haystack, then split the haystack at the first hit. /// /// Since only the first byte of a needle is inspected, be aware that there can be /// false-positives. Always compare the latter string of the output if it fits the expected /// prefix. fn split<'a>(&self, haystack: &'a str) -> Option<(&'a str, &'a str)>;
}
#[inline] pub(crate) fn split<'a>(&self, haystack: &'a str) -> Option<(&'a str, &'a str)> { // SAFETY: During the construction of `self` we used strings as inputs, and a // string always starts with a byte at char boundary. unsafe { $split_unchecked($(self.$field,)* haystack) }
}
}
/// SAFETY: caller has to ensure that the needle is at a char boundary pub(crate) unsafefn $split_unchecked(
$($field: u8,)*
haystack: &str,
) -> Option<(&str, &str)> { let idx = memchr::$memchr($($field,)* haystack.as_bytes())?; // SAFETY: The caller ensures that the needles are at char boundary. // The found index `< haystack.len()`.
Some((haystack.get_unchecked(..idx), haystack.get_unchecked(idx..)))
}
};
}
new_memchr_type!(Splitter1 split1_unchecked memchr a);
new_memchr_type!(Splitter2 split2_unchecked memchr2 a b);
new_memchr_type!(Splitter3 split3_unchecked memchr3 a b c);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.