#[inline]
pub fn is_templated(s: &str) -> bool {
if s.len() < 3 {
return false;
}
let mut skip_next = false;
for window in s.as_bytes().windows(3) {
if skip_next {
skip_next = false;
continue;
}
match window {
[b'$', b'$', b'{'] | [b'%', b'%', b'{'] => {
skip_next = true;
}
[b'$' | b'%', b'{', _] => return true,
_ => {}
}
}
false
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_templated() {
assert!(is_templated("${a}"));
assert!(is_templated("${\"a\"}"));
assert!(is_templated("%{ if foo }foo%{ else }bar%{ endif }"));
assert!(is_templated("$${ introduces an ${\"interpolation\"}"));
assert!(!is_templated(
"escaped directive %%{ if foo }foo%%{ else }bar%%{ endif }"
));
assert!(!is_templated("escaped interpolation $${a}"));
}
}