tuwunel_core/utils/string/
unquote.rs1const QUOTE: char = '"';
2
3pub trait Unquote<'a> {
5 fn is_quoted(&self) -> bool;
8
9 fn unquote(&self) -> Option<&'a str>;
13
14 fn unquote_infallible(&self) -> &'a str;
17}
18
19impl<'a> Unquote<'a> for &'a str {
20 #[inline]
21 fn unquote_infallible(&self) -> &'a str {
22 self.strip_prefix(QUOTE)
23 .unwrap_or(self)
24 .strip_suffix(QUOTE)
25 .unwrap_or(self)
26 }
27
28 #[inline]
29 fn unquote(&self) -> Option<&'a str> {
30 self.strip_prefix(QUOTE)
31 .and_then(|s| s.strip_suffix(QUOTE))
32 }
33
34 #[inline]
35 fn is_quoted(&self) -> bool { self.starts_with(QUOTE) && self.ends_with(QUOTE) }
36}