tuwunel_core/utils/string/
between.rs1type Delim<'a> = (&'a str, &'a str);
2
3pub trait Between<'a> {
5 fn between(&self, delim: Delim<'_>) -> Option<&'a str>;
8
9 fn between_infallible(&self, delim: Delim<'_>) -> &'a str;
14}
15
16impl<'a> Between<'a> for &'a str {
17 #[inline]
18 fn between_infallible(&self, delim: Delim<'_>) -> &'a str {
19 self.between(delim).unwrap_or(self)
20 }
21
22 #[inline]
23 fn between(&self, delim: Delim<'_>) -> Option<&'a str> {
24 self.split_once(delim.0)
25 .and_then(|(_, b)| b.rsplit_once(delim.1))
26 .map(|(a, _)| a)
27 }
28}